Skip to content
Laviyx Learn

Try

HTML course menu

HTML Lists: Ordered (ol), Unordered (ul) and Nested Lists

Learn HTML lists: unordered lists with ul, ordered lists with ol, list items with li, the start, reversed and type attributes, nesting lists inside lists, and using lists for navigation menus.

Beginner6 min readUpdated
On this page

Lists group related items. HTML has two main kinds: unordered lists, where order does not matter, and ordered lists, where it does.

Unordered lists: ul#

Use <ul> for items in no particular order. Each item is an <li> (list item). Browsers show bullets:

HTML
<p>Packing list:</p>
<ul>
  <li>Water bottle</li>
  <li>Umbrella</li>
  <li>Phone charger</li>
</ul>
Result

Ordered lists: ol#

Use <ol> when the order matters, such as steps or rankings. Browsers number the items automatically:

HTML
<p>How to make tea:</p>
<ol>
  <li>Boil water.</li>
  <li>Add tea leaves and sugar.</li>
  <li>Add milk and simmer for two minutes.</li>
</ol>
Result

If you add, remove or reorder items, the numbers update automatically.

Changing the numbering#

HTML
<ol start="5">
  <li>Fifth</li>
  <li>Sixth</li>
</ol>

<ol reversed>
  <li>Bronze</li>
  <li>Silver</li>
  <li>Gold</li>
</ol>

<ol type="A">
  <li>Option A</li>
  <li>Option B</li>
</ol>
Result
AttributeEffect
start="5"Start counting at 5
reversedCount down instead of up
type1 (default), a, A, i or I for letters or Roman numerals

You can also set value on a single <li> to change its number.

Nested lists#

A list can contain another list. Put the inner list inside an <li>, after the item's text:

HTML
<ul>
  <li>Fruits
    <ul>
      <li>Mango</li>
      <li>Banana</li>
    </ul>
  </li>
  <li>Vegetables
    <ol>
      <li>Carrot</li>
      <li>Spinach</li>
    </ol>
  </li>
</ul>
Result

Browsers change the bullet style for each nesting level.

Lists for navigation#

A website's main menu is a list of links, so it is usually marked up as one, inside a <nav> element:

HTML
<nav>
  <ul>
    <li><a href="/">Home</a></li>
    <li><a href="/courses">Courses</a></li>
    <li><a href="/contact">Contact</a></li>
  </ul>
</nav>

With CSS, the bullets are removed and the items are laid out in a row. Screen readers announce "list, 3 items", which tells users how big the menu is.

Styling note#

To change bullets or numbering style, use CSS, for example list-style-type: square;, rather than adding characters such as "•" or "1." to the text yourself.

Common mistakes#

Practice#

Practice exercise

Create the steps to make a sandwich as an ordered list, where step 2 "Add fillings" has a nested unordered list of three fillings.

Show solution
HTML
<ol>
  <li>Take two slices of bread.</li>
  <li>Add fillings:
    <ul>
      <li>Cucumber</li>
      <li>Tomato</li>
      <li>Cheese</li>
    </ul>
  </li>
  <li>Close the sandwich and cut it in half.</li>
</ol>
Result

Key takeaway#

Finished this lesson?