Menu
Coddy logo textTech

Nested Lists

Part of the Fundamentals section of Coddy's HTML journey — lesson 14 of 60.

You can place one list inside another—this is called a nested list. This is useful for creating hierarchical structures, such as outlines or multi-level menus. 

To create a nested list, you simply place an <ul> or <ol> element inside an <i><li></i> element of another list.

Here's an example of a nested unordered list:

<ul>
  <li>Item 1</li>
  <li>Item 2
    <ul>
      <li>Subitem 2.1</li>
      <li>Subitem 2.2</li>
    </ul>
  </li>
  <li>Item 3</li>
</ul>

The second item contains a nested list with two subitems. In the browser, it will display like this:

  • Item 1
  • Item 2
    • Subitem 2.1
    • Subitem 2.2
  • Item 3

You can also nest ordered lists or mix both. 

challenge icon

Challenge

Easy

Create an HTML document with a nested list. The list should look like this:

  • Fruits
    1. Apple
    2. Banana
    3. Orange
  • Vegetables
    • Carrot
    • Broccoli
    • Spinach
  • Grains

Cheat sheet

A nested list is created by placing a <ul> or <ol> element inside an <li> element of another list:

<ul>
  <li>Item 1</li>
  <li>Item 2
    <ul>
      <li>Subitem 2.1</li>
      <li>Subitem 2.2</li>
    </ul>
  </li>
  <li>Item 3</li>
</ul>

You can nest ordered lists or mix both ordered and unordered lists within each other.

Try it yourself

<!DOCTYPE html>
<html>
    <body>
        <!-- Write code here -->
    </body>
</html>
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals