Lesson 22 of 51 · Module 4, lesson 1 of 6 · 3 min

Bulleted and nested lists

Make bulleted lists, put lists inside lists, and choose the right kind of list.

What you'll learn

  • How to make a bulleted list with <ul> and <li>
  • How to put a list inside another list
  • Which kind of list to choose

Why this matters

Lists are everywhere: ingredients, features, menus, to-do lists. Written as a real list, the browser adds the bullets, and a screen reader announces "list, 4 items" so that the listener knows what is coming. Lines separated with <br> get none of that.

Three kinds of list

HTML has three kinds of list. This lesson covers the first; the next two lessons cover the others.

ListUse it whenElements
Unordered (bulleted)The order does not matter<ul> and <li>
Ordered (numbered)The order matters<ol> and <li>
DescriptionTerms with their explanations<dl>, <dt> and <dd>

A bulleted list

<ul> means unordered list. Each item is an <li> (list item).

html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Shopping list</title>
</head>
<body>
  <h1>Shopping list</h1>
  <ul>
    <li>Tomatoes</li>
    <li>Onions</li>
    <li>Bread</li>
    <li>Olive oil</li>
  </ul>
</body>
</html>

What you'll see: four items, each on its own line, with a round bullet in front, moved in from the left.

The page "Shopping list" with four bulleted items: Tomatoes, Onions, Bread, Olive oil.

Only <li> elements may go directly inside <ul>. Inside an <li>, you can put text, links, images — even another list.

Lists inside lists

To group items, put a whole new <ul> inside an <li>:

html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Shopping list</title>
</head>
<body>
  <h1>Shopping list</h1>
  <ul>
    <li>Vegetables
      <ul>
        <li>Tomatoes</li>
        <li>Onions</li>
      </ul>
    </li>
    <li>Bakery
      <ul>
        <li>Bread</li>
      </ul>
    </li>
  </ul>
</body>
</html>

What you'll see: "Vegetables" and "Bakery" with round bullets, and their items moved further in, with a different bullet (usually an empty circle).

The shopping list grouped into "Vegetables" (with Tomatoes and Onions indented below it) and "Bakery" (with Bread indented below it). The inner items have hollow circle bullets.

Notice where the inner <ul> is: inside the <li>, before its </li>.

A group of navigation links is a list of links. You will use this often:

html
<ul>
  <li><a href="index.html">Home</a></li>
  <li><a href="recipes.html">Recipes</a></li>
  <li><a href="about.html">About me</a></li>
</ul>

The bullets and indentation can be removed later with CSS. The list structure stays, and screen readers still say "list, 3 items".

Try it yourself

  1. Select the first example and choose Try it.
  2. Add two more items.
  3. Turn one item into a group with its own inner list.
  4. Put a link inside one of the items.

Common mistakes

  • Text directly inside <ul>, outside any <li>. It is not valid, and screen readers get the count wrong. Fix: every item is an <li>.
  • The inner list outside the <li>, such as </li><ul>…</ul>. Fix: put it inside the <li>, before </li>.
  • Using <br> or typed dashes instead of a list. No list is announced. Fix: use <ul> and <li>.
  • Choosing a list for its look. Bullets are a style; you can change or remove them with CSS. Fix: choose <ul> because the content is a list.

Check yourself

  1. Which element holds each item of a list?
  2. Where does an inner list go?
  3. Is a menu of links a list?

Answers

  1. <li>.
  2. Inside an <li> of the outer list, before its </li>.
  3. Yes — usually a <ul> of <li> elements, each containing a link.

Next: when the order matters — steps, rankings — you need a numbered list.

Chat with us on WhatsApp