The <li> tag is used in HTML to define a list item in an ordered list (<ol>), an unordered list (<ul>), or a definition list (<dl>).
Each item in a list is always included in a <li> tag.
Structure and syntax of the <li> tag
Basic structure and syntax
Here is the basic syntax of the <li> tag:
<ul>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ul>The <li> tag must be used within an ordered list (<ol>) or unordered list (<ul>), to define an item in the list.
Usage example
Here is an example of using the <li> tag in an unordered list:
<ul>
<li>Bread</li>
<li>Cheese</li>
<li>Wine</li>
</ul>In this example, each item in the list is defined by a <li> tag within the <ul> tag.
Attributes
The <li> tag can accept generic attributes such as class, id, and style, but it does not have specific attributes.
Difference with other similar tags
<ul>: The<ul>tag is used to create an unordered list, in which each item is defined by a<li>tag.<ol>: The<ol>tag is used to create an ordered list, in which each item is also defined by a<li>tag.<dl>: The<dl>tag is used for a definition list, in which terms are defined by a<dt>tag and definitions by a<dd>tag.
Browser compatibility
The <li> tag is supported by all modern browsers.
| Browser | Compatibility |
|---|---|
| Chrome | Yes |
| Firefox | Yes |
| Safari | Yes |
| Edge | Yes |
| Internet Explorer | Yes |