Provide contextual feedback messages for typical user actions with the handful of available and flexible alert messages.
Bootstrap 4 documentationAlerts are available for any length of text, as well as an optional dismiss button. For
proper styling, use one of the eight required
contextual classes (e.g., .alert-success
).
For inline dismissal, use the alerts jQuery plugin.
<div class="alert alert-primary" role="alert">
<span class="alert-inner--text">This is a primary alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.</span>
</div>
<div class="alert alert-secondary" role="alert">
<span class="alert-inner--text">This is a secondary alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.</span>
</div>
<div class="alert alert-success" role="alert">
<span class="alert-inner--text">This is a success alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.</span>
</div>
<div class="alert alert-info" role="alert">
<span class="alert-inner--text">This is a info alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.</span>
</div>
<div class="alert alert-warning" role="alert">
<span class="alert-inner--text">This is a warning alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.</span>
</div>
<div class="alert alert-danger" role="alert">
<span class="alert-inner--text">This is a danger alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.</span>
</div>
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 (e.g. the visible text), or is included through alternative means,
such as additional text hidden with the .sr-only
class.
Using the alert JavaScript plugin, it's possible to dismiss any alert inline. Here's how:
util.js
. The compiled version includes
this.
.alert-dismissible
class, which adds extra padding to the right of the alert and positions the .close
button.data-dismiss="alert"
attribute, which triggers the JavaScript functionality. Be sure to use the <button>
element with
it for proper behavior across all devices..fade
and .show
classes.
<div class="alert alert-primary alert-dismissible fade show" role="alert">
<span class="alert-inner--icon"><i class="fas fa-brain"></i></span>
<span class="alert-inner--text"><strong>Primary alert!</strong> You successfully read this important alert message.</span>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="alert alert-secondary alert-dismissible fade show" role="alert">
<span class="alert-inner--icon"><i class="far fa-dizzy"></i></span>
<span class="alert-inner--text"><strong>Secondary note!</strong> You successfully read this important alert message.</span>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<span class="alert-inner--icon"><i class="far fa-thumbs-up"></i></span>
<span class="alert-inner--text"><strong>Well done!</strong> You successfully read this important alert message.</span>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="alert alert-info alert-dismissible fade show" role="alert">
<span class="alert-inner--icon"><i class="far fa-bell"></i></span>
<span class="alert-inner--text"><strong>Heads up!</strong>This alert needs your attention, but it's not super important.</span>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="alert alert-warning alert-dismissible fade show" role="alert">
<span class="alert-inner--icon"><i class="fas fa-exclamation-circle"></i></span>
<span class="alert-inner--text"><strong>Warning!</strong> Better check yourself, you're not looking too good.</span>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<span class="alert-inner--icon"><i class="fas fa-fire"></i></span>
<span class="alert-inner--text"><strong>Oh snap!</strong> Change a few things up and try submitting again.</span>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>