Add a notification count badge to a button
Description: Add a red round badge with the number 5 on the top right corner of an “Inbox” button.
Hint:
- Use
position-relativeon the button andposition-absolute top-0 start-100 translate-middleon the badge.
Solution
<button type="button" class="btn btn-primary position-relative">
Inbox
<span class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger">
5
<span class="visually-hidden">unread messages</span>
</span>
</button>
Live preview
How it works
top-0 start-100puts the badge on the corner, andtranslate-middlemoves it half of its size back, so it sits on the corner.- The hidden text tells screen reader users what “5” means.
Learn more about the similar topics:
| Tutorials |
|---|
| Bootstrap Buttons |
| Bootstrap Alerts |
| Bootstrap Badges |
| Bootstrap Cards |
| Bootstrap List Group |
| Bootstrap Progress Bars and Spinners |
| Bootstrap Icons |