HTML Lists
Organize content using unordered, ordered, and description lists
Introduction to HTML Lists
What are HTML Lists?
HTML lists are used to group related items. They are essential for navigation menus, feature lists, steps, and many other UI patterns.
HTML supports three main types of lists:
- Unordered lists (
<ul>) – items with bullet points where order is not important. - Ordered lists (
<ol>) – items that are numbered or lettered, where order/sequence matters. - Description lists (
<dl>) – term/description pairs, ideal for glossaries and key–value data.
You will use lists everywhere in real projects: navigation menus, feature highlights, FAQs, steps in a process, and more. Understanding how each list type works will make your HTML more structured and easier to style with CSS.
Unordered Lists (<ul>)
Use an unordered list when the order of items doesn’t matter and you simply want to group related pieces of information. By default, browsers render unordered lists with solid bullet markers, but the appearance can be fully customized using CSS.
Example: Shopping List
- Milk
- Bread
- Eggs
- Vegetables
HTML Code:
<ul>
<li>Milk</li>
<li>Bread</li>
<li>Eggs</li>
<li>Vegetables</li>
</ul>
All <ul> Attributes
The <ul> element has no required attributes. List items must be wrapped in <li> children. Most styling is done with CSS (list-style-type, margins, etc.), not HTML attributes.
| Attribute | Applies to | Description | Example |
|---|---|---|---|
type |
<ul> |
Obsolete. Sets bullet style: disc, circle, or square. Prefer CSS list-style-type. |
<ul type="square"> |
id |
Global | Unique identifier for the list (links, CSS, JavaScript). | <ul id="nav-menu"> |
class |
Global | One or more class names for CSS or JS hooks. | <ul class="features list-unstyled"> |
style |
Global | Inline CSS (avoid when possible; use stylesheets). | <ul style="list-style-type: none;"> |
title |
Global | Advisory tooltip text on hover. | <ul title="Site sections"> |
lang |
Global | Language of list content (helps screen readers and SEO). | <ul lang="en"> |
dir |
Global | Text direction: ltr (left-to-right) or rtl (right-to-left). |
<ul dir="rtl"> |
hidden |
Global | Boolean. Hides the list from display and accessibility tree until removed. | <ul hidden> |
role |
Global / ARIA | Usually not needed—<ul> already has list semantics. Use only for special cases (e.g. role="menu" with keyboard support). |
<ul role="list"> |
aria-label |
ARIA | Accessible name when visible label text is missing. | <ul aria-label="Footer links"> |
data-* |
Global | Custom data attributes for JavaScript. | <ul data-section="products"> |
Example: Custom bullets with CSS (recommended)
<!-- Avoid obsolete type="" on ul; use CSS instead -->
<ul class="checklist">
<li>Free shipping</li>
<li>30-day returns</li>
<li>24/7 support</li>
</ul>
<style>
.checklist {
list-style-type: square; /* disc | circle | square | none */
padding-left: 1.5rem;
}
</style>
compact attribute is obsolete and not used in HTML5. Spacing is controlled with CSS (margin, padding, line-height).
Ordered Lists (<ol>)
Use an ordered list when the sequence of items is important. This is common for instructions, rankings, timelines, and any data where position has meaning. Ordered lists can be numbered with digits, letters, or even Roman numerals using the type attribute.
Example: Steps to Make Tea
- Boil water
- Add tea leaves
- Steep for 3–5 minutes
- Pour and serve
HTML Code:
<ol>
<li>Boil water</li>
<li>Add tea leaves</li>
<li>Steep for 3–5 minutes</li>
<li>Pour and serve</li>
</ol>
All <ol> Attributes
The <ol> element has three list-specific attributes in HTML5 (type, start, reversed) plus all global attributes. Only <li> elements are valid direct children (aside from script-support elements).
| Attribute | Values | Description | Example |
|---|---|---|---|
type |
1, a, A, i, I |
Legacy / obsolete. Sets numbering style: digits, lowercase/uppercase letters, or Roman numerals. Still works in browsers; prefer CSS list-style-type for new pages. |
<ol type="A"> |
start |
Integer (e.g. 1, 5, 10) |
Number of the first list item. Default is 1. Useful when a list continues from a previous section. |
<ol start="5"> |
reversed |
Boolean (presence = true) | Counts down instead of up. Works with start as the highest number. |
<ol reversed start="3"> |
id |
Global | Unique identifier for the ordered list. | <ol id="recipe-steps"> |
class |
Global | CSS/JS class names. | <ol class="steps numbered"> |
style |
Global | Inline CSS styles. | <ol style="list-style-type: lower-roman;"> |
title |
Global | Tooltip text shown on hover. | <ol title="Installation steps"> |
lang / dir |
Global | Language and text direction for the list content. | <ol lang="en" dir="ltr"> |
hidden |
Global | Boolean. Hides the list until the attribute is removed. | <ol hidden> |
aria-label |
ARIA | Accessible name when no visible heading describes the list. | <ol aria-label="Top 5 features"> |
data-* |
Global | Custom data for scripts. | <ol data-step-group="checkout"> |
List-specific attribute examples
Uppercase letters (type="A")
- Plan
- Design
- Build
Start at 5 (start="5")
- Fifth item
- Sixth item
- Seventh item
Countdown (reversed start="3")
- Launch
- Test
- Prepare
HTML Code: All three list-specific attributes
<!-- Numbering style (legacy; CSS is preferred) -->
<ol type="i">
<li>Introduction</li>
<li>Methods</li>
</ol>
<!-- Continue numbering from a previous list -->
<ol start="3">
<li>Third chapter</li>
<li>Fourth chapter</li>
</ol>
<!-- Count down from 3 to 1 -->
<ol reversed start="3">
<li>Step three</li>
<li>Step two</li>
<li>Step one</li>
</ol>
<!-- CSS equivalent for numbering style -->
<ol class="roman-list">...</ol>
<style>.roman-list { list-style-type: lower-roman; }</style>
<li> attribute: On ordered lists, each <li value="7"> sets the marker number for that item and updates numbering for following items. This is separate from <ol start> but often used together in long documents.
<ul>, the old compact attribute on <ol> is obsolete. Use CSS for spacing between items.
Description Lists (<dl>)
Description lists are used for name/value pairs such as terms and definitions. They are perfect for glossaries, metadata, or any content where you have a label followed by a more detailed explanation.
Example: Glossary
- HTML
- HyperText Markup Language – structures web content.
- CSS
- Cascading Style Sheets – styles and lays out web pages.
- JavaScript
- Scripting language that adds interactivity to websites.
HTML Code:
<dl>
<dt>HTML</dt>
<dd>HyperText Markup Language...</dd>
<dt>CSS</dt>
<dd>Cascading Style Sheets...</dd>
</dl>
Nested Lists
You can nest lists to represent hierarchies (for example, multi-level menus, outlines, or categories and sub‑categories). Each nested list is simply another <ul> or <ol> placed inside a parent <li> element.
Example: Course Outline
- HTML Basics
- Tags
- Attributes
- Document Structure
- CSS Basics
- Selectors
- Box Model
Best Practices
- Choose
<ul>vs<ol>based on whether order matters. - Wrap each list item in its own
<li>tag. - Use lists for navigation menus and grouped information instead of multiple paragraphs with line breaks.
- Keep nested lists clear and well-indented for readability.
- Use CSS to customize list bullets and numbering instead of deprecated HTML attributes.