1. Styling Unordered Lists¶
Unordered lists (<ul>) typically come with bullet points by default. To make them cleaner, Bootstrap5 provides utility classes for customization.
1.1 Removing Default Bullet Points¶
By default, unordered lists display black dots. Use the .list-unstyled class to remove these bullets and create a cleaner look.
<!-- Default unordered list (with bullets) -->
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
<!-- Unordered list without bullets using .list-unstyled -->
<ul class="list-unstyled">
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
Effect: The first list has bullets; the second does not.
1.2 Horizontal Lists¶
To display lists horizontally (e.g., navigation menus, tags), combine .list-inline and .list-inline-item.
<ul class="list-unstyled list-inline">
<li class="list-inline-item">Home</li>
<li class="list-inline-item">Products</li>
<li class="list-inline-item">About Us</li>
</ul>
Effect: List items are aligned horizontally without bullets, ideal for tags or navigation.
1.3 Adjusting List Item Spacing¶
If default spacing between list items is too large or small, use Bootstrap’s margin classes (e.g., .mb-2) to control spacing.
<ul class="list-unstyled">
<li class="mb-2">HTML</li>
<li class="mb-2">CSS</li>
<li>JavaScript</li>
</ul>
Effect: The first two list items have increased bottom margin (.mb-2), making the list more compact.
2. Styling Ordered Lists¶
Ordered lists (<ol>) default to numbering. To remove numbers or enhance the list, use the following methods.
2.1 Removing Default Numbering¶
The .list-unstyled class also works for ordered lists to remove number prefixes, simplifying the list.
<!-- Default ordered list (with numbers) -->
<ol>
<li>Step 1</li>
<li>Step 2</li>
<li>Step 3</li>
</ol>
<!-- Ordered list without numbers using .list-unstyled -->
<ol class="list-unstyled">
<li>Step 1</li>
<li>Step 2</li>
<li>Step 3</li>
</ol>
2.2 Styling Ordered Lists with List Groups¶
For more polished ordered lists (e.g., with borders, hover effects), use Bootstrap5’s list groups (list-group), which support numbering, hover states, etc.
<div class="list-group">
<a href="#" class="list-group-item list-group-item-action">
Step 1: Learn HTML
</a>
<a href="#" class="list-group-item list-group-item-action">
Step 2: Learn CSS
</a>
<a href="#" class="list-group-item list-group-item-action">
Step 3: Learn JavaScript
</a>
</div>
Effect: Each item has a border; hover changes the background color, and they are clickable (via <a> tags).
3. Detailed Explanation of List Groups¶
List groups are Bootstrap5’s most powerful list tool, ideal for scenarios requiring aesthetics, grouping, or interactivity (e.g., navigation menus, to-do lists).
3.1 Basic List Group¶
Use .list-group as the container and list-group-item for items:
<div class="list-group">
<li class="list-group-item">Home</li>
<li class="list-group-item">Product List</li>
<li class="list-group-item">User Center</li>
</div>
Effect: Each item has a gray border, creating a clean, organized look.
3.2 Controlling List Item States¶
List groups support state classes to highlight items:
- Active State: Use
.activeto highlight the currently selected item (background color changes). - Disabled State: Use
.disabledto mark inactive items (text grays out and clicks are disabled).
<div class="list-group">
<li class="list-group-item active">Home (Current Page)</li>
<li class="list-group-item">Product List</li>
<li class="list-group-item disabled">User Center (Disabled)</li>
</div>
3.3 Styling List Items¶
Leverage Bootstrap’s contextual classes to customize colors and backgrounds:
- Text Color:
.text-primary(blue),.text-success(green), etc. - Background Color:
.bg-primary(blue background),.bg-light(light gray background), etc.
<div class="list-group">
<li class="list-group-item bg-primary text-white">
Blue Background + White Text
</li>
<li class="list-group-item text-success">
Green Text
</li>
<li class="list-group-item small">
Small Text Size
</li>
</div>
3.4 Adjusting List Group Size¶
Control the overall size with .list-group-sm (small) or .list-group-lg (large):
<!-- Small list group -->
<div class="list-group list-group-sm">
<li class="list-group-item">Small Item 1</li>
<li class="list-group-item">Small Item 2</li>
</div>
<!-- Large list group -->
<div class="list-group list-group-lg">
<li class="list-group-item">Large Item 1</li>
<li class="list-group-item">Large Item 2</li>
</div>
4. Practical Tips Summary¶
- Simple Lists: Use
.list-unstyledto remove bullets for plain text lists. - Horizontal Lists: Combine
.list-inline+.list-inline-itemfor tags, navigation, etc. - Interactive Lists: Use
list-groupfor bordered, hoverable lists with clickable items or state markers. - Colors & Spacing: Combine contextual classes (
.text-*,.bg-*) and margin classes (.mb-*) for quick styling.
With these methods, beginners can quickly master Bootstrap5 list styling. Choose the appropriate list type based on your needs.