Course topics

By WebNest Studio Engineering Team

HTML Tutorial

HTML Lists

HTML provides two main list types for grouping related items: unordered lists for items with no required sequence, and ordered lists for items whose order matters. Lists can also be nested inside one another to represent hierarchical relationships, such as a table of contents or a multi-level menu.

Why it matters

Navigation menus, steps of a recipe, feature lists and glossaries are all lists, and marking them up as lists lets a screen reader announce how many items there are and move between them. Navigation menus in nearly every site you will inspect are an unordered list of links.

Unordered and Ordered Lists

An unordered list, <ul>, renders items with bullet points by default and is appropriate when the sequence of items doesn't matter — a list of features, ingredients, or navigation links. An ordered list, <ol>, renders items with numbers by default and should be used when sequence carries meaning — step-by-step instructions or a ranking. In both cases, each individual item is wrapped in an <li> (list item) element, and <li> is only valid as a direct child of <ul>, <ol>, or <menu>.

Nesting Lists

A nested list is created by placing an entire <ul> or <ol> inside an <li> of a parent list. This is how multi-level navigation menus, outlines, and file-tree-style structures are built in plain HTML, and browsers automatically indent and adjust bullet or number styles at each nested level.

Description Lists

A third, less common list type, <dl> (description list), pairs terms with their definitions using <dt> (term) and <dd> (description) elements. It's well suited to glossaries, metadata key-value pairs, or FAQ-style content.

Example

An ordered list of steps containing a nested unordered list

HTML
<ol>
  <li>Sign up for an account</li>
  <li>Choose a subscription plan
    <ul>
      <li>Basic</li>
      <li>Pro</li>
      <li>Enterprise</li>
    </ul>
  </li>
  <li>Start building your site</li>
</ol>
Output
Renders a numbered list with three main steps; the second step shows a bulleted sub-list of three plan options indented beneath it.

Common Mistakes

  • Placing text or other elements directly inside <ul> or <ol> without wrapping them in <li>.
  • Using <br> to fake list spacing instead of using actual <li> elements for each item.
  • Choosing <ul> for content where the order genuinely matters (like ranked steps), losing the numbered sequence.
  • Forgetting to close the parent <li> after a nested list, breaking the list's structure.

Exercise

Write the steps for making tea as an ordered list with three steps: Boil water, Add the following and Pour and serve. Inside the second step, nest an unordered list with the items Tea leaves and Sugar.

Expected result: a numbered list from 1 to 3, with two bullet points indented under step 2.

HTML · starter code
<h2>How to make tea</h2>

<!-- TODO: ordered list with a nested unordered list in step 2 -->
Show hints
  • An ordered list is ol, an unordered list is ul, and each item is an li.
  • The nested list goes inside the li of step 2, before that li is closed.
Show solution
HTML · solution
<h2>How to make tea</h2>

<ol>
  <li>Boil water</li>
  <li>
    Add the following
    <ul>
      <li>Tea leaves</li>
      <li>Sugar</li>
    </ul>
  </li>
  <li>Pour and serve</li>
</ol>

Quick quiz

1. Which list should be used for steps that must be followed in sequence?

  • A. <ul>
  • B. <ol>
  • C. <dl>
  • D. <menu>
Show answer

B. An ordered list is for content where the order matters.

2. Which elements may be direct children of a ul or ol?

  • A. <p> and <li>
  • B. Any element
  • C. Only <li> elements
  • D. Another <ul>
Show answer

C. A nested list must be placed inside an li, not directly inside the parent list.

3. Which elements make up a description list?

  • A. ul, li
  • B. ol, li
  • C. table, tr, td
  • D. dl, dt, dd
Show answer

D. dl is the list, dt a term, and dd its description.

Interview questions

What are the three types of list in HTML?

Show answer

An unordered list, ul, for items whose order does not matter, shown with bullets. An ordered list, ol, for items in a sequence, shown with numbers; it accepts start, reversed and type attributes. A description list, dl, for pairs of terms and descriptions, using dt and dd, as in a glossary.

Why are navigation menus usually marked up as a list?

Show answer

A menu is a set of related links, which is what a list expresses. Marked up as a ul inside a nav, it lets a screen reader announce that there is a navigation region containing a list of a given number of items, and lets the user skip it or step through it. The bullets and vertical layout are removed with CSS.

Key Points to Remember

  • Use <ul> when item order doesn't matter, <ol> when it does; each item goes inside <li>.
  • Nested lists are built by placing a <ul> or <ol> inside a parent <li>.
  • <dl>/<dt>/<dd> model term-definition pairs, useful for glossaries and FAQs.
  • <li> is only valid directly inside <ul>, <ol>, or <menu>.

Practice in the playground

Write and run your own code for this topic, or start from the exercise or an example. Shows a live preview of your HTML, CSS and JavaScript. Your code for each topic is kept in this browser.

Run the examples

Change an input, predict the result, then compare it with the output. Explain why the result changes.

WebNest Studio

Written by

WebNest Studio Engineering Team

Practical lessons from developers working with Java, Python, React, databases and production systems.

Led by Vansh Duggal, Founder, WebNest Studio · Full-stack & software engineering