HTML and CSS

Lesson 4 of 10

Lesson ยท 8 min

Lists

Two kinds of list

HTML has two main kinds of list. Both use li elements for the items.

  • ul is an unordered list. The browser shows a bullet before each item.
  • ol is an ordered list. The browser shows a number before each item.

Use ol when the order matters, such as the steps of a recipe. Use ul when it does not.

<ul>
  <li>Bread</li>
  <li>Cheese</li>
</ul>

<ol>
  <li>Slice the bread</li>
  <li>Add the cheese</li>
</ol>

The only direct children of a ul or an ol are li elements.

Lists inside lists

To make a sub-list, put a new ul or ol inside an li. Do not put it between two li elements.

<ul>
  <li>Fruit
    <ul>
      <li>Pear</li>
      <li>Plum</li>
    </ul>
  </li>
  <li>Bread</li>
</ul>

The browser indents the inner list and changes its bullet.

Your turn

Add the three lists in the editor. Indenting your code is not required, but it makes the nesting easier to see.

Tasks

3 to do

  1. Task 1, not checked yet. Add a bulleted list with the ul element. It has three items in this order: Water, Map, Snacks. Use an li element for each item.

  2. Task 2, not checked yet. Add a numbered list with the ol element. The steps are Boil the water, Add the tea, Wait three minutes.

  3. Task 3, not checked yet. Inside the Snacks item, add a second ul with two items: Apples and Nuts.

Task 1 of 3

Add a bulleted list with the ul element. It has three items in this order: Water, Map, Snacks. Use an li element for each item.

All tasks

index.html

Ctrl+Enter runs your code. Ctrl+Shift+Enter checks it. Press Esc, then Tab, to leave the editor.

Preview

Your page shows here