Course Content
Bootstrap 5 Alerts
0/1
Bootstrap
About Lesson

Bootstrap 5 Badges:

Bootstrap 5 badges are versatile UI elements used to display small counts, labels, or other indicators. They are often used alongside buttons, lists, or headings to draw attention to specific information, such as notifications or status updates.

Default badges use the .badge class with contextual color classes to indicate different meanings.

Example:

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

Output:

Displays badges with different contextual background colors.

Badges are commonly used with buttons to display counts or notifications.

Example:

CSS
<button type="button" class="btn btn-primary">
  Notifications <span class="badge bg-secondary">4</span>
</button>
<button type="button" class="btn btn-success">
  Messages <span class="badge bg-light text-dark">12</span>
</button>

Output:

Buttons with badges indicating notification counts.

Badges can be styled as links using <a> tags for interactive functionality.

Example:

CSS
<a href="#" class="badge bg-info">Clickable Badge</a>
<a href="#" class="badge bg-warning">Another Link</a>

Output:

Clickable badges styled as links.

Use badges with headings to highlight statuses or counts.

Example:

CSS
<h1>Heading 1 <span class="badge bg-success">New</span></h1>
<h2>Heading 2 <span class="badge bg-warning">Updated</span></h2>

Output:

Badges appended to headings for additional context.

Add .rounded-pill to create rounded badges, also called pill badges.

Example:

CSS
<span class="badge bg-primary rounded-pill">Primary</span>
<span class="badge bg-danger rounded-pill">Danger</span>
<span class="badge bg-success rounded-pill">Success</span>

Output:

Circular, rounded badges for a sleek appearance.

Combine badges with icons to create visually appealing indicators.

Example:

CSS
<span class="badge bg-info">
  <i class="bi bi-info-circle"></i> Info
</span>
<span class="badge bg-danger">
  <i class="bi bi-exclamation-circle"></i> Error
</span>

Output:

Badges with embedded icons for better user experience.