# Description & Nested Lists

> When your data is pairs of terms and values, `<dl>` fits better than a `<ul>`. And when a list item has sub-items, nesting a second list inside the `<li>` is exactly right.

Subject: HTML | Lesson 9 of 42 | 5 min read
Interactive lesson: https://codewithanimation.in/html/description-and-nested-lists
Previous: [Unordered & Ordered Lists](https://codewithanimation.in/html/lists.md) | Next: [Meaning vs Appearance](https://codewithanimation.in/html/strong-em-vs-b-i.md)

## What they are

`<dl>` is the description list. It groups any set of term-value pairs using two inner tags: `<dt>` for the term and `<dd>` for its description. Despite the old name, definition list, HTML5 broadened the scope: `<dl>` is not only for dictionaries. Metadata panels, FAQ sections, and any key-value grouping all fit.

A nested list is just a `<ul>` or `<ol>` placed inside an `<li>`. Because list items can hold any block content, nesting comes naturally, and the browser indents each level automatically.

## Why it matters

When you reach for two `<p>` tags to write a term and its description, a screen reader reads them as two unrelated paragraphs with no structural connection. `<dl>` tells the browser, and any tool reading the page, that each `<dt>` and the `<dd>` below it belong together as a pair.

Nested lists communicate hierarchy. A flat `<ul>` of breadcrumbs and sourdough reads as equals. Moving sourdough inside a nested list under bread tells the reader that sourdough is a kind of bread, not a sibling of it. The structure carries information that prose alone cannot.

## How it works

Inside a `<dl>`, alternate `<dt>` and `<dd>` elements. The pairings are flexible: one `<dt>` can have multiple `<dd>` entries when a term has several meanings, and multiple `<dt>` elements can share one `<dd>` when several terms have the same description. There is no mandatory one-to-one ratio.

For nested lists, place the child `<ul>` or `<ol>` inside the `<li>` that owns it, before the closing `</li>` tag. This is where the nesting lives in the content model. A common mistake is placing the nested list after the closing `</li>` of the parent item, which makes it a sibling, not a child, and breaks the hierarchy both visually and semantically.

## Common mistake: Nesting a list after the closing </li> instead of inside it

It is easy to write the label text, close the `</li>`, then start the nested `<ul>`. The markup may render roughly correctly in some browsers, but the structure is wrong: the nested list is now a sibling of the parent item, not a child. Always open the nested `<ul>` or `<ol>` before you close the `</li>` that owns it.

## Tip: <dl> works for any key-value data, not just dictionaries

An article byline, a product spec sheet, a recipe metadata block (prep time, serves, difficulty), a FAQ where questions are terms and answers are descriptions: these all fit `<dl>` precisely. Reach for it whenever you have named data where every piece of information is the value of something.

## Try it: Try it

See a `<dl>` pair in action and how a nested `<ul>` indents sub-items under the parent list item.

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/html/description-and-nested-lists

## Check yourself

### Question 1

You are marking up an article sidebar: Author, Date, and Category, each with its value. What is the best element?

- A. <dl> with <dt> for labels and <dd> for values
- B. <ul> with <li> for each pair
- C. Two <p> tags per row, one for the label and one for the value

Correct answer: A

`<dl>` is designed for exactly this: grouped term-value pairs. Each label is a `<dt>` and each value is a `<dd>`, and any tool reading the page knows they belong together.

- Why not B: A <ul> groups peer items. These are not peers; each label and value form a pair. <dl> expresses that relationship.
- Why not C: Separate paragraphs have no structural connection. A screen reader reads them as independent sentences, not paired data.

### Question 2

Where does a nested <ul> live in the markup?

- A. Inside the <li> that owns it, before the closing </li>
- B. After the closing </li>, as the next sibling
- C. Inside the parent <ul>, but not inside any <li>

Correct answer: A

The nested list belongs inside the `<li>`, before `</li>`. The content model of `<li>` allows block content including another list, and that is how hierarchy is encoded.

- Why not B: That makes the nested list a sibling of the parent item, not a child of it, breaking the hierarchy.
- Why not C: A <ul> inside a <ul> without an <li> wrapper is invalid. Only <li> is a valid direct child of <ul>.

### Question 3

Is a <dl> limited to one <dt> matched with exactly one <dd>?

- A. No. One <dt> can have multiple <dd>, and multiple <dt> can share one <dd>
- B. Yes, each <dt> must pair with exactly one <dd>
- C. No, but only one <dd> per <dt> is valid; multiple <dt> per <dd> is allowed

Correct answer: A

The `<dl>` content model is flexible: one term to many descriptions and many terms to one description are both valid. This covers cases like a word with multiple meanings or several synonyms sharing a single definition.

- Why not B: The HTML spec places no such restriction. A term can have several descriptions, and several terms can share one description.
- Why not C: Both directions are valid: one <dt> with many <dd>, and many <dt> with one <dd>.

## Remember this

- `<dl>` groups term-value pairs using `<dt>` (term) and `<dd>` (description); it is not limited to dictionaries.
- One `<dt>` can have multiple `<dd>` entries; multiple `<dt>` can share one `<dd>`.
- Nested lists live inside the `<li>` that owns them, before the closing `</li>` tag.
- Each nesting level is a new `<ul>` or `<ol>` inside an `<li>`, never placed directly inside the parent list.
