In this tutorial I’ll show you how to create HTML lists in your Web page. We’ll look at unordered (bullet) lists, ordered (numbered) lists, and definition lists.
Types of HTML lists
There are 3 basic types of lists that you can produce using HTML. They are:
Unordered lists
Unordered lists are also known as bullet lists or bulleted lists. For example:
- Apples are green
- Bananas are yellow
- Oranges are orange
Ordered lists
These are also known as numbered lists. For example:
- Light the blue touch paper.
- Stand well back.
- Enjoy the fireworks!
Definition lists
Good for making lists where each item needs a summary followed by a more detailed description. For example:
- Paris, France
- The capital city of France. Famous attractions include the Eiffel Tower and the Notre Dame Cathedral.
- Sydney, Australia
- The state capital of New South Wales, Australia. Famous attractions include the Sydney Opera House and Harbour Bridge.
- London, England
- The capital city of England. Famous attractions include Tower Bridge and Big Ben.
Let’s explore how to create each of these types of HTML lists.
Creating unordered lists
To create an unordered, or bullet, list you use <ul></ul>
tags for the list, and <li></li>
tags for the list items.
So, to create the unordered list example above, you’d use:
<ul>
<li>Apples are green</li>
<li>Bananas are yellow</li>
<li>Oranges are orange</li>
</ul>
Creating ordered lists
The method to create ordered (numbered) lists is almost exactly the same as for unordered lists. The only difference is that you use <ol></ol>
tags in place of the <ul></ul>
tags.
To recreate the ordered list above:
<ol>
<li>Light the blue touch paper.</li>
<li>Stand well back.</li>
<li>Enjoy the fireworks!</li>
</ol>
Creating definition lists
Creating a definition list is a little more complicated than the last 2 types, but it’s still pretty easy!
The definition list itself is created with the <dl></dl>
tags. Each item in the list consists of a term, created using the <dt></dt>
tags, and the indented definition, which uses the <dd></dd>
tags.
So, the cities example above is created as follows:
<dl>
<dt><strong>Paris, France</strong></dt>
<dd>The capital city of France. Famous attractions
include the Eiffel Tower and the Notre Dame Cathedral.</dd>
<dt><strong>Sydney, Australia</strong></dt>
<dd>The state capital of New South Wales, Australia. Famous
attractions include the Sydney Opera House and
Harbour Bridge.</dd>
<dt><strong>London, England</strong></dt>
<dd>The capital city of England. Famous attractions
include Tower Bridge and Big Ben.</dd>
</dl>
Mixing and matching HTML lists
It’s possible to nest lists in HTML. For example, here is a 2-level ordered list:
- Chapter 1
-
- Section 1.1
- Section 1.2
-
- Chapter 2
-
- Section 2.1
- Section 2.2
- Section 2.3
-
…and here’s the code for it:
<ol>
<li>Chapter 1
<ol>
<li>Section 1.1</li>
<li>Section 1.2</li>
</ol>
</li>
<li>Chapter 2
<ol>
<li>Section 2.1</li>
<li>Section 2.2</li>
<li>Section 2.3</li>
</ol>
</li>
</ol>
It’s even possible to nest different types of lists together! In this example, the unordered and ordered lists above are nested inside a definition list:
- Types of Fruit
-
-
- Apples are green
- Bananas are yellow
- Oranges are orange
-
- Firework Instructions
-
-
- Light the blue touch paper.
- Stand well back.
- Enjoy the fireworks!
-
…and here’s the code:
<dl>
<dt><strong>Types of Fruit</strong></dt>
<dd>
<ul>
<li>Apples are green</li>
<li>Bananas are yellow</li>
<li>Oranges are orange</li>
</ul>
</dd>
<dt><strong>Firework Instructions</strong></dt>
<dd>
<ol>
<li>Light the blue touch paper.</li>
<li>Stand well back.</li>
<li>Enjoy the fireworks!</li>
</ol>
</dd>
</dl>
That’s about all there is to know about HTML lists. You’ve looked at creating bullet lists, numbered lists, and definition lists.
Why not have a go at creating a few HTML lists yourself! They’re easy to make.
Leave a Reply