agyanadda@gmail.com

Bootstrap Alerts and Badges

Bootstrap Components 1 min read Updated Dec 1, 2026 Topic 14 of 32

Alerts

Alerts show feedback messages.

<div class="alert alert-success">Saved successfully!</div>
  • Colours: alert-primary, alert-success, alert-danger, alert-warning, alert-info…
  • Links inside: alert-link matches the alert colour
  • Headings: alert-heading
  • Dismissible: add alert-dismissible fade show and a close button <button class="btn-close" data-bs-dismiss="alert"> (needs Bootstrap JS)

Badges

Small labels and counters.

  • badge text-bg-primary — coloured label
  • rounded-pill — pill shape
  • Inside buttons: Messages <span class="badge text-bg-light">4</span>
  • Notification dot: position-absolute top-0 start-100 translate-middle

Example

Example — Alerts and badges HTML
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">

<div class="container my-3">
  <div class="alert alert-success"><strong>Success!</strong> Your profile was updated.</div>
  <div class="alert alert-danger">Payment failed. <a href="#" class="alert-link">Try again</a>.</div>
  <div class="alert alert-warning alert-dismissible fade show">
    Your exam starts in 10 minutes.
    <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
  </div>

  <h4>New course <span class="badge text-bg-danger">Hot</span></h4>
  <span class="badge rounded-pill text-bg-primary">HTML</span>
  <span class="badge rounded-pill text-bg-info">CSS</span>

  <button class="btn btn-primary position-relative ms-3">
    Inbox
    <span class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger">9</span>
  </button>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>

Test Yourself With Exercises

Exercise 1 Multiple Choice

Which attribute closes an alert when the button is clicked?

Exercise 2 True / False

Dismissible alerts need the Bootstrap JavaScript file.

Exercise 3 Fill in the Blank

Add the class rounded-___ to make a pill-shaped badge.

Frequently Asked Questions

Check the session in Blade: @if(session('success')) <div class="alert alert-success">{{ session('success') }}</div> @endif