HTML <li> li tag
The <li>
tag in HTML is used to define a list item. It is most commonly used inside list containers like <ul>
(unordered list) and <ol>
(ordered list), and sometimes <menu>
(for a list of commands or options). Each <li>
represents a single item within these lists.
Usage:
- Unordered List (
<ul>
): Items are usually presented with bullet points. - Ordered List (
<ol>
): Items are presented in a numbered sequence.
Example with an Unordered List:
<ul>
<li>Apples</li>
<li>Bananas</li>
<li>Cherries</li>
</ul>
This will display as:
- Apples
- Bananas
- Cherries
Example with an Ordered List:
<ol>
<li>First Step</li>
<li>Second Step</li>
<li>Third Step</li>
</ol>
This will display as:
- First Step
- Second Step
- Third Step
Key Points:
- Unordered List (
<ul>
): The<li>
items are displayed with bullet points, but the bullets can be styled or removed using CSS. - Ordered List (
<ol>
): The<li>
items are displayed with numbers or letters, and the numbering format can be customized with thetype
attribute (e.g.,<ol type="A">
for uppercase letters). - Nesting: Lists can be nested, meaning you can have lists within lists (both ordered and unordered).
Example of a Nested List:
<ul>
<li>Fruits
<ul>
<li>Apples</li>
<li>Bananas</li>
</ul>
</li>
<li>Vegetables</li>
</ul>
This would look like:
- Fruits
- Apples
- Bananas
- Vegetables
The <li>
tag is essential for creating structured lists in HTML, making content more organized and readable.