List groups help organize items in a neat list. Badges show extra info like counts or status next to each item.
List group with badges in Bootsrap
<ul class="list-group"> <li class="list-group-item d-flex justify-content-between align-items-center"> Item name <span class="badge bg-primary rounded-pill">Badge content</span> </li> </ul>
Use list-group-item for each list item.
Use d-flex justify-content-between align-items-center to place badge on the right side aligned vertically.
<ul class="list-group"> <li class="list-group-item d-flex justify-content-between align-items-center"> Messages <span class="badge bg-primary rounded-pill">14</span> </li> </ul>
<ul class="list-group"> <li class="list-group-item d-flex justify-content-between align-items-center"> Notifications <span class="badge bg-danger rounded-pill">3</span> </li> <li class="list-group-item d-flex justify-content-between align-items-center"> Updates <span class="badge bg-success rounded-pill">7</span> </li> </ul>
<ul class="list-group"> <li class="list-group-item d-flex justify-content-between align-items-center"> Empty badge <span class="badge bg-secondary rounded-pill">0</span> </li> </ul>
This example shows a list of email folders with badges indicating the number of messages in each. Different badge colors help show importance or status.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>List Group with Badges 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 py-4"> <h1 class="mb-4">Tasks List</h1> <ul class="list-group"> <li class="list-group-item d-flex justify-content-between align-items-center"> Inbox <span class="badge bg-primary rounded-pill">5</span> </li> <li class="list-group-item d-flex justify-content-between align-items-center"> Sent <span class="badge bg-secondary rounded-pill">2</span> </li> <li class="list-group-item d-flex justify-content-between align-items-center"> Drafts <span class="badge bg-warning text-dark rounded-pill">1</span> </li> <li class="list-group-item d-flex justify-content-between align-items-center"> Spam <span class="badge bg-danger rounded-pill">0</span> </li> </ul> </main> </body> </html>
Badges use bg-* classes for colors and rounded-pill for pill shape.
Use flex utilities d-flex justify-content-between align-items-center to align text left and badge right.
Badges should have good color contrast for accessibility.
List groups organize items vertically.
Badges show extra info like counts or status next to items.
Use Bootstrap flex classes to align badges nicely on the right.
Practice
list group with badges in Bootstrap?Solution
Step 1: Understand list groups
List groups in Bootstrap organize items vertically for easy reading.Step 2: Role of badges
Badges add extra info like counts or statuses aligned to the right of list items.Final Answer:
To display a vertical list of items with extra info like counts on the right -> Option DQuick Check:
List groups + badges = vertical list with extra info [OK]
- Confusing badges with navigation tabs
- Thinking list groups are for images
- Using badges for background colors
Solution
Step 1: Identify flex classes for alignment
Usingd-flex justify-content-between align-items-centermakes the list item a flex container that spaces content horizontally and centers vertically.Step 2: Confirm badge alignment
This combination pushes the badge to the right side automatically.Final Answer:
list-group-item d-flex justify-content-between align-items-center -> Option CQuick Check:
Flex + justify-content-between aligns badge right [OK]
- Using float classes which Bootstrap 5 discourages
- Using text-center which centers content
- Using non-existent badge-end class
<ul class="list-group">
<li class="list-group-item d-flex justify-content-between align-items-center">
Messages
<span class="badge bg-primary rounded-pill">14</span>
</li>
</ul>Solution
Step 1: Analyze list group and flex classes
Thelist-group-itemwith flex classes arranges content horizontally with space between.Step 2: Badge styling and placement
The badge usesbg-primaryfor blue background androunded-pillfor pill shape, placed on the right side.Final Answer:
A vertical list with 'Messages' on left and a blue pill-shaped badge with '14' on right -> Option AQuick Check:
Flex list group with badge = text left, badge right [OK]
- Thinking badge appears below text
- Confusing vertical and horizontal list layout
- Assuming badge class causes error
<ul class="list-group">
<li class="list-group-item">
Notifications
<span class="badge badge-primary">5</span>
</li>
</ul>Solution
Step 1: Check badge color class
Bootstrap 5 usesbg-primaryfor badge background color, notbadge-primary.Step 2: Confirm badge alignment
While flex classes help alignment, the main error is the wrong badge color class.Final Answer:
Incorrect badge color class; should be bg-primary -> Option AQuick Check:
Use bg-primary for badge color in Bootstrap 5 [OK]
- Using old Bootstrap 4 badge classes
- Forgetting flex classes but that is not an error
- Placing badge outside list item
Solution
Step 1: Identify correct badge background classes
Bootstrap 5 usesbg-dangerfor red,bg-warningfor yellow, andbg-successfor green backgrounds.Step 2: Confirm badge class usage
Badges requirebg-*classes, notbadge-*ortext-*for background colors.Final Answer:
bg-danger for High, bg-warning for Medium, bg-success for Low -> Option BQuick Check:
Use bg-danger/warning/success for badge colors [OK]
- Using old badge-danger classes
- Using text color classes instead of background
- Mixing unrelated color classes
Ready to prove it?
Pass the test and this pattern moves unknown
