<li>
Example
<div class="tags">
<li>CSS</li>
<li>HTML</li>
</div><ul class="tags">
<li>CSS</li>
<li>HTML</li>
</ul><li> must sit inside a list element so browsers and screen readers treat the items as a list.
Common mistakes
- Using
<li>without a list parent, which is invalid and loses list semantics. - Wrapping groups of
<li>elements in a<div>inside the list.
Key points
- Every
<li>has a<ul>,<ol>or<menu>as its parent. - Sub-lists are placed inside an
<li>, not between items.
Interview questions
Can an li contain block elements like div or p?
Yes. An <li> accepts flow content, including paragraphs, headings and nested lists.
How do I change the number of one li?
In an <ol>, set the value attribute on that <li>. Following items continue counting from it.
How do I style the bullet of an li?
Use the ::marker pseudo-element for color and size, or list-style-type to change the symbol.