<li>

Term side of the Card.
Topic: Lists
Unit title: <li>
Categories: Tag
Explanation side of the Card

Explanation: The element that represents an item in a list, whether ordered (`<ol>`) or unordered (`<ul>`). It's used to structure content in a clear, bullet-point or numbered format, making information easy to read and scan.

Browser compatibility:
  • The chrome browser supports this feature starting from version 1.
  • The edge browser supports this feature starting from version 12.
  • The firefox browser supports this feature starting from version 1.
  • The safari browser supports this feature starting from version 3.
Availability: 

Example

Wronghtml
<div class="tags">
  <li>CSS</li>
  <li>HTML</li>
</div>
Righthtml
<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.

Analytics cookiesWe'd like to use analytics cookies to see which pages are useful. They're set only if you accept. Privacy Policy