Master Code
On The Go

Learn. Practice. Build.

Home › Code Snippets › HTML Snippets › Reference › <ul> & <ol>

HTML Reference

<ul> & <ol> — List Elements

The two list elements that structure content, navigation, and steps. Plus the description list family.

Last updated: October 2026

Definition: HTML has three list elements — <ul> (unordered, bullet points), <ol> (ordered, numbered), and <dl> (description, term-definition pairs). List items inside ul and ol are wrapped in <li>.

🎬 Live Example

The three list types, side by side.

<ul> Unordered
  • HTML
  • CSS
  • JavaScript
<ol> Ordered
  1. Install Node.js
  2. Create a project
  3. Run the server
<dl> Description
HTML
Structure of the web
CSS
Styling and layout

💡 Choose based on meaning, not appearance. Use <ol> whenever sequence matters.

📝

Basic Syntax

<!-- Unordered list -->
<ul>
    <li>Item one</li>
    <li>Item two</li>
    <li>Item three</li>
</ul>

<!-- Ordered list -->
<ol>
    <li>First step</li>
    <li>Second step</li>
    <li>Third step</li>
</ol>

⚙️ Attributes Reference

Only <ol> has specific attributes. <ul> and <li> use only global attributes.

Element Attribute Purpose
<ol>typeNumbering style: 1 (default), A, a, I, i.
<ol>startStart number. Default 1.
<ol>reversedReverse the numbering.
<li>valueOverride the number for this item only.
Allid, class, style, etc.Global attributes.
1

Unordered List <ul>

Use when the order of items doesn't matter. Renders as bullet points by default.

<ul>
    <li>HTML</li>
    <li>CSS</li>
    <li>JavaScript</li>
</ul>

Common uses:

  • Feature lists on a landing page
  • Navigation menus (with CSS list-style: none)
  • Ingredients, tags, categories
  • Bullet point lists in articles
2

Ordered List <ol>

Use when the sequence of items matters. Renders as numbered steps.

<ol>
    <li>Install Node.js</li>
    <li>Run npm install</li>
    <li>Start the dev server</li>
</ol>

Advanced usage with type, start, and reversed:

<!-- Start from 5 -->
<ol start="5">
    <li>Fifth item</li>
    <li>Sixth item</li>
</ol>

<!-- Uppercase letters -->
<ol type="A">
    <li>Option A</li>
    <li>Option B</li>
</ol>

<!-- Roman numerals, reversed -->
<ol type="I" reversed>
    <li>Countdown 3</li>
    <li>Countdown 2</li>
    <li>Countdown 1</li>
</ol>
3

Nested Lists

Place a nested <ul> or <ol> inside an <li> to create a sublist.

<ul>
    <li>Frontend
        <ul>
            <li>HTML</li>
            <li>CSS</li>
            <li>JavaScript</li>
        </ul>
    </li>
    <li>Backend
        <ul>
            <li>Node.js</li>
            <li>Python</li>
            <li>PostgreSQL</li>
        </ul>
    </li>
</ul>

This renders with increasing indentation for each level. Use it for outlines, file trees, and multi-level navigation.

4

Description List <dl>

Term-definition pairs. Use it for glossaries, FAQs, and metadata.

<dl>
    <dt>HTML</dt>
    <dd>HyperText Markup Language. The structure of the web.</dd>

    <dt>CSS</dt>
    <dd>Cascading Style Sheets. Styling and layout.</dd>

    <dt>JavaScript</dt>
    <dd>The programming language of the web.</dd>
</dl>

You can also have multiple <dd> elements per <dt>:

<dl>
    <dt>Coffee</dt>
    <dd>Hot beverage made from roasted beans.</dd>
    <dd>Also a programming term: "Java" is not "JavaScript".</dd>
</dl>
5

Styling Lists

Common CSS patterns for lists.

/* Remove bullets (great for navigation menus) */
ul.no-bullets {
    list-style: none;
    padding: 0;
}

/* Custom bullet with an emoji or icon */
ul.custom li::before {
    content: "→ ";
    color: #3b82f6;
    font-weight: 700;
}

/* Horizontal nav from a ul */
nav ul {
    display: flex;
    gap: 1.5rem;
    list-style: none;
    padding: 0;
}

/* Remove default padding from lists */
ul, ol {
    padding-left: 1.25rem;
}

/* Space out list items */
li {
    margin-bottom: 0.5rem;
}

🎯 Choosing the Right List Type

Element Use when Example
<ul>Order doesn't matterFeatures, tags, related links
<ol>Order mattersTutorial steps, rankings
<dl>Term-definition pairsGlossaries, FAQs, metadata
<div>Not a listNavigation menus (still use <ul>!)

💡 Important: Even navigation menus should use <ul> for the links. Then use CSS to make it horizontal. Screen readers announce the list structure.

⚠️ Common Mistakes

♿ Accessibility Notes

❓ Frequently Asked Questions

What is the difference between ul and ol?

ul (unordered list) is for items where order doesn't matter — bullet points. ol (ordered list) is for items where sequence matters — numbered steps. Choose based on meaning, not appearance.

What is the li tag?

li (list item) is the child element of ul and ol. Every item in a list is wrapped in li. You cannot have a ul or ol without li children.

What is the dl tag?

dl (description list) is for term-definition pairs. It contains dt (description term) and dd (description details). Use it for glossaries, FAQs, and metadata.

Can I nest lists?

Yes. Place a nested ul or ol inside an li element. This creates sublists for multi-level content like outlines or navigation menus.

How do I remove the bullet points from a list?

Use CSS: list-style: none. This is common for navigation menus built with ul. Never remove list semantics — screen readers still announce the list correctly.

🎯 What's Next?

← All HTML Reference