Correct HTML Syntax - bold inside list tag or list inside bold tag

Kir*_*ash 3 html

I have a simple question to ask. Since I can't find any online article, posting my question here to get your views.

Which of the below syntax is correct? b inside li or li inside b. Although both does the job of making the font weight bold, I would love to know if one syntax is correct and the other one is not.

<ul>
  <li><b>1</b></li>
  <li><b>2</b></li>
  <li><b>3</b></li>
</ul>

<ul>
  <b><li>1</li></b>
  <b><li>2</li></b>
  <b><li>3</li></b>
</ul>
Run Code Online (Sandbox Code Playgroud)

Que*_*tin 7

This is easily tested by passing the HTML through a validator or looking at the specification.

A b element may not be a child of a ul element, so the latter is invalid.

The former is allowed.


That said, presentation is a job for CSS, not HTML, so you should be applying your bold face from your stylesheet.

li {
  font-weight: bold;
}
Run Code Online (Sandbox Code Playgroud)
<ul>
  <li>1</li>
  <li>2</li>
  <li>3</li>
</ul>
Run Code Online (Sandbox Code Playgroud)

  • 如果答案能够回答您的问题,请不要忘记接受答案。 (2认同)