BeginnerLesson 7 of 307 min read

HTML lists: ul, ol, dl and nested lists

Use unordered, ordered and description lists, nest them correctly and build menus.

In this lesson you will

  • Choose between ul, ol and dl
  • Nest lists correctly
  • Control numbering with attributes
  • Understand why menus are lists

About 9 minutes

Three kinds of list

Lists are everywhere on the web: menus, steps, feature lists, ingredients, search results. HTML has three kinds, and choosing the right one gives your content meaning.

Kind Element Use when
Unordered <ul> Order does not matter, such as a shopping list
Ordered <ol> Sequence matters, such as recipe steps
Description <dl> Terms paired with explanations, such as a glossary

Unordered lists

<ul>
  <li>Milk</li>
  <li>Eggs</li>
  <li>Bread</li>
</ul>

The ul contains list items, and each li is one entry. Browsers add bullets and indentation by default. Only li elements may sit directly inside ul or ol. Putting a paragraph straight inside a list is invalid HTML.

Ordered lists

<ol>
  <li>Boil the water</li>
  <li>Add the noodles</li>
  <li>Wait three minutes</li>
  <li>Drain and serve</li>
</ol>

Three helpful attributes change the numbering:

<ol start="5">...</ol>          <!-- begins at 5 -->
<ol reversed>...</ol>         <!-- counts down: 3, 2, 1 -->
<ol type="a">...</ol>         <!-- a, b, c instead of 1, 2, 3 -->

Nested lists

A list item can hold another list. Place the inner list inside the li, before it closes.

<ul>
  <li>Fruit
    <ul>
      <li>Apple</li>
      <li>Banana</li>
    </ul>
  </li>
  <li>Vegetables</li>
</ul>
Common mistake

A very common error is placing the inner ul after the closing </li>, directly inside the outer ul. It often looks fine but it is invalid, and it can break screen readers and your CSS later.

Description lists

<dl>
  <dt>HTML</dt>
  <dd>The language that structures a web page.</dd>
  <dt>CSS</dt>
  <dd>The language that styles it.</dd>
</dl>

dt is the term and dd is its description. One term can have several descriptions, and one description can serve several terms. They are perfect for glossaries, FAQs, product details and metadata such as “Author: Priya”.

Turn the plain lines into a numbered recipe list with an unordered ingredients list above it.

Ingredients
Tea leaves
Water
Milk
Steps
Boil water
Add tea
Add milk and serve

Use <h2> for the two titles, a <ul> for ingredients and an <ol> for steps. Each item gets an <li>.

<h2>Ingredients</h2>
<ul>
  <li>Tea leaves</li>
  <li>Water</li>
  <li>Milk</li>
</ul>
<h2>Steps</h2>
<ol>
  <li>Boil water</li>
  <li>Add tea</li>
  <li>Add milk and serve</li>
</ol>

Why lists matter beyond bullets

Lists look like a small topic, but they underpin the web. Navigation menus are lists of links. Card grids, breadcrumb trails, pagination, tag clouds and footers are all lists dressed up with CSS. Using real lists tells screen readers “here are seven items”, which lets a visitor skip, count and understand the group. The code below is the standard pattern for a menu, and you will use it in every project.

<nav>
  <ul>
    <li><a href="/">Home</a></li>
    <li><a href="/courses/">Courses</a></li>
    <li><a href="/contact/">Contact</a></li>
  </ul>
</nav>
Choose by meaning, not by looks

If the order matters, use ol even if you plan to hide the numbers with CSS. If it does not, use ul. CSS can later remove or replace bullets entirely, so never pick a list type just for its default appearance.

Practice exercises

  1. Write an ordered list of the steps to make your favourite dish, each step one sentence.
  2. Add an unordered ingredients list with a nested list for the sauce.
  3. Create a glossary with four terms about a subject you know well, using a description list.
  4. Make a menu list of three links to pages you created earlier.

Worked example: a course outline

Here is a realistic page section that combines all three list types. Read it as a structure first, then notice how little extra markup it needs.

