Thuta Learning
HTML
IntermediateWeb DevelopmentBeginner

Unordered Lists

HTMLLesson 1720 min

What you'll walk away with

  • Decide when ul is the right element: items whose order does not matter
  • Write valid markup with only li elements as direct children of ul
  • Nest a sub-list correctly inside an li
  • Change the bullet style with CSS instead of HTML attributes

Explain it simply

Explain it simply

Think of a shopping list: eggs, bread, milk. It does not matter which you buy first; what matters is that they belong to one list. In HTML that kind of list is a ul (unordered list), and each entry goes inside an li (list item).

The browser draws a bullet before each item and indents the list a little. But the real job of ul is not the look: it tells screen readers and search engines that these items belong together as a group.

Problem → Why → Solution

The problem: a list faked with bullet characters

A feature list is written as paragraphs with a • character typed by hand. On screen it looks like a list, but a screen reader user does not hear "list, 3 items"; they hear three separate paragraphs, possibly with the word "bullet". Every new item needs a hand-typed •, and restyling the bullets with CSS is awkward.

features.html
<p>Why choose us?</p>
<p>• Free delivery</p>
<p>• 24/7 support</p>
<p>• 30-day returns</p>

Why is ul better?

ul and li put the fact that the items form a group, and how many there are, into the accessibility tree. A screen reader announces where the list starts and ends, and the user can skip the whole list at once. The bullet becomes CSS's job, so you can restyle it without touching the HTML.

Core concept: ul is the group, li is each member

Use ul when reordering the items would not change their meaning. There is an easy test: shuffle the items, and ask whether the reader would misunderstand. If not, use ul; if yes, as with recipe steps or rankings, use ol from the next lesson. When you want to pair each term with its explanation, choose the third kind of list, dl.

ElementUse it whenExample
ulA group of items whose order does not matterFeatures, tags, menu links
olItems whose order is part of the meaningInstall steps, a top 10
dlPairs of a term and its descriptionA glossary, product specs

The content model of ul is strict: its direct children may only be li elements (plus script-supporting elements such as script and template). Putting p, div, a or h3 directly inside ul is invalid. Inside an li, however, almost anything goes: links, paragraphs, images, even another list.

For a sub-list, put a new ul inside the parent item's li, not between two li elements. In Chromium the first level gets disc bullets (●), the second circle (○) and the third square (■), each level indented by about 40px.

The bullet's appearance is presentation, so it belongs to CSS. Change it with list-style-type: square; or the ::marker pseudo-element, and hide it with list-style: none;. The type attribute on ul is obsolete; do not use it. Even where no bullets are shown, as in a navigation menu, links are kept in a ul because it tells assistive technology "there are five links here". Safari with VoiceOver has been known to stop announcing a list once list-style: none is applied, so when the item count matters, people add role="list" as well.

Mental model: the shuffle test
  1. Imagine shuffling the items
  2. Meaning unchanged? Choose ul
  3. Wrap every item in its own li
  4. Leave the bullet's look to CSS

HTML says "these belong together"; CSS says "draw them like this".

General pattern

html
<ul>
  <li>Item</li>
  <li>
    Item with a sub-list
    <ul>
      <li>Sub-item</li>
    </ul>
  </li>
</ul>

Every direct child of ul is an li. A sub-list lives inside its parent item's li, and that li closes only after the sub-list.

Example: a product feature list

This example lists three features of a website. Moving "Fast loading" to the end would not change the meaning, so ul is the right choice.

html
<ul>
  <li>Fast loading</li>
  <li>Mobile responsive</li>
  <li>Beginner friendly</li>
</ul>

Code breakdown

  1. Opening tag<ul>

    Starts the list. By default the browser adds a 16px top and bottom margin and 40px of left padding.

  2. First item<li>Fast loading</li>

    One item, one li. You never type the bullet; the browser draws it as the li's marker.

  3. More items<li>Mobile responsive</li>

    Each li is a direct child of ul. Adding an item means adding one more li line, nothing else.

  4. Closing tag</ul>

    Ends the list. A screen reader may announce something like "end of list" here.

You should see
A bulleted list appears:
• Fast loading
• Mobile responsive
• Beginner friendly
It is indented about 40px and each item has a filled disc. A screen reader announces it as a list of 3 items.

A list without bullets: the navigation menu

A site's main menu is one of the most common homes for ul. nav says "this is navigation" and ul says "there are three links". CSS removes the bullets and indentation and lines the items up horizontally, while the semantics stay the same.

nav.html
<style>
  .menu { list-style: none; margin: 0; padding: 0; display: flex; gap: 1rem; }
</style>

