HTML Lists
Think about the last time you went shopping, followed a recipe, or checked a to-do list. You did not read a long paragraph. You read short lines, one after another. Lists are one of the oldest and most natural ways humans organize information, and the web is full of them.
Even where you do not notice them, lists are working. A navigation menu is a list of links. A table of contents is a list of sections. A set of product features, a series of steps, a glossary of terms: all lists. In this section, you will learn how HTML marks them up, so that your content is easy to scan for people and easy to understand for browsers, search engines, and screen readers.
What You Will Learnβ
In this section, you will be able to:
- Create bullet lists with
<ul>and<li> - Create numbered lists with
<ol>, and control their start, direction, and numbering style - Create term and definition lists with
<dl>,<dt>, and<dd> - Put lists inside other lists the right way
- Change markers, spacing, and layout with CSS
- Make lists accessible and meaningful for everyone
You should know what an HTML element and an attribute are. If you need a refresher, review Paragraphs and Headings first.
Your First Listβ
Here is the smallest useful list: a bullet list of three items.
- HTML Code
- Browser Output
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
- HTML
- CSS
- JavaScript
There are two parts here:
<ul>is the list container. It says: "a group of related items starts here."<li>is a list item. Each one is a single entry in the group.
You will see this "container plus items" pattern in every kind of HTML list.
The Three Kinds of Listsβ
HTML gives you three list types. Each answers a different question.
| Type | Elements | Question it answers | Example |
|---|---|---|---|
| Unordered list | <ul> and <li> | "What are the items?" (order does not matter) | Ingredients, features, tags |
| Ordered list | <ol> and <li> | "What are the items in sequence?" (order matters) | Steps, rankings, instructions |
| Description list | <dl>, <dt>, and <dd> | "What is this term, and what does it mean?" | Glossaries, FAQs, metadata |
Let's see all three side by side.
- HTML Code
- Browser Output
<!-- 1. Unordered: order does not matter -->
<ul>
<li>Flour</li>
<li>Eggs</li>
<li>Milk</li>
</ul>
<!-- 2. Ordered: order matters -->
<ol>
<li>Mix the dry ingredients.</li>
<li>Add the eggs and milk.</li>
<li>Bake for 20 minutes.</li>
</ol>
<!-- 3. Description: terms and meanings -->
<dl>
<dt>Preheat</dt>
<dd>Warm the oven before baking.</dd>
<dt>Whisk</dt>
<dd>Beat quickly to add air.</dd>
</dl>
- Flour
- Eggs
- Milk
- Mix the dry ingredients.
- Add the eggs and milk.
- Bake for 20 minutes.
- Preheat
- Warm the oven before baking.
- Whisk
- Beat quickly to add air.
Which List Should I Use?β
The most common beginner question is "ul or ol?" Use this quick test.
If you shuffled the items, would the meaning change?
- No: use
<ul>. A shopping list works in any order. - Yes: use
<ol>. Recipe steps in the wrong order ruin the dish. - Is each entry a name paired with a description? Use
<dl>.
| Content | Best list | Why |
|---|---|---|
| Items to pack for a trip | <ul> | Any order is fine |
| Steps to install a tool | <ol> | You must follow the sequence |
| Top 5 programming languages | <ol> | The ranking is the point |
| Features of a product | <ul> | They are equal in importance |
| Glossary of tech words | <dl> | Each term has a definition |
| A website's main menu | <ul> | A group of related links |
| Author, date, and category of an article | <dl> | Names paired with values |
Beginners sometimes pick <ol> because they like numbers, or <ul> because they like bullets. Pick by meaning. You can change how a list looks with CSS later, but you cannot fix meaning with CSS.
Why Not Just Use Paragraphs or <br />?β
You could type items on separate lines with <br />, or start each line with a dash. It would look like a list. But it would not be a list.
- Fake list
- Real list
<p>
- HTML<br />
- CSS<br />
- JavaScript
</p>
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
A real list gives you things a fake one cannot:
- Screen readers announce it. Users hear "list, 3 items," and can jump from item to item.
- Browsers and search engines understand it. They know these lines belong together.
- CSS can style it. Spacing, markers, and layout are easy to control.
- It is easy to maintain. Adding, moving, or removing an item is simple and safe.
Lists You Already Use Every Dayβ
Once you know what to look for, lists are everywhere on the web.
| On a website | Marked up as |
|---|---|
| Navigation menu | <ul> inside a <nav> |
| Breadcrumb trail (Home > Courses > HTML) | <ol> |
| Search results | <ol> or <ul> |
| Pricing plan features | <ul> |
| FAQ questions and answers | <dl> |
| Comments under an article | <ul> or <ol> |
| "How to" tutorial steps | <ol> |
You already met the first one in Navigation Menus, where a list of links became a full menu.
Your Learning Pathβ
Follow the lessons in order. Each one builds on the one before.
ποΈ Unordered Lists
Learn how to create HTML unordered (bullet) lists with the ul and li elements. Understand when to use them, what can go inside list items, default styling, real-world examples like feature lists and menus, common mistakes, and best practices on CodeHarborHub.
ποΈ Ordered Lists
Learn how to create HTML ordered (numbered) lists with the ol and li elements. Master the start, reversed, and type attributes, the li value attribute, when order really matters, step-by-step instructions, rankings, accessibility, and common mistakes on CodeHarborHub.
ποΈ Description Lists
Learn how to create HTML description lists with the dl, dt, and dd elements. Pair terms with meanings for glossaries, FAQs, product specs, and metadata. Covers grouping with div, multiple terms and descriptions, styling, accessibility, and common mistakes on CodeHarborHub.
ποΈ Nested Lists
Learn how to nest HTML lists correctly. Put a ul or ol inside an li to build outlines, sub-menus, and multi-level steps. Covers mixing list types, default marker changes, the most common nesting mistake, multi-level numbering with CSS counters, accessibility, and best practices on CodeHarborHub.
ποΈ Styling Lists
Learn how to style HTML lists with CSS. Change bullet and number styles with list-style-type, control marker position, use custom images and the ::marker pseudo-element, remove bullets safely, build horizontal menus, add spacing, and number lists in other writing systems on CodeHarborHub.
ποΈ Accessible Lists
Learn how to make HTML lists accessible to everyone. Understand how screen readers announce lists, why real list markup matters, how to label lists, keep list semantics when removing bullets, build accessible navigation, breadcrumbs, and checklists, and test your lists on CodeHarborHub.
This section includes one lesson that was not in the original plan: Styling Lists (list-styling.mdx). Lists look plain by default, and almost every real project changes their markers and spacing, so it deserves its own page between nested lists and accessibility.
Rules That Apply to Every Listβ
A few rules hold for all three list types. Learn them once and you will avoid most mistakes.
- Only
<li>goes directly inside<ul>and<ol>. Text, headings, or paragraphs placed straight inside them are invalid. - Only
<dt>and<dd>go inside<dl>. You can also group each pair in a<div>. - Anything can go inside an
<li>: text, links, images, even other lists. - Do not skip levels or mix up the containers. A nested list belongs inside an
<li>, not beside it. - Do not use lists only for indentation. Lists carry meaning. If the content is not a list, do not mark it as one.
- Invalid
- Valid
<ul>
<p>HTML</p>
<li>CSS</li>
Some loose text
</ul>
<ul>
<li>HTML</li>
<li>CSS</li>
<li>Some text, now inside an item</li>
</ul>
A Real-World Exampleβ
Lists often work together. This small course card uses all three types in one place.
- HTML Code
- Browser Output
<h3>Intro to HTML</h3>
<dl>
<dt>Level</dt>
<dd>Beginner</dd>
<dt>Duration</dt>
<dd>4 weeks</dd>
</dl>
<h4>What you will learn</h4>
<ul>
<li>Page structure</li>
<li>Text, links, and images</li>
<li>Lists and tables</li>
</ul>
<h4>How the course works</h4>
<ol>
<li>Read the lesson.</li>
<li>Try the example.</li>
<li>Complete the practice.</li>
</ol>
Intro to HTML
- Level
- Beginner
- Duration
- 4 weeks
What you will learn
- Page structure
- Text, links, and images
- Lists and tables
How the course works
- Read the lesson.
- Try the example.
- Complete the practice.
Common Beginner Mistakesβ
Here are a few traps worth knowing about before you start. Each one has a lesson later.
| Mistake | What goes wrong | Where you will fix it |
|---|---|---|
Using <br /> and dashes to fake a list | Screen readers and search engines do not see a list | This page |
Choosing <ol> or <ul> by looks | Wrong meaning, wrong announcements | Unordered Lists, Ordered Lists |
Putting text or <p> directly inside <ul> | Invalid HTML | Unordered Lists |
Placing a nested list outside an <li> | Broken structure | Nested Lists |
Using <dl> for ordinary bullet items | Terms and definitions that do not exist | Description Lists |
| Removing bullets with CSS and losing the list meaning | Some screen readers stop announcing the list | Accessible Lists |
Lists for a Global Audienceβ
Lists travel across languages and cultures well, but a few habits help.
- Keep items short and parallel. Start each item the same way ("Install...", "Create...", "Run..."). Translation tools handle short, regular lines best.
- Remember that numbering styles differ. Some languages use their own numerals, and right-to-left languages place markers on the right. CSS can handle both.
- Do not rely on the visual marker alone. In an ordered list, the meaning of "step 3" should be clear from the content too.
- Set the
langattribute on your page so assistive tools read the list in the right language.
Quick Recapβ
Test yourself. Click a question to reveal the answer.
1. Which element holds the items of a bullet list, and which holds each item?
<ul> is the container, and each item is an <li>.
2. When should you choose <ol> over <ul>?
When the order of the items matters, such as steps, rankings, or instructions.
3. Which three elements make a description list?
<dl> is the list, <dt> is a term, and <dd> is its description.
4. What can go directly inside a <ul> or <ol>?
Only <li> elements. Anything else must go inside an <li>.
5. Why is a real list better than lines separated by <br />?
A real list has meaning. Screen readers announce it, search engines understand it, and CSS can style it. A fake list is only text that looks like a list.
Key Takeawaysβ
- HTML has three list types:
<ul>for unordered items,<ol>for ordered items, and<dl>for terms and descriptions. - Choose by meaning. If shuffling the items would change the sense, use
<ol>. - Only
<li>belongs directly inside<ul>and<ol>, and only<dt>and<dd>inside<dl>. - Lists are everywhere: menus, steps, glossaries, and features. Real lists help screen readers, search engines, and you.
- Keep items short and parallel, so your content works well across languages.
Ready to begin? Start with Unordered Lists.