Class 24 of 48 • Core Components

Bootstrap 5 Alerts, Dismissible Notifications & Event Hooks

Alerts provide contextual feedback messages for typical user actions (e.g. successful form submissions, security warnings, network error alerts, and system announcements). Bootstrap 5 alerts support rich content, matching icon styles, and smooth dismissible fade transitions.

Bootstrap 5 Contextual Alerts and Dismissible Notifications
Figure 24: Contextual alert styling with status icons, emphasized text, and accessible dismiss button triggers.

1. The Contextual Alert Classes

Wrap your message inside <div class="alert alert-*" role="alert">:

<div class="alert alert-primary" role="alert">A simple primary alert!</div>
<div class="alert alert-success" role="alert">Your project was saved successfully!</div>
<div class="alert alert-danger" role="alert">Error: Invalid login credentials.</div>
<div class="alert alert-warning" role="alert">Warning: Server maintenance tonight at 11 PM.</div>

2. Dismissible Alerts with Fade Transition

To allow users to dismiss an alert, add the .alert-dismissible and .fade.show classes, followed by a close button with data-bs-dismiss="alert":

<div class="alert alert-warning alert-dismissible fade show shadow-sm" role="alert">
  <strong><i class="fa fa-exclamation-triangle"></i> Examination Notice:</strong>
  BCA Practical lab submissions close this Friday at 5:00 PM.
  <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>

3. Alerts with Additional Content & Dividers

Alerts can contain complex markup including headings, paragraphs, and dividers:

<div class="alert alert-success p-4 rounded-3" role="alert">
  <h4 class="alert-heading"><i class="fa fa-check-circle"></i> Registration Successful!</h4>
  <p>Your student account has been verified. You now have full access to all 48 Bootstrap classes.</p>
  <hr>
  <p class="mb-0">Whenever you need help, feel free to visit our Student Discussion Forum.</p>
</div>

Explore Related Bootstrap Tutorials & Next Steps

Strengthen your responsive web design mastery by studying these connected classes:

Badges & Status Counters

Combine alerts with status badges to highlight critical information.

Toast Push Notifications

Compare static in-page alerts with auto-dismissing floating toasts.

Dismissible Alert Events

Listen for close.bs.alert and closed.bs.alert JavaScript events.

Alert ARIA Live Regions

Use role='alert' and aria-live='assertive' to inform screen readers.

Frequently Asked Questions (FAQ) - Student & Interview Review

Alerts dispatch two events: close.bs.alert (fires immediately when the close button is clicked) and closed.bs.alert (fires once the fade-out CSS transition finishes and the alert is removed from the DOM).
Retrieve the alert instance and call close(): const alert = bootstrap.Alert.getOrCreateInstance('#myAlert'); alert.close();.
The role='alert' attribute is an ARIA landmark that instructs assistive technologies (screen readers) to immediately announce the message to visually impaired users.

Next Step in Your Bootstrap Learning Path:

Advance your practical frontend engineering skills with the next topic in our synchronized curriculum.

Continue to Class 25: Badges & Pill Counters → Previous: ← Class 23: Dropdowns & Split Menus | Full Syllabus

Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Reddit

You may also like this!