A list group helps you show a list of items neatly. It makes lists look clean and easy to read on your webpage.
List group component in Bootsrap
<ul class="list-group"> <li class="list-group-item">Item 1</li> <li class="list-group-item">Item 2</li> <li class="list-group-item">Item 3</li> </ul>
Use <ul> or <div> with list-group class to start the list.
Each item uses list-group-item class for consistent styling.
<ul class="list-group"> <li class="list-group-item active" aria-current="true">Active item</li> <li class="list-group-item">Normal item</li> <li class="list-group-item">Another item</li> </ul>
<a> tags with list-group-item-action to make list items clickable.<div class="list-group"> <a href="#" class="list-group-item list-group-item-action">Clickable link 1</a> <a href="#" class="list-group-item list-group-item-action">Clickable link 2</a> </div>
<ul class="list-group"> <li class="list-group-item disabled" tabindex="-1" aria-disabled="true">Disabled item</li> <li class="list-group-item">Enabled item</li> </ul>
This page shows a simple task list using Bootstrap's list group. One item is active to highlight it, and one is disabled to show it is not available. The list uses semantic HTML and accessibility attributes.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Bootstrap List Group Example</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" /> </head> <body> <main class="container mt-4"> <h1>My Task List</h1> <ul class="list-group" aria-label="Task list"> <li class="list-group-item">Buy groceries</li> <li class="list-group-item active" aria-current="true">Walk the dog</li> <li class="list-group-item">Read a book</li> <li class="list-group-item disabled" tabindex="-1" aria-disabled="true">Call plumber</li> </ul> </main> </body> </html>
The active class highlights the current or selected item.
The disabled class makes an item look inactive and prevents interaction.
Use list-group-item-action on links or buttons inside the list group to make them interactive.
List groups organize items in a clean, styled list.
Use list-group-item for each item inside a list-group container.
You can highlight, disable, or make items clickable with special classes.
Practice
list-group component?Solution
Step 1: Understand the role of
Thelist-grouplist-groupcomponent is designed to group related items in a list format.Step 2: Compare with other components
Unlike navigation bars or grids,list-groupfocuses on listing items with consistent styling.Final Answer:
To organize and style a list of items cleanly -> Option AQuick Check:
List groups = styled item lists [OK]
- Confusing list group with navigation bar
- Thinking it creates buttons or grids
- Mixing it with image display components
Solution
Step 1: Identify the container class for list groups
Bootstrap requires the container to have the classlist-groupto apply styles.Step 2: Choose the correct HTML element
Commonly,<ul>or<div>withlist-groupis used; here<ul>with classlist-groupis correct.Final Answer:
<ul class="list-group"> -> Option CQuick Check:
Use <ul> with class list-group [OK]
- Using wrong class names like list-item or group-list
- Using <ol> without correct class
- Using elements without the list-group class
<ul class="list-group"> <li class="list-group-item active">Home</li> <li class="list-group-item">Profile</li> <li class="list-group-item disabled">Messages</li> </ul>
Solution
Step 1: Understand the class effects
activehighlights the item,disabledgreys out and disables interaction.Step 2: Apply classes to list items
'Home' is active (highlighted), 'Profile' normal, 'Messages' disabled (greyed and unclickable).Final Answer:
A list with 'Home' highlighted, 'Profile' normal, and 'Messages' greyed out and unclickable -> Option BQuick Check:
Active = highlight, Disabled = greyed out [OK]
- Thinking disabled items are clickable
- Assuming all items look the same
- Confusing active and disabled effects
<ul class="list-group"> <li class="list-group-item">Item 1</li> <li class="list-group-item active">Item 2</li> <li class="list-group-item disabled">Item 3</li> <li class="list-group-item" disabled>Item 4</li> </ul>
Solution
Step 1: Check usage of disabled
Bootstrap requiresdisabledas a class, not as an HTML attribute on<li>.Step 2: Identify the incorrect line
The last<li>usesdisabledas an attribute, which is invalid and won't style properly.Final Answer:
The last <li> uses an invalid disabled attribute instead of class -> Option AQuick Check:
Use class="disabled", not disabled attribute [OK]
- Using disabled as an attribute instead of class
- Thinking active class is invalid
- Missing list-group-item class on items
Solution
Step 1: Identify clickable list group items
Bootstrap uses<a>tags with classeslist-group-itemandlist-group-item-actionfor clickable items.Step 2: Check other options
<ul class="list-group"> <li class="list-group-item">Item 1</li> <li class="list-group-item">Item 2</li> </ul> uses non-clickable<li>, A misseslist-group-item-action, D usesliwithout proper container and classes.Final Answer:
Div with <a> tags having list-group-item and list-group-item-action classes -> Option DQuick Check:
Clickable list items = <a> + list-group-item-action [OK]
- Using <li> without action class for clickable items
- Missing list-group-item-action class
- Using buttons without proper classes
Ready to prove it?
Pass the test and this pattern moves unknown
