HTML Lists
π Introduction to HTML Lists
HTML lists are used to group related pieces of information in a structured format. They improve readability and organization of content on webpages.
>>"Lists arenβt just for shopping β they structure ideas, steps, and meaning on the web." π§
π’ Types of HTML Lists
- Ordered List β Uses numbers or letters
- Unordered List β Uses bullet points
- Description List β Defines terms and descriptions
1οΈβ£ Ordered List: <ol>
Ordered lists are used when the sequence matters, like steps in a recipe or rankings.
Ordered List Example
<ol>
<li>Wake up</li>
<li>Brush your teeth</li>
<li>Drink water</li>
</ol>Note
π‘ You can change the number format using the type attribute (e.g. type="A" for uppercase letters).
π Unordered List: <ul>
Unordered lists are used when the order doesn't matter, such as listing features or groceries.
Unordered List Example
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>π Description List: <dl>
A description list pairs terms with their definitions, ideal for glossaries or FAQs.
Description List Example
<dl>
<dt>HTML</dt>
<dd>A markup language for web documents.</dd>
<dt>CSS</dt>
<dd>Used to style HTML content.</dd>
</dl>π¨ Styling Lists with CSS
Lists can be styled using CSS for better visual appeal.
CSS List Styling
ul {
list-style-type: square;
padding-left: 20px;
}
ol {
list-style-type: upper-roman;
}
li {
color: #333;
margin-bottom: 6px;
}Note
ποΈ Use list-style-type to change bullets or numbering, and padding for spacing.
π Real-World Use Case: Features List
Product Features List
<h2>Key Features</h2>
<ul>
<li>Responsive design</li>
<li>Dark mode support</li>
<li>Cross-browser compatibility</li>
</ul>βοΈ Nested Lists
You can create lists inside list items to represent sub-items.
Nested List Example
<ul>
<li>Frontend
<ul>
<li>HTML</li>
<li>CSS</li>
</ul>
</li>
<li>Backend
<ul>
<li>Node.js</li>
<li>Python</li>
</ul>
</li>
</ul>π Learn More
>>"Organized content is easier to read, easier to understand, and easier to love." β€οΈ