HTML Lists
HTML Lists: Unordered, Ordered, and Description Lists
HTML lists group related items so they're easy to scan and easy to navigate with assistive technology. Many screen readers announce that a list is present and how many items it has, which tells visitors what to expect before they read it. HTML has three kinds: unordered, ordered, and description lists.
The Three Types of HTML Lists
Unordered Lists (
ul): Display bulleted items where sequence does not matter, such as feature checklists or navigation menus.Ordered Lists (
ol): Display numbered or lettered steps where order matters, such as installation instructions or recipes.Description Lists (
dl): Pair terms (dt) with their definitions (dd), ideal for glossaries or key-value metadata.
Inside ul and ol, every direct child must be an li element. To create a nested sublist, place the inner ul or ol inside an existing li, never directly inside the outer ul.
HTML Lists Example with a Nested List
To nest a sublist, put the inner <ul> or <ol> inside an existing <li>, never directly inside the outer list.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HTML Lists Example</title>
</head>
<body>
<h3>Deployment Steps</h3>
<ol>
<li>Install dependencies</li>
<li>Build assets
<ul>
<li>Compile TypeScript</li>
<li>Minify CSS bundle</li>
</ul>
</li>
<li>Restart web worker</li>
</ol>
<h3>Protocol Glossary</h3>
<dl>
<dt>HTTP</dt>
<dd>Protocol used to transfer web pages between servers and browsers.</dd>
<dt>DOM</dt>
<dd>Tree representation of HTML elements in browser memory.</dd>
</dl>
</body>
</html>The numbered list gives the order of deployment, the bulleted sublist sits inside step 2, and the description list pairs each term with its definition.
Customizing Ordered Lists
Three attributes change how an <ol> ordered list is numbered:
start="5"begins counting at 5.reversedcounts downward.type="A"uses uppercase letters (a, A, i, I, and1are also valid).
<ol start="5">
<li>Fifth item</li>
<li>Sixth item</li>
</ol>CSS can set the numbering style too, usinglist-style-type, which is often cleaner when it's a design choice.
Common Mistakes to Avoid
Putting
<div>or<h3>directly inside<ul>. Only<li>elements belong as direct children of<ul>or<ol>.Nesting a sublist outside an
<li>. Put the child list inside the parent<li>, not between two<li>elements.Faking bullets with hyphens. Typing
- Iteminside<p>tags loses the list semantics and spacing. Use a real<ul>.Using a list only for indentation. Choose lists for related items, and use CSS for layout.
Frequently Asked Questions
When should I use ul vs ol?
Use <ol> when sequence matters, such as step-by-step guides or rankings, and <ul> when items can appear in any order.
Are navigation bars normally built with ul lists?
Yes. Wrapping navigation links in a <ul> inside a <nav> is a common semantic pattern, usually styled horizontally with CSS Flexbox.
What is a description list used for?
It pairs terms with definitions, as in glossaries or metadata. Each <dt> (term) is followed by one or more <dd>(description) elements.
Can I put a list inside another list?
Yes. Place the inner <ul> or <ol> inside an <li> of the outer list.
Unlock Your
Full Potential.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Try it Yourself
Experiment with the code from this lesson in our interactive playground.