Lesson 17 of 60 – Bootstrap Badges
28%

Bootstrap Badges

Bootstrap badges are small labels used to display additional information such as status, counts, categories, notifications, or short messages. Badges are commonly used with buttons, headings, navigation menus, cards, and tables.

Note: Bootstrap badges are created using the .badge class together with a contextual background class such as .text-bg-primary.

1. What Are Bootstrap Badges?

A badge is a small visual label that provides additional information about an element.

Example:

<span class="badge text-bg-primary">
New
</span>
New

Badges are useful when you want to show a short piece of information without taking much space.

2. The .badge Class

The .badge class provides the basic styling for a Bootstrap badge.

<span class="badge text-bg-success">
Success
</span>
Success

The .badge class is normally combined with a contextual background utility.

3. Primary Badge

Use text-bg-primary to create a primary-colored badge.

<span class="badge text-bg-primary">
Primary
</span>
Primary

Primary badges can be used for general information or highlighted categories.

4. Success Badge

The text-bg-success class creates a success-style badge.

<span class="badge text-bg-success">
Completed
</span>
Completed

It can be used for statuses such as Completed, Active, Approved, or Paid.

5. Danger Badge

The text-bg-danger class creates a danger-style badge.

<span class="badge text-bg-danger">
Failed
</span>
Failed

Danger badges can be used for errors, failed operations, or important warning statuses.

6. Warning Badge

The text-bg-warning class creates a warning badge.

<span class="badge text-bg-warning">
Pending
</span>
Pending

Warning badges are useful for statuses that require attention.

7. Info Badge

The text-bg-info class creates an informational badge.

<span class="badge text-bg-info">
Information
</span>
Information

It can be used to identify additional information or categories.

8. Light Badge

The text-bg-light class creates a light-colored badge.

<span class="badge text-bg-light border">
Light
</span>
Light

A border can help distinguish a light badge from a light background.

9. Dark Badge

The text-bg-dark class creates a dark badge.

<span class="badge text-bg-dark">
Dark
</span>
Dark

10. Different Badge Colors

Bootstrap provides several contextual background combinations for badges.

<span class="badge text-bg-primary">Primary</span>
<span class="badge text-bg-secondary">Secondary</span>
<span class="badge text-bg-success">Success</span>
<span class="badge text-bg-danger">Danger</span>
<span class="badge text-bg-warning">Warning</span>
<span class="badge text-bg-info">Info</span>
<span class="badge text-bg-dark">Dark</span>
Primary Secondary Success Danger Warning Info Dark

11. Badges with Headings

Badges can be placed inside headings to display additional information.

<h3>
Students
<span class="badge text-bg-primary">
25
</span>
</h3>

Students 25

This is useful for showing counts next to headings.

12. Badge with a Button

Badges can be placed inside buttons to show counts or notifications.

<button class="btn btn-primary">

    Messages

    <span class="badge text-bg-light">
    5
    </span>

</button>

13. Notification Badge

Badges are commonly used to show notification counts.

<button class="btn btn-dark">
Notifications
<span class="badge text-bg-danger">
8
</span>
</button>

This pattern is commonly used in dashboards and navigation bars.

14. Badge in a Card

A badge can be used inside a Bootstrap card to show status.

<div class="card">

    <div class="card-body">

        <h5>Course Details</h5>

        <span class="badge text-bg-success">
        Active
        </span>

    </div>

</div>
Course Details
Active

15. Badge in a Table

Badges are very useful for displaying status values inside tables.

<td>
<span class="badge text-bg-success">
Active
</span>
</td>
Name Status
Rahul Active
Amit Pending
Ravi Inactive

16. Badge with List Groups

Badges can be placed inside list group items.

<ul class="list-group">

<li class="list-group-item d-flex justify-content-between">

    Students

    <span class="badge text-bg-primary">
    50
    </span>

</li>

</ul>
  • Students 50
  • Courses 8

17. Pill Badges

The .rounded-pill utility can be combined with a badge to create a pill-shaped appearance.

<span class="badge text-bg-primary rounded-pill">
New
</span>
New

Pill badges are useful for short labels and status indicators.

18. Pill Badge with Count

Pill-shaped badges work especially well for notification counts.

<span class="badge text-bg-danger rounded-pill">
99+
</span>
99+

19. Badge with Links

Badges can also be placed inside links.

<a href="#" class="text-decoration-none">

Products

<span class="badge text-bg-primary">
12
</span>

</a>
Products 12