<nav aria-label="Main">
  <ul class="menu" role="list">
    <li><a href="/">Home</a></li>
    <li><a href="/courses/">Courses</a></li>
    <li><a href="/about/">About</a></li>
  </ul>
</nav>

To restyle the bullet rather than hide it, use the ::marker pseudo-element. li::marker { color: teal; } changes only the bullet's colour and leaves the text alone. Giving list-style-type a string, such as list-style-type: "✓ ";, shows any character you like instead of the disc. All of this lives in CSS, so the HTML stays a plain ul with li elements.

In real projects

Where this shows up in real projects

On real websites ul shows up far more often than you might expect. Header menus, groups of footer links, breadcrumbs, the feature list in a pricing card, tags, product grids, cards of search results: developers write all of these as ul and li, then use CSS Grid or Flexbox to lay them out however they like. No bullets are visible, yet the list is there in the markup.

In frameworks such as React or Vue, mapping an array to li elements is an everyday pattern: a component returns one li per item and the parent places them inside a ul. In accessibility audits, "list contains children that are not li" is a common finding that tools such as axe report, usually after someone wrapped items in a div inside the ul.

Common mistakes

Common mistakes

1. Placing a sub-list outside the li

Writing <li>Drinks</li><ul>...</ul> makes the inner ul a direct child of the outer ul, which is invalid, and the sub-list loses its connection to "Drinks". Close the </li> after the sub-list: <li>Drinks<ul>...</ul></li>.

2. Putting div or a directly inside ul

Dropping <div class="card"> straight into a ul to lay out cards, or putting <a> elements in a menu without li, is common. Screen readers may then report the wrong number of items. Put the div or a inside an li.

3. Using ul just to indent text

Wrapping a paragraph in a ul to push it to the right tells assistive technology that something is a list when it is not. Use CSS margin or padding for indentation.

Best practices

Best practices

  • Put a heading or a lead-in sentence before the list that says what it is about.
  • Write items in parallel grammar: all nouns, or all starting with a verb.
  • Keep nesting to two, at most three, levels; split deeper structures with headings.

Mini challenge

Mini challenge: two lists for a course page

For an online course page, write a navigation menu without bullets and a nested "What's included" list.

  • A ul with three links inside nav, with bullets and padding removed by CSS
  • Two top-level items (Videos, Downloads) under a "What's included" heading
  • Each of those items holds a nested ul with two sub-items
  • Every direct child of every ul is an li
course.html
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>HTML for Beginners</title>
  <!-- TODO: CSS that removes bullets and padding from the menu only -->
</head>
<body>
  <!-- TODO: nav > ul with Home, Lessons, Pricing links -->

  <h2>What's included</h2>
  <!-- TODO: ul with Videos and Downloads,
       each holding its own nested ul of two sub-items -->
</body>
</html>

Expected: At the top, Home, Lessons and Pricing appear without bullets. Below "What's included" come ● Videos and ● Downloads, each followed by two ○ sub-items indented one level further.

Show hint

Give the menu ul a class and target that class in CSS, so the "What's included" list keeps its bullets. Put each nested ul after the item's text and before its </li>.

Show solution
course.html
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>HTML for Beginners</title>
  <style>
    .menu { list-style: none; padding: 0; display: flex; gap: 1rem; }
  </style>
</head>
<body>
  <nav aria-label="Main">
    <ul class="menu" role="list">
      <li><a href="/">Home</a></li>
      <li><a href="/lessons/">Lessons</a></li>
      <li><a href="/pricing/">Pricing</a></li>
    </ul>
  </nav>

  <h2>What's included</h2>
  <ul>
    <li>Videos
      <ul>
        <li>38 short lessons</li>
        <li>Captions in English and Myanmar</li>
      </ul>
    </li>
    <li>Downloads
      <ul>
        <li>Starter files for every lesson</li>
        <li>A printable cheat sheet</li>
      </ul>
    </li>
  </ul>
</body>
</html>

Quick quiz 1 / 3

Which way of writing a sub-list is valid?

Quick quiz 2 / 3

What does ul/li give screen reader users that <p>• Free delivery</p> paragraphs do not?

Quick quiz 3 / 3

On a recipe page, which part should be a ul?

What to remember

  • Use ul when shuffling the items would not change their meaning.
  • Only li may be a direct child of ul; inside an li you can put links, paragraphs or a sub-list.
  • Nest a sub-list inside its parent item's li and close that </li> after the sub-list.
  • Restyle or hide bullets with CSS, and keep the list semantics even in a navigation menu.

HTML Living Standard — Sections and Semantics — WHATWG

Updated on

Progress is saved only in this browser on this device. It isn't synced to other devices.

Report a problem with this lessonOpens your email app with this lesson's address filled in — nothing is sent until you send it.

Unordered Lists | Thuta Learning