Course Content
Bootstrap 5 Alerts
0/1
Bootstrap
About Lesson

Badges automatically adjust their size based on the parent element. You can combine them with size classes to customize the appearance.

Example:

HTML
<h1>Large Heading <span class="badge bg-primary">Large Badge</span></h1>
<h3>Small Heading <span class="badge bg-secondary">Small Badge</span></h3>

You can dynamically update badge counts using JavaScript.

Example:

HTML
<button id="counterBtn" type="button" class="btn btn-primary">
  Clicks <span id="badgeCount" class="badge bg-secondary">0</span>
</button>

<script>
  let count = 0;
  document.getElementById("counterBtn").addEventListener("click", function () {
    count++;
    document.getElementById("badgeCount").innerText = count;
  });
</script>
  1. Positioning: Badges can be placed inline or floated using Bootstrap utilities like .float-end.
  2. Colors: Use contextual color classes like .bg-success, .bg-danger, etc., for different badge meanings.
  3. Text Styling: Add classes like .text-dark or .text-light for better contrast.
  • Notifications: Highlight unread messages or new updates.
  • Counters: Display counts, such as items in a cart or tasks to complete.
  • Status Indicators: Show status (e.g., active, inactive, processing).
  • Labels: Tag items with categories or priorities.