HTML Lists Guide

Lists are essential HTML elements that help you organize content in a structured, easily scannable format. This guide covers the different types of lists and how to use them effectively.

1. Unordered Lists

The <ul> element represents an unordered list of items, typically rendered as a bulleted list. Each list item is defined with the <li> element.

<ul> <li>First item</li> <li>Second item</li> <li>Third item</li> </ul>
  • First item
  • Second item
  • Third item

Styling Unordered Lists

<ul style="list-style-type: disc;"> <li>Disc bullets (default)</li> </ul> <ul style="list-style-type: circle;"> <li>Circle bullets</li> </ul> <ul style="list-style-type: square;"> <li>Square bullets</li> </ul> <ul style="list-style-type: none;"> <li>No bullets</li> </ul>
  • Disc bullets (default)
  • Circle bullets
  • Square bullets
  • No bullets
Note: While you can change bullet styles with CSS's list-style-type property, it's generally recommended to keep styling in your CSS rather than inline.

2. Ordered Lists

The <ol> element represents an ordered list of items, typically rendered as a numbered list. Each list item is defined with the <li> element.

<ol> <li>First item</li> <li>Second item</li> <li>Third item</li> </ol>
  1. First item
  2. Second item
  3. Third item

Ordered List Attributes

Attribute Value Description
type 1, A, a, I, i Specifies the numbering type (numbers, uppercase letters, lowercase letters, uppercase Roman numerals, lowercase Roman numerals)
start number Specifies the starting number/value
reversed reversed Specifies that the list order should be descending

Different Numbering Types

<ol type="1"> <li>Numbers (default)</li> <li>Second item</li> </ol> <ol type="A"> <li>Uppercase letters</li> <li>Second item</li> </ol> <ol type="a"> <li>Lowercase letters</li> <li>Second item</li> </ol> <ol type="I"> <li>Uppercase Roman numerals</li> <li>Second item</li> </ol> <ol type="i"> <li>Lowercase Roman numerals</li> <li>Second item</li> </ol>
  1. Numbers (default)
  2. Second item
  1. Uppercase letters
  2. Second item
  1. Lowercase letters
  2. Second item
  1. Uppercase Roman numerals
  2. Second item
  1. Lowercase Roman numerals
  2. Second item

Starting Value and Reversed Order

<!-- Start from 5 --> <ol start="5"> <li>This item is number 5</li> <li>This item is number 6</li> </ol> <!-- Reversed order --> <ol reversed> <li>This will be 3</li> <li>This will be 2</li> <li>This will be 1</li> </ol>
  1. This item is number 5
  2. This item is number 6
  1. This will be 3
  2. This will be 2
  3. This will be 1

3. Description Lists

The <dl> element represents a description list, which consists of term-description pairs. Each term is defined with a <dt> element, and each description is defined with a <dd> element.

<dl> <dt>HTML</dt> <dd>HyperText Markup Language, the standard markup language for creating web pages.</dd> <dt>CSS</dt> <dd>Cascading Style Sheets, a style sheet language used for describing the presentation of a document written in HTML.</dd> <dt>JavaScript</dt> <dd>A programming language that enables interactive web pages.</dd> </dl>
HTML
HyperText Markup Language, the standard markup language for creating web pages.
CSS
Cascading Style Sheets, a style sheet language used for describing the presentation of a document written in HTML.
JavaScript
A programming language that enables interactive web pages.

Multiple Terms or Descriptions

<!-- Multiple terms, one description --> <dl> <dt>Firefox</dt> <dt>Mozilla Firefox</dt> <dd>A free, open-source web browser developed by the Mozilla Foundation.</dd> </dl> <!-- One term, multiple descriptions --> <dl> <dt>HTML</dt> <dd>Stands for HyperText Markup Language.</dd> <dd>The standard language for creating web pages and applications.</dd> </dl>
Firefox
Mozilla Firefox
A free, open-source web browser developed by the Mozilla Foundation.
HTML
Stands for HyperText Markup Language.
The standard language for creating web pages and applications.
Use Case: Description lists are perfect for glossaries, dictionaries, FAQs, and any content that has a name-value relationship.

4. Nested Lists

Lists can be nested inside one another to create hierarchical structures:

<ul> <li>Fruits <ul> <li>Apples <ul> <li>Granny Smith</li> <li>Honeycrisp</li> <li>Gala</li> </ul> </li> <li>Bananas</li> <li>Oranges</li> </ul> </li> <li>Vegetables <ul> <li>Carrots</li> <li>Broccoli</li> <li>Spinach</li> </ul> </li> </ul>
  • Fruits
    • Apples
      • Granny Smith
      • Honeycrisp
      • Gala
    • Bananas
    • Oranges
  • Vegetables
    • Carrots
    • Broccoli
    • Spinach

You can also mix different types of lists:

<ol> <li>Step 1 <ul> <li>Important note for step 1</li> <li>Another note for step 1</li> </ul> </li> <li>Step 2 <ul> <li>Important note for step 2</li> <li>Another note for step 2</li> </ul> </li> </ol>
  1. Step 1
    • Important note for step 1
    • Another note for step 1
  2. Step 2
    • Important note for step 2
    • Another note for step 2

5. List Item Values

The value attribute can be used on individual list items in an ordered list to override the automatic numbering:

<ol> <li>First item</li> <li>Second item</li> <li value="10">This will be item 10</li> <li>This will be item 11</li> <li value="20">This will be item 20</li> <li>This will be item 21</li> </ol>
  1. First item
  2. Second item
  3. This will be item 10
  4. This will be item 11
  5. This will be item 20
  6. This will be item 21
Note: The value attribute is only valid for <li> elements within <ol> elements, not within <ul> or <dl>.

6. Styling Lists with CSS

Here are some common CSS properties used to style lists:

<style> .custom-list { list-style-type: square; /* Type of bullet */ list-style-position: outside; /* Position of bullet (outside or inside) */ list-style-image: url('bullet.png'); /* Custom bullet image */ padding-left: 20px; /* Adjust the indentation */ } .custom-list li { margin-bottom: 10px; /* Space between items */ padding: 5px; /* Padding inside each item */ background-color: #f0f0f0; /* Background color for items */ } /* Shorthand property */ .shorthand-list { list-style: square inside url('bullet.png'); } </style>

Advanced List Styling Examples

<!-- Horizontal list (often used for navigation) --> <style> .horizontal-list { list-style-type: none; padding: 0; margin: 0; display: flex; } .horizontal-list li { margin-right: 15px; } </style> <ul class="horizontal-list"> <li>Home</li> <li>About</li> <li>Services</li> <li>Contact</li> </ul>
  • Home
  • About
  • Services
  • Contact
<!-- Custom counters with CSS --> <style> .custom-counters { list-style-type: none; counter-reset: item; padding-left: 0; } .custom-counters li { counter-increment: item; margin-bottom: 10px; } .custom-counters li::before { content: "Section " counter(item) ": "; font-weight: bold; color: #e74c3c; } </style> <ol class="custom-counters"> <li>Introduction</li> <li>Main Content</li> <li>Conclusion</li> </ol>
  1. Section 1: Introduction
  2. Section 2: Main Content
  3. Section 3: Conclusion

7. Best Practices

8. Browser Support

All list elements have excellent browser support across all modern browsers:

CH
Chrome
Yes
FF
Firefox
Yes
SF
Safari
Yes
ED
Edge
Yes
OP
Opera
Yes
IE
IE 11
Yes