Lists Bring Order To Web Pages: Here’s The HTML Code To Create Them

Disclosure: Your support helps keep the site running! We earn a referral fee for some of the services we recommend on this page. Learn more

Sharing is caring!

Last Updated on

Lists are used all the time on the web. Articles, website navigation menus, and product features on e-commerce websites all make frequent use of lists – even when you can't tell that a list is being used just by looking at the web page.

There are three types of lists you can use, and this quick guide will show you how to use each.

  • 3 Description Lists
  • 4 Nested Lists
  • 5 Using Lists for Menus
  • 6 Styling Lists
  • 7 Closing Thoughts
  • 8 Related Elements
  • Unordered Lists

    An unordered list is a list in which the order of the list items does not matter. Unordered lists should be used when rearranging the order of the list items would not create confusion or change the meaning of the information on the list.

    The ul element opens and closes an unordered list. The items on the list are contained between list item, li, tags. A simple unordered list containing three items could be created with the following HTML.

        <li>Item A</li>
        <li>Item B</li>
        <li>Item C</li>

    Unless CSS rules are created to change the appearance of the list, the default presentation of an unordered list is to add a disc-style bullet point on the left-hand side of each list item and to indent the entire list.

    Here's how our short unordered list renders in a browser:

  • Item A
  • Item B
  • Item C
  • Ordered Lists

    Ordered lists are used for lists of items for which the order of the items does matter. The syntax for an ordered list is exactly the same as for an unordered list. However, to create an ordered list, the ol tag is used rather than the ul tag. By making this one change, we can convert the unordered list in our previous example into an ordered list.

    We're also going to change the text of the list items to make it clear that these are items that need to appear in a specific sequential order.

        <li>Step 1</li>
        <li>Step 2</li>
        <li>Step 3</li>

    As you can see below, rather than a bulleted list, we now have a numbered list.

    1. Step 1
    2. Step 2
    3. Step 3

    Changing Numbering

    There are times when you want to control the numbering of ordered lists. For example, your list may be broken up by a paragraph that appears mid-list to expand on a certain concept, or you may create a countdown list that begins at a high number and counts down. Lastly, maybe you'd rather use roman numerals. HTML and CSS make it easy to control the numbering of ordered lists.

    Creating a Countdown List

    To reverse the number of a list, simply add the reversed attributed to the opening ol tag.

    <ol reversed>
        <li>Item 3</li>
        <li>Item 2</li>
        <li>Item 1</li>

    When rendered in most browsers the numbering of this list will appear reversed.

    1. Item 3
    2. Item 2
    3. Item 1

    Note that Microsoft browsers do not support the reversed attribute. If you use this attribute, bear in mind that visitors using Internet Explorer or Edge will see standard numbering.

    Starting a List on a Specific Number

    The start attribute is used to specify the number on which an ordered list starts. For example, imagine you have a list of 5 items, and after the second and fourth items you want to add a sentence or two with additional details. You could use the following HTML to do this without restarting the list numbering after each paragraph.

        <li>Step 1</li>
        <li>Step 2</li>
    <p>A few short sentences about Item 2 that we don't want to appear appended to the list item. A second sentence of additional details</p>
    <ol start="3">
        <li>Step 3</li>
        <li>Step 4</li>
    <p>Notice that we used the <code>start</code> attribute on the <code>ol</code> tag to restart the numbering at "3" following the break in the list above. We'll use the same technique to properly number Step 5 below.</p>
    <ol start="5">
        <li>Step 5</li>

    Here's how that list renders in the browser:

    1. Step 1
    2. Step 2

    A few short sentences about Item 2 that we don't want to appear appended to the list item. A second sentence of additional details

    1. Step 3
    2. Step 4

    Notice that we used the start attribute on the ol tag to restart the numbering at “3” following the break in the list above. We'll use the same technique to properly number Step 5 below.

    1. Step 5

    Changing the Numbering Style

    You can use CSS to change the marker style of an ordered list. In addition to standard numbering (referred to as decimal in CSS), you can also use:

  • upper-roman for uppercaseroman numerals
  • lower-roman for lowercase roman numerals
  • decimal-leading-zero to add a “0” placeholder before single-digit list items
  • We cover the list-style-type CSS property used to implement these numbering styles below.

    Description Lists

    Description lists are created with the dl tag. Used far less frequently than their ordered and unordered peers, description lists are used to contain name-value groups. Each name-value group consists of one name, or term, placed between dt tags, followed by one or more values with each value, or description, placed between dd tags.

    For example, if we wanted to use a description list to explain the relationship between members of a family, we might use the following code:


    When that list is rendered, it will be displayed in such a way that the relationships between the terms (dt) and values (dd) are clear.


    Nested Lists

    A nested list is a list within a list. If you've ever created a bulleted outline in a word processing document you probably used a variety of indentations and bullet point types to denote items that were subpoints of another item in the outline. This is the effect we're going for when we create nested lists.

    To create a nested list, simply add a new list within a parent list like this:

        <li>Item A</li>
        <li>Item B
                <li>Subitem B.1</li>
                <li>Subitem B.2</li>
        <li>Item C</li>

    When that list is loaded in the browser, the nested list will be indented further than the parent list, and a different type of item marker will be displayed.

  • Item A
  • Item B
  • Subitem B.1
  • Subitem B.2
  • Item C