HTML Lists
Learn how to create ordered, unordered, and description lists in HTML
Introduction to HTML Lists
HTML provides three main types of lists used to organize and present content clearly:
- Ordered lists (
<ol>) - lists with numbers - Unordered lists (
<ul>) - lists with bullets - Description lists (
<dl>) - lists with terms and descriptions
1. Ordered Lists
Ordered lists are used when the order of items matters. Each item is numbered automatically.
Syntex:
<!-- Ordered List -->
<ol>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ol>
Output
- First item
- Second item
- Third item
Each list item is defined using the <li> tag.
Customize Numbering:
You can customize the numbering style using the type attribute:
<ol type="A">
<li>Item A</li>
<li>Item B</li>
<li>Item C</li>
</ol>
Output
- Item A
- Item B
- Item C
| Type values | Output Styles |
|---|---|
| 1 (default) | 1, 2, 3 |
| A | A, B, C |
| a | a, b, c |
| I | |, ||, ||| |
| i | i, ii, iii |
Use start to change the starting number:
<ol start="5">
<li>Fifth item</li>
<li>Sixth item</li>
<li>Seventh item</li>
</ol>
Output
- Fifth item
- Sixth item
- Seventh item
2. Unordered Lists
Unordered lists are used when the order of items does not matter. Each item is marked with a bullet point.
Syntax:
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
Output
- HTML
- CSS
- JavaScript
Customize Bullet Style:
You can customize the bullet style using the type attribute:
<ul list-style-type="circle;">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
Output
- item 1
- item 2
- item 3
You can also use type to change the bullet style:
| list-style-type | bullet Styles |
|---|---|
| disc (default) | ● |
| circle | ○ |
| square | ■ |
| none | no bullet |
3. Description Lists
Description lists are used to define terms and their descriptions. They are useful for glossaries or definitions.
Syntax:
<dl>
<dt>HTML</dt>
<dd>HyperText Markup Language</dd>
<dt>CSS</dt>
<dd>Cascading Style Sheets</dd>
<dt>JavaScript</dt>
<dd>Programming language for web development</dd>
</dl>
Output
- HTML
- HyperText Markup Language
- CSS
- Cascading Style Sheets
- JavaScript
- Programming language for web development
Each term is defined using the <dt> tag and its description using the <dd> tag.
Summary
HTML lists are essential for organizing content effectively. Use ordered lists for sequences, unordered lists for bullet points, and description lists for terms and definitions. Understanding how to use these lists will help you create well-structured and readable web pages.