20. Badge with Spacing Utilities

Bootstrap spacing utilities can be used to add space around badges.

<span class="badge text-bg-primary me-2">
HTML
</span>

<span class="badge text-bg-success">
CSS
</span>
HTML CSS

The me-2 class adds margin on the end side of the first badge.

21. Badge for Course Categories

Badges can identify categories in an education website.

<span class="badge text-bg-primary">
HTML
</span>

<span class="badge text-bg-success">
CSS
</span>

<span class="badge text-bg-warning">
JavaScript
</span>

<span class="badge text-bg-danger">
Python
</span>
HTML CSS JavaScript Python

22. Badge for Student Status

Badges can display student status in an education management system.

Student 1: Active
Student 2: Pending
Student 3: Inactive
<span class="badge text-bg-success">
Active
</span>

<span class="badge text-bg-warning">
Pending
</span>

<span class="badge text-bg-danger">
Inactive
</span>

23. Badge for Payment Status

Badges are useful for showing payment status.

Student Payment
Rahul Paid
Amit Pending
Ravi Due

This makes status information easy to scan.

24. Badge for New Content

A badge can highlight newly added content.

<h4>
Bootstrap Tutorial

<span class="badge text-bg-success">
New
</span>

</h4>

Bootstrap Tutorial New

This pattern is useful for courses, lessons, products, and blog posts.

25. Badge with Headings of Different Sizes

Badges can be placed inside different heading elements.

Heading 2 5

Heading 4 10

Heading 6 2

The badge automatically fits naturally with its surrounding text.

26. Badge Accessibility

Badges should provide useful information rather than relying only on color.

  • Use meaningful text inside badges.
  • Do not communicate important information using color alone.
  • Use readable text and sufficient contrast.
  • Keep badge labels short and clear.
  • Use badges for supporting information.
Tip: Instead of showing only a red badge, use a label such as Due, Failed, or Inactive.

27. Common Badge Mistakes

Avoid using badges unnecessarily.

  • Do not use too many badges in one small area.
  • Do not use badges for long sentences.
  • Do not use color without meaningful text.
  • Do not make important actions look like simple labels.
  • Do not make badges unnecessarily large.

Badges work best when they provide short, useful information.

28. Badge Reference

Common Bootstrap badge combinations include:

<span class="badge text-bg-primary">Primary</span>

<span class="badge text-bg-success">Success</span>

<span class="badge text-bg-danger">Danger</span>

<span class="badge text-bg-warning">Warning</span>

<span class="badge text-bg-info">Info</span>

<span class="badge text-bg-dark">Dark</span>

<span class="badge text-bg-primary rounded-pill">
Pill
</span>

29. Practical Dashboard Example

Here is an example of badges used in a simple dashboard.

<div class="card">

    <div class="card-body">

        <h5>Student Dashboard</h5>

        <p>
        Account Status:
        <span class="badge text-bg-success">
        Active
        </span>
        </p>

        <p>
        Assignments:
        <span class="badge text-bg-primary">
        12
        </span>
        </p>

        <p>
        Pending Fees:
        <span class="badge text-bg-danger">
        Due
        </span>
        </p>

    </div>

</div>
Student Dashboard

Account Status: Active

Assignments: 12

Pending Fees: Due

30. Complete Bootstrap Badge Example

The following example combines headings, badges, counts, status labels, and pill badges.

<div class="container mt-4">

    <h3>
    Student Management

    <span class="badge text-bg-primary rounded-pill">
    25
    </span>

    </h3>

    <p>
    Active Students:
    <span class="badge text-bg-success">
    20
    </span>
    </p>

    <p>
    Pending Students:
    <span class="badge text-bg-warning">
    3
    </span>
    </p>

    <p>
    Inactive Students:
    <span class="badge text-bg-danger">
    2
    </span>
    </p>

</div>

Student Management 25

Active Students: 20

Pending Students: 3

Inactive Students: 2

📌 Key Points

  • Use .badge to create a Bootstrap badge.
  • Use text-bg-primary, text-bg-success, and other contextual classes for badge colors.
  • Badges are useful for statuses and short labels.
  • Badges can display notification counts.
  • Badges can be placed inside headings.
  • Badges can be placed inside buttons.
  • Badges can be used in tables and cards.
  • Use rounded-pill for pill-shaped badges.
  • Use meaningful text instead of relying only on color.
  • Keep badge content short and easy to understand.

🧠 Quick Quiz

Question: Which Bootstrap class is used as the basic class for creating a badge?