← Back to Bootstrap Course | Chapter 7: Components — Cards & Alerts | Lesson 6 of 7

Badges

Badges are small labels for counts, statuses or highlights.

In this page:

  1. Badges
Syntax
markup
<span class="badge text-bg-primary">Label</span>
<span class="badge rounded-pill text-bg-danger">Label</span>

Badges

Use .badge with .text-bg-{color} to create a small label; add .rounded-pill for pill shape. Badges scale with the parent heading or button font size, and can be positioned over other elements with position utilities.

Add visually hidden text for context.

Note: Add a .visually-hidden span so screen readers know what the number means.

Example: Badges

markup
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
<div class="container">
  <h4>Inbox <span class="badge text-bg-secondary">4</span></h4>
  <button class="btn btn-primary position-relative">Messages
    <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>
  <span class="badge text-bg-success ms-3">New</span>
</div>
</body>
</html>
Live Example
Related Topics
Common Mistakes
  1. Colour-only status badges
  2. Using badges as buttons without markup
  3. Missing context text
Chapter Summary
  • badge with text-bg-*
  • rounded-pill for pills
  • Scale with parent font size
  • Add hidden context text
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.