Write an HTML program to create an ordered and a nested list

Description: Create a numbered list of three steps that starts from number 5. Then create a nested list of Fruits and Vegetables with two sub items each.

Hint:

  • Use <ol start="5"> to start from 5.
  • For a nested list, put a new <ul> inside an <li>.

HTML program for ordered and nested lists

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Lists</title>
</head>
<body>
  <ol start="5">
    <li>Open the editor</li>
    <li>Write the code</li>
    <li>Save the file</li>
  </ol>

  <ul>
    <li>Fruits
      <ul>
        <li>Apple</li>
        <li>Mango</li>
      </ul>
    </li>
    <li>Vegetables
      <ul>
        <li>Potato</li>
        <li>Tomato</li>
      </ul>
    </li>
  </ul>
</body>
</html>

Output in the browser:

Output in the browser
  1. Open the editor
  2. Write the code
  3. Save the file
  • Fruits
    • Apple
    • Mango
  • Vegetables
    • Potato
    • Tomato

How it works

  • The start attribute sets the first number of an ordered list.
  • The inner <ul> is inside the <li> of its parent item, so it shows as a sub list.

Read HTML Lists.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.