Loading lessons...
Alerts
Alerts
Alerts are boxes that show messages to the user. They are created with the .alert class plus a contextual class.
Alert colors
| Class | Meaning |
|---|---|
.alert-success | success message |
.alert-info | informational message |
.alert-warning | warning message |
.alert-danger | danger message |
.alert-primary | primary message |
.alert-secondary | secondary message |
.alert-dark | dark message |
.alert-light | light message |
Example
<div class="alert alert-success">
<strong>Success!</strong> This alert box indicates a successful action.
</div>
<div class="alert alert-danger">
<strong>Danger!</strong> This alert box indicates a dangerous action.
</div>
Closing alerts
Add .alert-dismissible and a close button to let users dismiss the alert:
<div class="alert alert-warning alert-dismissible fade show">
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
<strong>Warning!</strong> This alert box could indicate a warning.
</div>
The data-bs-dismiss="alert" attribute tells Bootstrap to close the alert when clicked. The .fade and .show classes give a smooth fade animation.
Links in alerts
Use the .alert-link class on links inside alerts to match the alert color:
<div class="alert alert-info">
This is an info alert with an <a href="#" class="alert-link">important link</a>.
</div>
TL;DR
- Alerts use
.alertplus a contextual color class. .alert-dismissiblewith a close button lets users dismiss..alert-linkcolors links to match the alert..fade showadds a fade animation.