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.
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>
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>
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>
Strengthen your responsive web design mastery by studying these connected classes:
Combine alerts with status badges to highlight critical information.
Compare static in-page alerts with auto-dismissing floating toasts.
Listen for close.bs.alert and closed.bs.alert JavaScript events.
Use role='alert' and aria-live='assertive' to inform screen readers.
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).
close(): const alert = bootstrap.Alert.getOrCreateInstance('#myAlert'); alert.close();.
role='alert' attribute is an ARIA landmark that instructs assistive technologies (screen readers) to immediately announce the message to visually impaired users.
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