Lists are a way to group related items in HTML. There are two main types of lists: ordered lists and unordered lists.
Unordered lists are created using the <ul> tag, and each item inside it is defined using the <li> tag.
<ul>
<li>Apples</li>
<li>Bananas</li>
<li>Cherries</li>
</ul>
Output:
Ordered lists are created using the <ol> tag, and each item is still defined using <li>. Items are automatically numbered.
<ol>
<li>Wake up</li>
<li>Brush teeth</li>
<li>Have breakfast</li>
</ol>
Output:
| Feature | Ordered List (<ol>) | Unordered List (<ul>) |
|---|---|---|
| Display | Numbered items | Bulleted items |
| Tag | <ol> | <ul> |
| Use Case | Steps in a sequence, ranked lists | Simple lists, items with no particular order |
| Child Element | <li> for each item | <li> for each item |
Lists can also be nested. For example, you can put an unordered list inside an ordered list item:
<ol>
<li>Fruits
<ul>
<li>Apple</li>
<li>Banana</li>
</ul>
</li>
<li>Vegetables</li>
</ol>
<ul> for items without a specific order<ol> for steps, instructions, or ranked lists<li> for each list itemOrdered and unordered lists are essential tools in HTML for organizing content. They improve readability, structure information clearly, and can be easily styled using CSS.
By understanding when to use <ol> vs <ul>, you can create professional and well-structured web pages.