Loading...

HTML essentialsContent

Lists (ordered, unordered, description)

4 min lesson

Next
  • A list groups related items so readers can scan them quickly.
  • HTML has three list types: <ul> for unordered (bullets), <ol> for ordered (numbers) and <dl> for description lists (term and definition).
  • Think of a shopping list: the order does not matter, so it is unordered; a recipe's steps do matter, so they are ordered.
  • Each item in ul or ol goes in an <li> tag; in a dl, each pair uses <dt> for the term and <dd> for the definition.
  • This builds on Quotes, code & preformatted text and the earlier Content lessons: lists are another block-level structure.
  • The example shows one list of each type; you will see bullets, numbers and a term with its meaning.
  • Next, Links & images adds navigation and pictures to your content.
Keep in mind
  • Use ul when order does not matter and ol when it does.
  • Every item in ul and ol must be wrapped in li.
  • Use dl for pairs like word and meaning, not for simple bullet lists.
  • Do not type dashes or numbers manually; the browser adds them.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Lists</title>
</head>
<body>
  <!-- Unordered list: order does not matter -->
  <h2>Groceries</h2>
  <ul>
    <li>Milk</li>
    <li>Bread</li>
    <li>Eggs</li>
  </ul>
  <!-- Ordered list: order matters -->
  <h2>Steps</h2>
  <ol>
    <li>Boil water</li>
    <li>Add tea</li>
    <li>Wait three minutes</li>
  </ol>
  <!-- Description list: term and definition -->
  <h2>Terms</h2>
  <dl>
    <dt>HTML</dt>
    <dd>The language that structures a web page.</dd>
  </dl>
</body>
</html>

What happens: A page with the heading "Groceries" and a bulleted list of Milk, Bread, Eggs; the heading "Steps" and a numbered list 1. Boil water, 2. Add tea, 3. Wait three minutes; and the heading "Terms" with "HTML" followed by its definition "The language that structures a web page."

Breaking it down

ul

<ul>...</ul>

Starts an unordered list. Browsers show each item with a bullet, and order carries no meaning.

ol

<ol>...</ol>

Starts an ordered list. Browsers number the items automatically, so steps read in sequence.

li

<li>Milk</li>

One item in a ul or ol. Everything else must be inside an li, or the list is malformed.

dl, dt, dd

<dl><dt>HTML</dt><dd>...</dd></dl>

A description list. dt holds the term, dd holds the definition. Use it for glossaries and FAQs.

List types

TagMeaningMarker
ulUnordered listBullets
olOrdered listNumbers
dlDescription listTerm and definition
liList itemInside ul or ol
dt / ddTerm and definitionInside dl

A helpful analogy

An unordered list is a bag of items where order does not matter, like groceries in a basket. An ordered list is a queue at a ticket counter, where being first is different from being third.

Nesting rules

  • 1.Put li directly inside ul or ol, never loose text or other blocks.
  • 2.Nest a new ul or ol inside an li to create a sub-list.

Common mistakes

Typing numbers or dashes by hand

Avoid

1. Boil water<br>2. Add tea

Use instead

<ol><li>Boil water</li><li>Add tea</li></ol>

The browser adds numbers and bullets for real lists. Typing them manually breaks the structure and screen readers skip them.

Using dl for a simple bullet list

Avoid

<dl><dt>Milk</dt></dl>

Use instead

<ul><li>Milk</li></ul>

A description list needs pairs. For single items with no definition, ul is the correct tag.

Quick tips

  • •Nest a sub-list inside an li to show steps within steps.
  • •Do not use lists for layout; use div and CSS instead.
Previous
Next