Alerts

Provide contextual feedback messages for typical user actions with the handful of available and flexible alert messages.

Examples

Alerts are available for any length of text, as well as an optional dismiss button. For proper styling, use of the contextual classes (e.g., .alert-success) is required. For inline dismissal, use the Alert jQuery widget.

Conveying Meaning to Assistive Technologies

Please refer to the Accessiblity notes about conveying meaning with color.

<div class="alert alert-primary" role="alert">
<strong>Primary!</strong> You read this important alert message.
</div>
<div class="alert alert-secondary" role="alert">
<strong>Secondary!</strong> You read this important alert message.
</div>
<div class="alert alert-success" role="alert">
<strong>Success!</strong> You successfully read this alert message.
</div>
<div class="alert alert-info" role="alert">
<strong>Infomation!</strong> Something needs your attention, but it is not urgent.
</div>
<div class="alert alert-warning" role="alert">
<strong>Warning!</strong> Something seems to have gone wrong with this item.
</div>
<div class="alert alert-danger" role="alert">
<strong>Danger!</strong> There is definitely some error now.
</div>

Use the .alert-link utility class to quickly provide matching colored links within any alert.

<div class="alert alert-primary" role="alert">
<strong>Primary!</strong> You read <a href="#" class="alert-link">this important alert message</a>.
</div>
<div class="alert alert-secondary" role="alert">
<strong>Secondary!</strong> You read <a href="#" class="alert-link">this important alert message</a>.
</div>
<div class="alert alert-success" role="alert">
<strong>Success!</strong> You successfully read <a href="#" class="alert-link">this alert message</a>.
</div>
<div class="alert alert-info" role="alert">
<strong>Information!</strong> Something <a href="#" class="alert-link">needs your attention</a>, but it is not urgent.
</div>
<div class="alert alert-warning" role="alert">
<strong>Warning!</strong> Something seems to have gone <a href="#" class="alert-link">wrong with this item</a>.
</div>
<div class="alert alert-danger" role="alert">
<strong>Danger!</strong> There is definitely <a href="#" class="alert-link">some error</a> now.
</div>

Additional Content

Alerts can also contain additional HTML elements like headings, paragraphs, and dividers.

<div class="alert alert-success" role="alert">
<h4 class="alert-heading">Well done!</h4>
<p>You successfully read this important alert message. This example text is going to run a bit longer so that you can see how spacing within an alert works with this kind of content.</p>
<hr>
<p class="mb-0">Whenever you need to, use the margin utilities to keep things nice and tidy.</p>
</div>

SASS Reference

Variables

The available Customization options, or Sass variables, that can be customized for the alert component.

Name Type Default Description
$enable-alert boolean true Enable the generation of the alert component classes. Smaller segements of the alert component classes can be disabled with the following $enable-* variables.
$enable-alert-close boolean true Enable the generation of the alert close button rule.
$enable-alert-heading boolean true Enable the generation of the alert heading override.
$enable-alert-link boolean true Enable the generation of the alert link styles.
$enable-alert-colors boolean true Enable the generation of the alert color variants.
$alert-padding-y string 1rem Vertical padding for alert containers.
$alert-padding-x string 1rem Horizontal padding for alert containers.
$alert-margin-bottom string $spacer Vertical spacing for alert containers.
$alert-border-width string $border-width Border width for alert containers.
$alert-border-radius string $border-radius Border radius for alert containers.
$alert-link-font-weight string $font-weight-bold Font weight adjustment for alert links.
$alert-close-padding-y string .75rem Vertical padding for alert close buttons.
$alert-close-padding-x string .75rem Horizontal padding for alert close buttons.
$alert-themes map () Map of color schemes for alerts.
$alert-colors list $base-colors Colors to mix and merge into $alert-themes
$alert-levels map $level-context Levels to mix alert colors with.

Mixins

Here are the mixins related to alerts that we use to help generate our CSS. You can also uses these mixins to generate your own custom components or utilities.

alert-variant

Generate an alert color variant.

@include alert-variant($color, $bg, $border, $hover-color);
Argument Type Default Description
$color number none Text color for an alert.
$bg number none Background color for an alert.
$border number none Border and horizontal rule color for an alert.
$hover-color number none Hover state text color for alert links.