<li>
A single item of a `<ul>`, `<ol>`, or `<menu>` list.
- Display
- list-item
- Closing tag
- Required
- Permitted content
- Flow content
Example
#<ol>
<li>Module 1: document structure</li>
<li>
Module 2: text and links
<ul>
<li>paragraphs and headings</li>
<li>hyperlinks</li>
</ul>
</li>
<li>Module 3: images</li>
</ol>Definition and usage
#The <li> element (from list item) marks one item of a list. It must be a direct child of <ul>, <ol>, or <menu>. Whether a bullet or a number appears before the content depends on the parent, not on the <li> itself.
Inside it you can put any flow content: text, a link, an image, several paragraphs, or even another list. This is how nested lists are built, for example a menu with a submenu or a course plan divided into modules and lessons.
By default the element has display: list-item, which is why it generates a marker (a bullet or a number). You style the marker with the ::marker pseudo-element, and you hide it by setting list-style: none on the list.
Syntax
#<li>item content</li>Attributes
#integer
Sets the number of this item in an<ol>list. The following items keep counting from the given value. In<ul>and<menu>lists the attribute has no effect.
The element also supports all global attributes, such as class, id, style and hidden.
Attributes in practice
#value
integerSets the number of this item in an <ol> list. The following items keep counting from the given value. In <ul> and <menu> lists the attribute has no effect.
<h4>Ranking of the week</h4>
<ol>
<li>Ola, 980 pts</li>
<li>Kuba, 870 pts</li>
<li value="2">Maja, 870 pts</li>
<li>Tomek, 750 pts</li>
</ol>Default CSS
#Most browsers display this element with these default styles:
li {
display: list-item;
}Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- Put a sublist inside the
<li>, not next to it. A<ul>placed directly inside another list is a syntax error. - You can change the bullet’s color and size without extra elements:
li::marker { color: orange; }. - If the whole item should be clickable, put an
<a>link in it and enlarge it in CSS. Don’t attach a click handler to the<li>itself.
Related entries
#- <ul>A bulleted list in which the order of the items doesn’t matter.
- <ol>A numbered list in which the order of the items matters.
- <menu>A list of commands, for example a toolbar with buttons. It works like `<ul>`.
- <dl>A description list: name and description pairs, for example a glossary of terms or technical data.
Practise it in lessons
#Spotted a mistake or missing an example? Write to us.