How to Create HTML Nested Lists with Examples

html nested lists

In this article, you will learn how the browsers read nested lists in HTML and how to use them with clear examples.

What are HTML Nested Lists?

A nested list is a list inside another list in HTML.

A browser shows a main list, then indents a sub-list. The browser reads a parent list item, then finds a child list inside. The browser then shows that child list under the parent item.

Here is an example:

<ul>
  <li>Item one
    <ul>
      <li>Sub-item one</li>
      <li>Sub-item two</li>
    </ul>
  </li>
  <li>Item two</li>
</ul>

This shows one unordered list with a nested sub-list inside the first item. The browser reads the outer list, then reads the inner list under the first item.

You may forget to close a <ul> or <ol> tag. You may place the nested list outside the <li> tag.

The Difference Between Ordered and Unordered Nested Lists

An unordered nested list uses <ul> tags. The browser shows bullet points.
An ordered nested list uses <ol> tags. The browser shows numbers.

Here is a table showing you the key differences:

FeatureUnordered Nested ListOrdered Nested List
List markerBulletNumber
Semantic useUse for items without orderUse for items with order
Nested sequenceSub-lists show bulletsSub-lists show numbers

Use an unordered nested list for topics without order. Use an ordered nested list for steps or ranked items.

Examples

Basic unordered nested list:

<ul>
  <li>Fruit
    <ul>
      <li>Apple</li>
      <li>Banana</li>
    </ul>
  </li>
</ul>

Take this example. This returns a list of fruit with sub-items. You get a bullet list, then a second bullet list inside a bullet. It shows how browsers indent sub-items under the main heading.

Ordered list with nested unordered list:

<ol>
  <li>Step 1
    <ul>
      <li>Do this</li>
    </ul>
  </li>
  <li>Step 2</li>
</ol>

Take this example. You get a numbered list for steps. It shows one step with a sub-step in bullet form. The layout reads a number, then shows a bullet list under that step.

Nested ordered lists:

<ol>
  <li>Chapter 1
    <ol>
      <li>Section 1.1</li>
      <li>Section 1.2</li>
    </ol>
  </li>
  <li>Chapter 2</li>
</ol>

Take this example. You get a number list inside a number list. It shows chapter numbers, then section numbers under each chapter. This shows how to keep a clear hierarchy.

Mixed nested list:

<ul>
  <li>Project
    <ol>
      <li>Phase one</li>
      <li>Phase two</li>
    </ol>
  </li>
  <li>Archive</li>
</ul>

Take this example. You see a bullet list with a numbered sub-list. It shows the project name, then numbered phases below. You get a mix of list types to show order inside a bullet list.

Wrapping Up

You learned what nested lists in HTML mean and how browsers show them, and how to write both ordered and unordered nested lists.

Here is a quick recap:

  • You saw what nested lists mean, how to write them, how browsers read them, how to fix nesting mistakes, how ordered and unordered types differ, and how to use examples from basic to mixed types.

FAQs

What is an HTML nested list?

HTML nested lists place one list inside another. Example:
  • Fruit
    • Apple
    • Banana
This shows a parent list with child items inside.

How do you create nested ordered and unordered lists?

Example:
  1. Step 1
  2. Step 2
    • Option A
    • Option B
  • <ol> creates numbers
  • <ul> creates bullets

Why use HTML nested lists in webpages?

  • Organize data in a clear structure
  • Show hierarchy between parent and child items
  • Improve readability of menus and outlines
Menus, outlines, and FAQs often rely on nested lists.

Can you style HTML nested lists with CSS?

Yes, you can style nested lists: ul li ul { list-style-type: square; margin-left: 20px; } This changes the nested list style and indents it.

Similar Reads

HTML Form novalidate Attribute: How it Works with Examples

The form novalidate attribute in HTML lets you skip browser checks when you submit a form. You can control errors…

HTML audio Tag: How to Embed and Control Sound in Pages

The audio tag adds sound to web pages without plugins. It gives you control to play, pause, loop, or mute…

HTML br Tag: Line Breaks

The br tag adds a single line break in HTML. It is an empty tag that does not need a…

HTML noscript Tag: How to Display Fallback When JS Is Disabled

The HTML noscript tag tells the browser what to show when JavaScript does not run. This tag targets users who…

The hidden Attribute in HTML: How it Works with Examples

The HTML hidden attribute hides elements from users but keeps them in the code. You can use it when you…

HTML Class Attribute: Use in CSS and JavaScript

The HTML class attribute helps group elements. It helps you update the page style without changing the structure of HTML.…

HTML Global Attributes Overview

HTML global attributes work on most elements. They do not depend on the tag name. You can use them with…

HTML track Tag: How to Add Subtitles to Videos

The track tag in HTML adds text tracks like subtitles and captions to media. It improves video access and helps…

HTML lang Attribute: How it Works with Examples

The HTML lang attribute tells browsers and tools what language the page uses. It helps users and search engines understand…

HTML wbr Tag: Word Break Opportunities

The <wbr> tag in HTML helps the browser decide where it can break a word. It does not force a…

Previous Article

State in React Step by Step with Examples

Next Article

Node.js HTTP Server with Examples for Beginners

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *


Subscribe to Get Updates

Get the latest updates on Coding, Database, and Algorithms straight to your inbox.
No spam. Unsubscribe anytime.