HTML Lists with Examples
HTML lists are used to display items in an organized way.
Examples:
- Menu items
- Steps
- Features
- Subjects
Types of HTML Lists
HTML has 3 types of lists:
- Unordered List (<ul>)
- Ordered List (<ol>)
- Description List (<dl>)
1. Unordered List (<ul>)
Used when order doesn't matter
Shows items with bullets
Syntax
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>Output
- HTML
- CSS
- JavaScript
<ul> Attributes
type (bullet style)
<ul type="disc">
<ul type="circle">
<ul type="square">Example:
<ul type="square">
<li>Apple</li>
<li>Mango</li>
</ul>2. Ordered List (<ol>)
Used when order matters
Shows items with numbers
Syntax
<ol>
<li>Open Browser</li>
<li>Write Code</li>
<li>Save File</li>
</ol>Output
- Open Browser
- Write Code
- Save File
ol> Attributes
1. Type (number style)
| Value | Output |
| 1 | 1, 2, 3 |
| A | A, B, C |
| a | a, b, c |
| I | I, II, III |
| i | i, ii, iii |
<ol type="A">
<li>HTML</li>
<li>CSS</li>
</ol>2. start (starting number)
<ol start="5">
<li>Item</li>
<li>Item</li>
</ol>3. reversed (reverse order)
<ol reversed>
<li>First</li>
<li>Second</li>
</ol>3. Description List (<dl>)
Used for terms and definitions
Syntax
<dl>
<dt>HTML</dt>
<dd>HyperText Markup Language</dd>
<dt>CSS</dt>
<dd>Cascading Style Sheets</dd>
</dl>Important Notes
- type attribute is mostly old-school (CSS preferred now)
- Attributes are written in opening tag
- Lists improve readability
