HTML Lists
Lists are used whenever information needs to be presented as a group of related items.
1. Unordered List
An unordered list displays items with bullets.
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
It produces:
โข HTML
โข CSS
โข JavaScript
<ul> means unordered list.2. List Item
Each item inside a list uses
<li>.<li>HTML</li>Think of it as:
<ul> โ List containerโ
<li> โ Individual item 3. Ordered List
An ordered list displays items in a sequence, usually using numbers.
<ol>
<li>Learn HTML</li>
<li>Learn CSS</li>
<li>Learn JavaScript</li>
</ol>
It produces:
1. Learn HTML
2. Learn CSS
3. Learn JavaScript
<ol> means ordered list.4. When to Use Which?
Use
<ul> when order doesn't matter:<ul>
<li>Apples</li>
<li>Bananas</li>
<li>Oranges</li>
</ul>
Use
<ol> when order or sequence matters:<ol>
<li>Create an account</li>
<li>Verify your email</li>
<li>Log in</li>
</ol>
5. Nested Lists
A list can contain another list.
<ul>
<li>
Frontend
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
</li>
<li>
Backend
<ul>
<li>Node.js</li>
<li>Express</li>
</ul>
</li>
</ul>
The structure becomes:
โข Frontend
โข HTML
โข CSS
โข
JavaScript
โข
Backend
โข Node.js
โข Express
6. Lists in Navigation
Lists are commonly used to structure navigation menus.
<nav>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
</nav>
CSS can later transform this into a horizontal navigation bar.
7. Lists in Real Websites
Lists are useful for many things:
โข Shopping items
โข Features
โข Navigation menus
โข Steps
โข Skills
โข Categories
โข Search results
โข Product specifications
For example:
<h2>My Skills</h2>
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
<li>React</li>
</ul>
8. Important Rule
<li> should normally be used as a child of a list such as <ul> or <ol>.Good:
<ul>
<li>HTML</li>
<li>CSS</li>
</ul>
Not appropriate:
<li>HTML</li>
<li>CSS</li>
๐ง Remember
<ul> โ Unordered list โ Bullets<ol> โ Ordered list โ Numbers/sequence<li> โ List item โ Individual item Key Takeaway
<ul>
โ
Unordered group
โ
<li> Item
<li> Item
<li> Item
and
<ol>
โ
Ordered group
โ
<li> Step 1
<li> Step 2
<li> Step 3
Lists are simple, but they are fundamental to creating well-structured HTML content.
Double Tap โค๏ธ For More