Home

How to Create Numbered Lists in HTML5

|
|  Updated:  
2016-03-26 14:02:52
HTML5 and CSS3 All-in-One For Dummies
Explore Book
Buy On Amazon

Lists are powerful tools to group similar elements, and lists give visitors to your site an easy way to zoom in on groups of information. Just about anything fits in a list, from sets of instructions to collections of links. A numbered list consists of at least two items, each prefaced by a number. Use a numbered list when the order or priority of items is important.

You use two kinds of elements for a numbered list:

  • The ordered list element (

      ) specifies a numbered list.

    1. List item elements (

    2. ) mark each item in the list.

    A numbered list with three items requires elements and content in the following order:

      1. Content for the first list item

      2. Content for the second list item

      3. Content for the third list item

      The following markup defines a three-item numbered list:

      <!DOCTYPE html>
      <html>
        <head>
          <meta charset="UTF-8">
          <title>Numbered Lists</title>
        </head>
        <body>
          <h1>Things to do today</h1>
          <ol>
            <li>Feed cat</li>
            <li>Wash car</li>
            <li>Grocery shopping</li>
          </ol>
        </body>
      </html>

      This figure shows how a browser renders this markup. You don’t have to specify a number for each item in a list; the browser identifies list items from the markup and adds numbers, including a period after each one by default.

      image0.jpg

      If you swap the first two items in the list, they’re still numbered in order when the page appears, as shown in this figure.

      image1.jpg
          <ol>
            <li>Wash car</li>
            <li>Feed cat</li>
            <li>Grocery shopping</li>
          </ol>

      About This Article

      This article is from the book: 

      About the book author:

      Ed Tittel is a 28-year veteran of the computer industry. A seasoned author and consultant, Ed has more than 140 books to his credit.

      Chris Minnick is an accomplished author, teacher, and programmer. Minnick authored or co-authored over 20 books, including titles in the For Dummies series. He has developed video courses for top online training platforms and he teaches programming and machine learning to professional developers at some of the largest global companies.