<h2>Learn Web Basics</h2>
<p>What you will get:</p>
<ul>
  <li>31 short lessons</li>
  <li>Live editors in every lesson</li>
  <li>Quizzes with explanations</li>
</ul>

<p>How it works:</p>
<ol>
  <li>Read the lesson</li>
  <li>Edit the example</li>
  <li>Take the quiz</li>
</ol>

<dl>
  <dt>Time needed</dt><dd>About 10 minutes a lesson</dd>
  <dt>Cost</dt><dd>Free</dd>
</dl>

With no CSS at all, this reads clearly: a benefits list, a process, and a pair of facts. That is the real value of semantic HTML. The meaning is in the markup, so every device, from a search engine to a screen reader to a smartwatch, can present it sensibly.

Lists and links together

Real lists usually contain links, bold words, and sometimes small paragraphs. You can put any inline content in an li. For example <li><a href="css.html">CSS basics</a> – style your first page</li>. If an item holds a long explanation, wrap it in a <p> inside the li, which is valid and keeps screen readers happy.

Styling a taste of what is coming

One short CSS rule turns a plain list into a horizontal menu, which shows why the list is the right element underneath. Change the colours in the editor and watch.

Add a fourth link called Contact and change the background colour of the links.

<style>
 ul{list-style:none;padding:0;display:flex;gap:10px}
 a{padding:8px 14px;background:#EFEAFD;border-radius:999px;text-decoration:none;color:#4B2BC9}
</style>
<ul>
  <li><a href="#">Home</a></li>
  <li><a href="#">Courses</a></li>
  <li><a href="#">Blog</a></li>
</ul>

Copy one of the <li> lines and change the word. For the colour, edit the background value in the a rule.

<style>
 ul{list-style:none;padding:0;display:flex;gap:10px}
 a{padding:8px 14px;background:#DDEBFF;border-radius:999px;text-decoration:none;color:#2F4BB8}
</style>
<ul>
  <li><a href="#">Home</a></li>
  <li><a href="#">Courses</a></li>
  <li><a href="#">Blog</a></li>
  <li><a href="#">Contact</a></li>
</ul>

Common mistakes with lists

  • Typing bullets by hand (“- Apple”) instead of using real list elements.
  • Using br tags to fake a list. Screen readers will not announce it as a list.
  • Leaving out the closing </li>. Browsers forgive it, but your code becomes harder to read and fix.
  • Putting a heading inside a list item to make it look big. Use real headings outside the list instead.

Check what you learned

Five quick questions. Pick an answer and you will see straight away whether it is right and why.

Which list suits a set of recipe steps?

  1. ul
  2. ol
  3. dl
  4. li

Steps happen in order, so an ordered list fits.

What may be a direct child of ul?

  1. p
  2. div
  3. li
  4. span

Only li elements belong directly inside ul or ol.

Where does a nested list go?

  1. After the closing li
  2. Inside the li it belongs to
  3. Inside the ul tag attributes
  4. Before the outer ul

The inner list sits inside its parent list item.

Which pair makes a glossary entry?

  1. li and ol
  2. dt and dd
  3. th and td
  4. h1 and p

dt is the term and dd the description inside a dl.

What does <ol start="3"> do?

  1. Shows only three items
  2. Starts numbering at 3
  3. Adds three columns
  4. Skips the first three items

The start attribute sets the first number.

Summary

  • ul for bullets, ol for sequences, dl for terms and descriptions.
  • Only li elements go directly inside ul or ol.
  • Nest inner lists inside the parent li.
  • Menus and grids are lists styled by CSS.

Next lesson

Tables: show rows and columns of data properly.

Questions

Can I change the bullet shape?

Yes, with CSS list-style properties. You can even remove bullets completely, which is how menus are made.

How many levels can I nest?

There is no limit, but more than three levels is hard to read and usually means the content needs rethinking.

Is a description list common?

Less than ul and ol, but it is the right choice for glossaries, product specs and FAQ-style pairs.

Can li contain other elements?

Yes. A list item can hold text, links, images, paragraphs and nested lists.

Progress is saved in this browser.