Lesson 8: HTML Lists

What are HTML Lists?

HTML lists allow web developers to group related items together. There are three types of lists in HTML: unordered lists, ordered lists, and description lists.

Types of Lists:

Unordered Lists (<ul>)

An unordered list starts with the <ul> tag. Each list item starts with the <li> tag. List items are marked with bullets.

HTML Code:

<ul>
    <li>Coffee</li>
    <li>Tea</li>
    <li>Milk</li>
</ul>

Output:

  • Coffee
  • Tea
  • Milk

Ordered Lists (<ol>)

An ordered list starts with the <ol> tag. Each list item starts with the <li> tag. List items are marked with numbers by default.

HTML Code:

<ol>
    <li>First step</li>
    <li>Second step</li>
    <li>Third step</li>
</ol>

Output:

  1. First step
  2. Second step
  3. Third step

Ordered List Types

You can change the numbering style using the type attribute:

HTML Code:

<ol type="A">
    <li>Item A</li>
    <li>Item B</li>
</ol>

<ol type="i">
    <li>Item i</li>
    <li>Item ii</li>
</ol>

Output:

  1. Item A
  2. Item B
  1. Item i
  2. Item ii
Type Value Description Example
type="1" Numbers (default) 1, 2, 3...
type="A" Uppercase letters A, B, C...
type="a" Lowercase letters a, b, c...
type="I" Uppercase Roman numerals I, II, III...
type="i" Lowercase Roman numerals i, ii, iii...

Starting Number

Use the start attribute to begin counting from a specific number:

HTML Code:

<ol start="5">
    <li>Fifth item</li>
    <li>Sixth item</li>
    <li>Seventh item</li>
</ol>

Output:

  1. Fifth item
  2. Sixth item
  3. Seventh item

Nested Lists

Lists can be nested inside other lists to create sublists:

HTML Code:

<ul>
    <li>Fruits
        <ul>
            <li>Apple</li>
            <li>Orange</li>
        </ul>
    </li>
    <li>Vegetables
        <ul>
            <li>Carrot</li>
            <li>Broccoli</li>
        </ul>
    </li>
</ul>

Output:

  • Fruits
    • Apple
    • Orange
  • Vegetables
    • Carrot
    • Broccoli

Description Lists (<dl>)

Description lists are used to display terms and their descriptions:

HTML Code:

<dl>
    <dt>HTML</dt>
    <dd>HyperText Markup Language</dd>
    <dt>CSS</dt>
    <dd>Cascading Style Sheets</dd>
</dl>

Output:

HTML
HyperText Markup Language
CSS
Cascading Style Sheets
Description List Tags:

Practical Example: Recipe

HTML Code:

<h3>Pancake Recipe</h3>
<h4>Ingredients:</h4>
<ul>
    <li>2 cups flour</li>
    <li>2 eggs</li>
    <li>1 cup milk</li>
</ul>
<h4>Instructions:</h4>
<ol>
    <li>Mix ingredients</li>
    <li>Heat pan</li>
    <li>Cook pancakes</li>
</ol>

Output:

Pancake Recipe

Ingredients:

  • 2 cups flour
  • 2 eggs
  • 1 cup milk

Instructions:

  1. Mix ingredients
  2. Heat pan
  3. Cook pancakes
💡 Best Practices:

Styling Lists with CSS

You can customize list appearance using CSS:

<ul style="list-style-type: square;">
    <li>Square bullets</li>
</ul>

<ul style="list-style-type: none;">
    <li>No bullets</li>
</ul>

Practice Exercise

Try This:

Create a page about your school with: