Bootstrap 5 Alerts component
Responsive Alerts built with the latest Bootstrap 5. Alerts component shows contextual feedback messages for attracts the user’s attention without interrupting the user’s task.
Alerts are available for any length of text, as well as an optional close button.
Alert styles
By default, alert does not apply any style, use one of the eight required contextual classes (e.g., .alert-success
) for proper styling. For inline dismissal, use the alerts JavaScript plugin.
Success
Add .alert-success
to the .alert
.
<div class="alert alert-success" role="alert">
<div class="d-flex gap-4">
<span><i class="fa-solid fa-circle-check text-success"></i></span>
<div>
File has been uploaded.
</div>
</div>
</div>
Danger
Add .alert-danger
to the .alert
.
This account has been permanently deleted
The user `IanAtlas` no longer has access to Atlassian services.
<div class="alert alert-danger" role="alert">
<div class="d-flex gap-4">
<span><i class="fa-solid fa-circle-exclamation text-danger"></i></span>
<div class="d-flex flex-column gap-2">
<h6 class="mb-0">This account has been permanently deleted</h6>
<p class="mb-0">The user `IanAtlas` no longer has access to Atlassian services.</p>
</div>
</div>
</div>
Warning
Add .alert-warning
to the .alert
.
Cannot connect to the database
We are unable to save any progress at this time.
<div class="alert alert-warning" role="alert">
<div class="d-flex gap-4">
<span><i class="fa-solid fa-circle-exclamation text-warning"></i></span>
<div class="d-flex flex-column gap-2">
<h6 class="mb-0">Cannot connect to the database</h6>
<p class="mb-0">We are unable to save any progress at this time.</p>
</div>
</div>
</div>
Primary
Add .alert-primary
to the alert.
Editing is restricted
You're not allowed to change these restrictions. It's either due to the restrictions on the page, or permission settings for this space.
<div class="alert alert-primary" role="alert">
<div class="d-flex gap-4">
<span><i class="fa-solid fa-circle-info text-primary"></i></span>
<div class="d-flex flex-column gap-2">
<h6 class="mb-0">Editing is restricted</h6>
<p class="mb-0">You're not allowed to change these restrictions. It's either due to the restrictions on the page, or permission settings for this space.</p>
</div>
</div>
</div>
More styles
Add .alert-secondary
to the alert.
<div class="alert alert-secondary" role="alert">
A simple secondary alert—check it out!
</div>
Add .alert-info
to the alert for display information.
<div class="alert alert-info" role="alert">
A simple info alert—check it out!
</div>
Add .alert-light
to the alert.
<div class="alert alert-light" role="alert">
A simple light alert—check it out!
</div>
Add .alert-dark
to the alert.
<div class="alert alert-dark" role="alert">
A simple dark alert—check it out!
</div>
Description
Alerts can also contain additional HTML elements like headings, paragraphs and dividers. Add .alert-heading
to a formatted title above the content.
The Modern Prometheus
You will rejoice to hear that no disaster has accompanied the commencement of an enterprise which you have regarded with such evil forebodings. I arrived here yesterday, and my first task is to assure my dear sister of my welfare and increasing confidence in the success of my undertaking.
Learn more
<div class="alert alert-primary" role="alert">
<h6 class="alert-heading">The Modern Prometheus</h6>
<p class="mb-2">You will rejoice to hear that no disaster has accompanied the commencement of an enterprise which you have regarded with such evil forebodings. I arrived here yesterday, and my first task is to assure my dear sister of my welfare and increasing confidence in the success of my undertaking.</p>
<hr>
<a class="fw-semibold fs-sm" href="#">Learn more</a>
</div>
Dismiss button
Using the alert JavaScript plugin, it’s possible to dismiss any alert inline. Here’s how:
- Be sure you’ve loaded the alert plugin, or the compiled Bootstrap JavaScript.
- Add a close button and the
.alert-dismissible
class, which adds extra padding to the right of the alert and positions the close button. - On the close button, add the
data-bs-dismiss="alert"
attribute, which triggers the JavaScript functionality. Be sure to use the<button>
element with it for proper behavior across all devices. - To animate alerts when dismissing them, be sure to add the
.fade
and.show
classes.
More
This is an info alert — check it out!<div class="alert alert-success alert-dismissible fade show" role="alert">
Holy guacamole! You should check in on some of those fields below.
<button type="button" class="btn-close btn-close-sm" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<div class="alert alert-info alert-dismissible fade show" role="alert">
<h5 class="alert-heading">More</h5>
This is an info alert — check it out!
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
closed.bs.alert
event and programmatically sets focus()
to the most appropriate location in the page. If you’re planning to move focus to a non-interactive element that normally does not receive focus, make sure to add tabindex="-1"
to the element.Link colors
Default link color.
Editing is restricted
You're not allowed to change these restrictions. It's either due to the restrictions on the page, or permission settings for this space.
<div class="alert alert-primary" role="alert">
<div class="d-flex gap-4">
<span><i class="fa-solid fa-circle-info text-primary"></i></span>
<div class="d-flex flex-column gap-2">
<h6 class="mb-0">Editing is restricted</h6>
<p class="mb-0">
You're not allowed to change these restrictions. It's either due to the
restrictions on the page, or permission settings for this space.
</p>
<div class="d-flex gap-1">
<a href="#">Request edit access</a>
<span>·</span>
<a href="#">Learn more</a>
</div>
</div>
</div>
</div>
Use the .alert-link
utility class to quickly provide matching colored links within any alert.
<div class="alert alert-primary" role="alert">
A simple primary alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.
</div>
<div class="alert alert-secondary" role="alert">
A simple secondary alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.
</div>
<div class="alert alert-success" role="alert">
A simple success alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.
</div>
<div class="alert alert-danger" role="alert">
A simple danger alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.
</div>
<div class="alert alert-warning" role="alert">
A simple warning alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.
</div>
<div class="alert alert-info" role="alert">
A simple info alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.
</div>
<div class="alert alert-light" role="alert">
A simple light alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.
</div>
<div class="alert alert-dark" role="alert">
A simple dark alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.
</div>
Custom icon
Similarly, you can use flexbox utilities and Font Awesome Icons to create alerts with icons. Depending on your icons and content, you may want to add more utilities or custom styles.
The Modern Prometheus
You will rejoice to hear that no disaster has accompanied the commencement of an enterprise which you have regarded with such evil forebodings.
<div class="alert alert-primary" role="alert">
<div class="d-flex gap-4">
<span>
<svg width="24" height="24" viewBox="0 0 24 24"><g fill="rgb(12, 102, 228)" fill-rule="evenodd"><path d="M10.935 6v4.738L6.997 19h10.005l-3.938-8.262V6h-2.129zm7.873 12.14A2 2 0 0117.002 21H6.997a2 2 0 01-1.805-2.86l3.743-7.854V4h6.13v6.286l3.743 7.853z" fill-rule="nonzero"></path><path d="M9 13h6l3 7H6z"></path><rect x="8" y="3" width="8" height="2" rx="1"></rect></g></svg></span>
<div class="d-flex flex-column gap-2">
<h6 class="mb-0">The Modern Prometheus</h6>
<p class="mb-0">You will rejoice to hear that no disaster has accompanied the commencement of an enterprise which you have regarded with such evil forebodings. </p>
</div>
</div>
</div>
Accessibility
(WAI-ARIA: https://www.w3.org/WAI/ARIA/apg/patterns/alert/)
When the component is dynamically displayed, the content is automatically announced by most screen readers. At this time, screen readers do not inform users of alerts that are present when the page loads.
Using color to add meaning only provides a visual indication, which will not be conveyed to users of assistive technologies such as screen readers. Ensure that information denoted by the color is either obvious from the content itself (for example the visible text), or is included through alternative means, such as additional hidden text.
Actions must have a tab index of 0 so that they can be reached by keyboard-only users.