Class 25 of 48 • Core Components

Bootstrap 5 Badges: Pill Badges, Counters & Notification Indicators

Badges are small, lightweight visual indicators used to label items, highlight statuses (e.g. "New", "Verified", "Beta"), or display numerical counters (such as unread emails or shopping cart counts). In Bootstrap 5, badges scale proportionally to match the font size of their immediate parent element.

Bootstrap 5 Badges, Pill Counters, and Absolute Positioning Indicators
Figure 25: Contextual badge variants, rounded-pill tags, and absolute top-right notification counter badges.

1. Contextual Badges & Pill Badges

Apply .badge paired with a background color class. Use .rounded-pill for stadium-shaped rounded pills:

<!-- Standard Badges -->
<span class="badge bg-primary">Primary</span>
<span class="badge bg-success">Verified</span>
<span class="badge bg-danger">Expired</span>
<span class="badge bg-warning text-dark">Pending</span>

<!-- Rounded Pill Badges -->
<span class="badge rounded-pill bg-info text-dark">Pill Info</span>
<span class="badge rounded-pill bg-dark">Class 25 of 48</span>

2. Badges inside Headings & Buttons

Badges inherit font sizes using em units, scaling automatically inside headings:

<h2>Bootstrap Masterclass <span class="badge bg-secondary">New</span></h2>

<!-- Notification Counter on Button -->
<button type="button" class="btn btn-primary">
  Notifications <span class="badge text-bg-light">4</span>
</button>

3. Absolute Positioned Notification Badges

Create modern smartphone-style notification dots positioned at the top-right corner of an action button:

<button type="button" class="btn btn-primary position-relative">
  <i class="fa fa-envelope"></i> Inbox
  <span class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger">
    99+
    <span class="visually-hidden">unread messages</span>
  </span>
</button>

Explore Related Bootstrap Tutorials & Next Steps

Strengthen your responsive web design mastery by studying these connected classes:

Buttons with Notification Badges

Embed pill badges inside buttons to show unread message counts.

List Groups with Badges

Display item counts next to list items using flexbox auto margins.

Contextual Alerts

Use matching colors between alert boxes and highlighted badges.

Badges in Headings

Scale badges automatically to match the font size of parent headings.

Frequently Asked Questions (FAQ) - Student & Interview Review

Screen readers need clear verbal descriptions. A sighted user sees the red badge with '99+', but screen readers will announce 'unread messages' to visually impaired visitors.
Add .p-2 and .border.border-light to an empty <span class='position-absolute top-0 start-100 translate-middle p-2 bg-danger border border-light rounded-circle'></span>.
Yes! Apply the badge classes to an anchor tag: <a href='#' class='badge bg-primary text-decoration-none'>React</a>.

Next Step in Your Bootstrap Learning Path:

Advance your practical frontend engineering skills with the next topic in our synchronized curriculum.

Continue to Class 26: Progress Bars → Previous: ← Class 24: Alerts & Notifications | Full Syllabus

Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Reddit

You may also like this!