Bootstrap 4 Alerts
Display pre-styled alerts and messages for common user actions.
Bootstrap provides an easy way to create a stylized alert message box with its alert component.
To create an alert box, use the .alert
class along with one of the .alert-*
classes to specify the kind of alert.
<div class="alert alert-success" role="alert">Success alert</div>
<div class="alert alert-info" role="alert">Info alert</div>
<div class="alert alert-warning" role="alert">Warning alert</div>
<div class="alert alert-danger" role="alert">Danger alert</div>
<div class="alert alert-light" role="alert">Light alert</div>
<div class="alert alert-dark" role="alert">Dark alert</div>
Dismissible Alerts
You can create dismissible alerts by adding Bootstrap's .alert-dismissible
class, along with a Close button. When the user clicks the Close button, the alert disappears.
Here we use ×
to create the Close icon (×).
xxxxxxxxxx
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
<strong>Congratulations!</strong> You successfully tied your shoelace!
</div>
Fading Effect
You can give the alert a slight fading effect when closing them by adding the .fade
and .show
classes.
xxxxxxxxxx
<div class="alert alert-success alert-dismissible fade show" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
<strong>Congratulations!</strong> You successfully tied your shoelace!
</div>
Alerts with Links
Use Bootstrap's .alert-link
class on the <a>
tag to match link color with the text.
xxxxxxxxxx
<div class="alert alert-success alert-dismissible fade show" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
<strong>Congratulations!</strong> Now you're ready to do the <a href="#" class="alert-link">next shoelace</a>.
</div>