Lists are one of the most common content structures on the web. Whether it’s a shopping list, steps in a recipe, or definitions of terms, HTML provides semantic elements to organize them perfectly.
What you’ll learn:
Unordered lists (<ul>) for bullet points
Ordered lists (<ol>) for numbered sequences
Description lists (<dl>) for terms and definitions
Nested lists and advanced techniques
Best practices for accessible lists
Prerequisites:
Unordered lists are for items without a specific sequence. Use <ul> (unordered list) with <li> (list items):
Interactive code playground requires JavaScript. Here's the code:
<h2>Shopping List</h2>
<ul>
<li>Milk</li>
<li>Eggs</li>
<li>Bread</li>
<li>Cheese</li>
<li>Apples</li>
</ul>
The browser automatically adds bullet points. Each <li> is one item.
Interactive code playground requires JavaScript. Here's the code:
<h2>Features of Our App</h2>
<ul>
<li>Lightning-fast performance</li>
<li>Beautiful user interface</li>
<li>Cloud synchronization</li>
<li>Offline mode support</li>
</ul>
<h2>Skills You'll Learn</h2>
<ul>
<li>HTML fundamentals</li>
<li>CSS styling</li>
<li>JavaScript interactivity</li>
</ul>
Use <ol> (ordered list) when the order matters:
Interactive code playground requires JavaScript. Here's the code:
<h2>Steps to Bake Cookies</h2>
<ol>
<li>Preheat oven to 375°F</li>
<li>Mix dry ingredients</li>
<li>Add butter and sugar</li>
<li>Combine wet and dry ingredients</li>
<li>Drop on baking sheet</li>
<li>Bake for 10-12 minutes</li>
</ol>
The browser automatically numbers the items. The order is semantic—it matters for understanding.
By default, <ol> uses Arabic numbers (1, 2, 3). You can change this with the type attribute:
Interactive code playground requires JavaScript. Here's the code:
<h3>Arabic Numerals (default)</h3>
<ol>
<li>First</li>
<li>Second</li>
<li>Third</li>
</ol>
<h3>Uppercase Roman Numerals</h3>
<ol type="I">
<li>First</li>
<li>Second</li>
<li>Third</li>
</ol>
<h3>Lowercase Letters</h3>
<ol type="a">
<li>First</li>
<li>Second</li>
<li>Third</li>
</ol>
Common type values:
"1" — Arabic numerals (default)
"A" — Uppercase letters
"a" — Lowercase letters
"I" — Uppercase Roman numerals
"i" — Lowercase Roman numerals
Description lists are for terms with their descriptions. Use <dl> (description list), <dt> (term), and <dd> (definition):
Interactive code playground requires JavaScript. Here's the code:
<h2>Web Development Glossary</h2>
<dl>
<dt>HTML</dt>
<dd>HyperText Markup Language. Defines the structure and content of web pages.</dd>
<dt>CSS</dt>
<dd>Cascading Style Sheets. Controls the appearance and layout of web pages.</dd>
<dt>JavaScript</dt>
<dd>A programming language that adds interactivity and dynamic behavior to web pages.</dd>
</dl>
One term can have multiple definitions, and multiple terms can share a definition:
Interactive code playground requires JavaScript. Here's the code:
<dl>
<dt>HTTP</dt>
<dt>HTTPS</dt>
<dd>Protocols for transferring data on the web. HTTPS is the secure version.</dd>
<dt>API</dt>
<dd>Application Programming Interface. A set of rules for software communication.</dd>
<dd>Often used for web services and third-party integrations.</dd>
</dl>
Lists can contain other lists. This is useful for hierarchical information:
Interactive code playground requires JavaScript. Here's the code:
<h2>HTML Topics</h2>
<ol>
<li>Basics
<ol>
<li>Elements and tags</li>
<li>Attributes</li>
<li>Structure</li>
</ol>
</li>
<li>Content
<ol>
<li>Text and headings</li>
<li>Links and images</li>
<li>Lists</li>
</ol>
</li>
<li>Advanced
<ol>
<li>Accessibility</li>
<li>Web Components</li>
</ol>
</li>
</ol>
Nesting automatically adjusts indentation and numbering. You can mix list types too:
Interactive code playground requires JavaScript. Here's the code:
<h2>To-Do List by Category</h2>
<ul>
<li>Work
<ul>
<li>Finish report</li>
<li>Email client</li>
</ul>
</li>
<li>Home
<ul>
<li>Buy groceries</li>
<li>Clean kitchen</li>
</ul>
</li>
</ul>
List items often contain links. This is common for navigation menus and article listings:
Interactive code playground requires JavaScript. Here's the code:
<h2>Popular Articles</h2>
<ul>
<li><a href="/article/getting-started">Getting Started with HTML</a></li>
<li><a href="/article/css-basics">CSS Fundamentals</a></li>
<li><a href="/article/js-guide">JavaScript Guide</a></li>
</ul>
<h2>Favorite Websites</h2>
<ol>
<li><a href="https://mdn.mozilla.org" target="_blank">MDN Web Docs</a></li>
<li><a href="https://w3.org" target="_blank">W3C</a></li>
<li><a href="https://stackoverflow.com" target="_blank">Stack Overflow</a></li>
</ol>
Here’s a realistic combination of lists in a recipe:
Interactive code playground requires JavaScript. Here's the code:
<h1>Chocolate Chip Cookie Recipe</h1>
<h2>Ingredients</h2>
<ul>
<li>2 cups flour</li>
<li>1 cup butter, softened</li>
<li>3/4 cup sugar</li>
<li>2 eggs</li>
<li>1 tsp vanilla extract</li>
<li>1 tsp baking soda</li>
<li>2 cups chocolate chips</li>
</ul>
<h2>Instructions</h2>
<ol>
<li>Preheat oven to 375°F</li>
<li>Cream butter and sugar together
<ol type="a">
<li>Use an electric mixer</li>
<li>Mix for 2-3 minutes</li>
</ol>
</li>
<li>Add eggs and vanilla</li>
<li>Mix in flour and baking soda</li>
<li>Fold in chocolate chips</li>
<li>Bake for 10-12 minutes</li>
</ol>
<h2>Definitions</h2>
<dl>
<dt>Cream</dt>
<dd>To mix butter and sugar until light and fluffy.</dd>
<dt>Fold</dt>
<dd>To gently combine ingredients using a spatula.</dd>
</dl>
Screen readers announce lists specially. Use <ul>, <ol>, and <dl> correctly:
<!-- Good: Semantic list -->
<!-- Bad: Not semantic -->
Each <li> should contain actual content:
< li > This is a complete item </ li >
Lists are for content structure, not design:
<!-- Bad: Don't use lists for layout -->
< li > Column 1 content </ li >
< li > Column 2 content </ li >
<!-- Use CSS for layout instead -->
< div > Column 1 content </ div >
< div > Column 2 content </ div >
Create lists for different purposes:
Interactive code playground requires JavaScript. Here's the code:
<h1>My Interests</h1>
<h2>Hobbies (unordered)</h2>
<ul>
<li>Add your hobbies here</li>
<li>Add another hobby</li>
</ul>
<h2>Learning Path (ordered)</h2>
<ol>
<li>First thing to learn</li>
<li>Second thing</li>
<li>Third thing</li>
</ol>
<h2>Definitions (description list)</h2>
<dl>
<dt>Your term here</dt>
<dd>Definition of the term</dd>
</dl>
Experiment with:
Creating nested lists with multiple levels
Mixing ordered and unordered lists
Adding links inside list items
Using different type attributes for ordered lists
Using <div> or <p> Instead of Lists
Don’t replace semantic lists with generic elements:
Nesting Lists Incorrectly
Nested lists must be inside <li> elements:
<ul> for unordered lists (bullets)
<ol> for ordered lists (numbers)
<dl> for description lists (terms and definitions)
<li> for individual list items
<dt> for terms, <dd> for definitions
Lists can be nested for hierarchical information
Always use semantic list elements—don’t replace them with <div>
Proper list structure helps accessibility and SEO
Basic Structure
Learn semantic page structure with header, nav, main, and footer.
Continue →
Semantic HTML
Level up with semantic elements for better structure.
Continue →