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>
Note: The old 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
  1. Boil water
  2. Add tea leaves
  3. Steep for 3–5 minutes
  4. 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")
  1. Plan
  2. Design
  3. Build
Start at 5 (start="5")
  1. Fifth item
  2. Sixth item
  3. Seventh item
Countdown (reversed start="3")
  1. Launch
  2. Test
  3. 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>
Related <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.
Note: Like <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

Using Lists for Navigation

Most navigation menus on modern websites are built using lists. A navigation list is typically wrapped in a <nav> element and styled with CSS to appear horizontally across the top of the page or vertically as a sidebar.

Example: Simple Navigation Menu
HTML Code:
<nav>
    <ul>
        <li><a href="#">Home</a></li>
        <li><a href="#">About</a></li>
        <li><a href="#">Services</a></li>
        <li><a href="#">Contact</a></li>
    </ul>
</nav>

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.