Lists (Ordered, Unordered, Description)
Unordered Lists (<ul>)
Unordered lists use bullet points to represent list items.
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
CSS Styling:
list-style-type: Controls the bullet style (e.g.,disc,circle,square,none).list-style-image: Uses an image as the bullet point.list-style-position: Controls whether the bullet point is inside or outside the list item content (inside,outside).- Padding and margin can be used to adjust spacing.
ul {
list-style-type: circle;
padding-left: 20px; /* Add some space for the bullets */
}
ul li {
margin-bottom: 5px; /* Add space between list items */
}
Ordered Lists (<ol>)
Ordered lists use numbers or letters to represent list items.
<ol>
<li>First Item</li>
<li>Second Item</li>
<li>Third Item</li>
</ol>
CSS Styling:
list-style-type: Controls the numbering style (e.g.,decimal,lower-roman,upper-roman,lower-alpha,upper-alpha).list-style-position: Controls whether the number is inside or outside the list item content (inside,outside).- Padding and margin can be used to adjust spacing.
ol {
list-style-type: upper-roman;
padding-left: 20px;
}
ol li {
margin-bottom: 5px;
}
Description Lists (<dl>)
Description lists consist of terms (<dt>) and their corresponding descriptions (<dd>).
<dl>
<dt>HTML</dt>
<dd>The standard markup language for creating web pages.</dd>
<dt>CSS</dt>
<dd>Used to style the appearance of web pages.</dd>
<dt>JavaScript</dt>
<dd>A programming language used to add interactivity to web pages.</dd>
</dl>
CSS Styling:
margin: Adjusts the spacing around the entire description list.padding: Adjusts the spacing within the description list.- Styling
<dt>and<dd>individually allows for custom formatting of terms and descriptions. Often<dt>is bolded.
dl {
margin-bottom: 20px;
}
dt {
font-weight: bold;
margin-bottom: 5px;
}
dd {
margin-left: 20px;
margin-bottom: 10px;
}
Nesting Lists
Lists can be nested within each other to create hierarchical structures.
<ul>
<li>Item 1</li>
<li>Item 2
<ul>
<li>Sub-item 1</li>
<li>Sub-item 2</li>
</ul>
</li>
<li>Item 3</li>
</ol>
Nesting can be done with <ul>, <ol>, and even <dl> elements. CSS styling will cascade down, but can be overridden for specific nested lists.