HTML <li> Tag โ List Item
๐ Introduction
The <li> tag represents a list item in HTML.
It is used inside:
<ul>(unordered lists)<ol>(ordered lists)
Each <li> represents one item in a list.
๐งฑ Syntax
<li>Item</li>
๐ก Example with <ul>
<!DOCTYPE html>
<html>
<head>
<title>LI Example</title>
</head>
<body>
<h2>My Skills</h2>
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
</body>
</html>
๐ก Example with <ol>
<ol>
<li>Open editor</li>
<li>Write code</li>
<li>Run program</li>
</ol>
๐ฅ๏ธ Output Explanation
- Each
<li>becomes one visible item - In
<ul>โ bullets appear - In
<ol>โ numbers appear - Order depends on list type
๐ฏ Important Rule
๐ <li> cannot be used alone
It must be inside a list:
โ Correct:
<ul>
<li>Item</li>
</ul>
โ Wrong:
<li>Item</li>
๐ฏ When to Use <li>
Use it for:
- Navigation menus
- Feature lists
- Steps in tutorials
- Any grouped items
Example:
<ul>
<li>Home</li>
<li>About</li>
<li>Contact</li>
</ul>
๐ง Important Concept
๐ Think of <li> as a single building block
<ul>/<ol>= container<li>= items inside it
๐จ Nested Lists
You can also nest lists:
<ul>
<li>
Frontend
<ul>
<li>HTML</li>
<li>CSS</li>
</ul>
</li>
</ul>
๐ซ Common Mistakes
- Using
<li>outside lists โ - Forgetting
<ul>or<ol>โ - Mixing structure incorrectly โ
๐งช Mini Exercise
Create a page with:
- A navigation menu using
<ul>and<li> - A step-by-step tutorial using
<ol>and<li> - A nested list (e.g., categories and sub-items)