HTML Lists

Bullet lists, numbered lists, nested lists and description lists.

Lesson 16 of 44Beginner12 min read

Lists are everywhere on the web: shopping baskets, navigation menus, step-by-step instructions and top-10 rankings. HTML has three kinds of list, and choosing the right one is easy once you ask one question: does the order matter?

Marking up lists properly is about more than bullet points. Screen readers announce "list, 5 items" before reading a list, so visitors know what to expect, and search engines often pick up well-structured lists of steps or ingredients for their results pages.

Unordered lists: when order doesn't matter

Use <ul> (unordered list) when the items could appear in any order. Each item goes in an <li> (list item) element, and browsers show a bullet point in front of each one.

HTML
<ul>
  <li>Sun cream</li>
  <li>Sunglasses</li>
  <li>Beach towel</li>
</ul>

Only <li> elements may sit directly inside a <ul>. Headings, paragraphs and images can go inside an <li>, but not between list items.

Ordered lists: when order matters

Use <ol> (ordered list) for steps, rankings and instructions. Browsers number the items automatically, so if you insert a new step, everything renumbers itself.

Useful attributes:

  • start="5" begins counting at 5.
  • reversed counts down, which suits countdowns and "top 10" lists.
  • type="A", "a", "I" or "i" switches to letters or Roman numerals.

A recipe's method, the steps to reset a password and a league table are all good candidates for <ol>.

Nested lists

A list can sit inside an <li> to create sub-points:

HTML
<ul>
  <li>Fruit
    <ul>
      <li>Apples</li>
      <li>Pears</li>
    </ul>
  </li>
  <li>Vegetables</li>
</ul>

The inner list goes inside the <li>, before its closing tag. This is how multi-level outlines and dropdown menus are built.

Description lists for terms and definitions

For pairs of terms and explanations, such as a glossary, a FAQ or product specifications, use <dl> (description list) with <dt> for each term and <dd> for its description:

HTML
<dl>
  <dt>Weight</dt>
  <dd>1.2 kg</dd>
  <dt>Battery life</dt>
  <dd>Up to 10 hours</dd>
</dl>

HTML Lists Syntax

List syntax

<ul> <li>item</li> </ul>
<ol> <li>first</li> <li>second</li> </ol>
<dl> <dt>term</dt> <dd>description</dd> </dl>

HTML Lists Summary

  • Use <ul> when order doesn't matter and <ol> when it does.
  • Every item in either list goes inside an <li> element.
  • Attributes like start, reversed and type change how ordered lists count.
  • Put a nested list inside an <li>, not between items.
  • Use <dl>, <dt> and <dd> for terms and their descriptions.

HTML Lists Examples

Each example runs in the page. Edit the code and press Run to see what changes.

Example 1

Shopping list and recipe steps

<h3>Shopping list</h3>
<ul>
  <li>Avocados</li>
  <li>Limes</li>
  <li>Tortilla chips</li>
</ul>

<h3>How to make guacamole</h3>
<ol>
  <li>Mash the avocados.</li>
  <li>Squeeze in the lime juice.</li>
  <li>Add salt and stir.</li>
  <li>Eat immediately with chips.</li>
</ol>
ResultEdit the code, then press Run or Ctrl+Enter
Line-by-line explanation
  1. Lines 2 to 6An unordered list: the order you buy things doesn't matter.
  2. Lines 9 to 14An ordered list: you can't eat it before mashing it! Numbers are added automatically.
Example 2

Countdown and nested lists

<h3>Top 3 snacks of all time</h3>
<ol reversed>
  <li>Popcorn</li>
  <li>Nachos</li>
  <li>Toast (controversial)</li>
</ol>

<h3>Packing list</h3>
<ul>
  <li>Clothes
    <ul>
      <li>T-shirts</li>
      <li>Jumper</li>
    </ul>
  </li>
  <li>Toothbrush</li>
</ul>
ResultEdit the code, then press Run or Ctrl+Enter
Line-by-line explanation
  1. Line 2reversed counts down: 3, 2, 1.
  2. Lines 10 to 15A nested <ul> sits inside the "Clothes" <li>, before its closing tag.
Example 3

A mini glossary with a description list

<dl>
  <dt>Bug</dt>
  <dd>A mistake in code that makes it behave unexpectedly.</dd>
  <dt>Debugging</dt>
  <dd>The art of finding and fixing bugs.</dd>
</dl>
ResultEdit the code, then press Run or Ctrl+Enter
Line-by-line explanation
  1. Line 2<dt> is the term.
  2. Line 3<dd> is its description, indented by default.

Common HTML Lists Mistakes

Putting text straight inside ul

Don't
<ul>
  Milk
  <li>Bread</li>
</ul>
Do
<ul>
  <li>Milk</li>
  <li>Bread</li>
</ul>

The only direct children of <ul> and <ol> should be <li> elements.

Nesting the sub-list outside the li

Don't
<ul>
  <li>Fruit</li>
  <ul><li>Apple</li></ul>
</ul>
Do
<ul>
  <li>Fruit
    <ul><li>Apple</li></ul>
  </li>
</ul>

A nested list belongs inside the item it describes.

HTML Lists in Real Projects

Lists in real interfaces

Navigation bars, footer link groups, breadcrumb trails, product feature lists, comment threads and step-by-step checkouts are all lists under the hood. Using real list elements tells screen readers "this is a list of 5 items", which helps people understand the page quickly.

HTML Lists Exercises

Answer each one and check it instantly. If you get stuck, open the hint before the answer.

Fill in the blankseasy

Make this a numbered list of steps.

<>
  <>Plug in the kettle</li>
  <li>Boil the water</li>
</ol>
Multiple choiceeasy

Which list should you use for the steps to assemble a bookshelf?

Multiple choicemedium

How do you make an ordered list start at 10?

Fix the bugmedium

The sub-list of planets should be nested inside the "Inner planets" item, and "Mars" is missing its <li>. Fix it.

<ul>
  <li>Inner planets</li>
  <ul>
    <li>Mercury</li>
    <li>Venus</li>
    Mars
  </ul>
  <li>Outer planets</li>
</ul>
ResultEdit the code, then press Run or Ctrl+Enter
Checks
  • The nested list is inside an li
  • The nested list has 3 items
  • "Mars" is in an li
  • The outer list has 2 items

HTML Lists Quiz

3 questions to check what you learned.

  1. What does <li> stand for?

    • line
    • list item
    • link
    • list index
  2. Which attribute makes an ordered list count down?

    • down
    • start="-1"
    • reversed
    • order="desc"
  3. Which elements make up a description list?

    • <ul>, <li>
    • <dl>, <li>
    • <desc>, <term>
    • <dl>, <dt>, <dd>

HTML Lists Challenge

Your weekend plan

Build:

  1. An <h2> "Weekend plan"
  2. An ordered list with at least 3 activities in order
  3. A nested unordered list inside one of the items, with at least 2 things to bring
ResultEdit the code, then press Run or Ctrl+Enter
Checks
  • There's an h2 "Weekend plan"
  • Ordered list has 3+ top-level items
  • A ul is nested inside an ol item
  • The nested list has 2+ items