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-relative on the button and position-absolute top-0 start-100 translate-middle on 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-100 puts the badge on the corner, and translate-middle moves it half of its size back, so it sits on the corner.
  • The hidden text tells screen reader users what “5” means.

Read Badges and Utilities.


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
Exercises & Assignments
Create a card with an image, a title, a text and a button
Create an alert which the user can close
Create a progress bar at 60 percent
Create a pricing section with three cards
Create a button group
Add a notification count badge to a button
Create a hero section with a heading and two buttons
Interview Questions & Answers
How do you create buttons in Bootstrap?
How do you make a full width button in Bootstrap 5?
What are Bootstrap alerts and how do you close them?
What is a card in Bootstrap?
How do you use Bootstrap Icons?
How do you make cards of equal height in Bootstrap?