Alerts
An alert gives users important information about their current task, without them having to leave the screen.
Wrap any text and an optional dismiss button in .alert for basic alert messages.
Anatomy
- Container
- Icon
- Body content
- Close (optional)
Types of alert
Options
You have four types to choose from: success, info, warning and error. Pick the one that best fits the message you're trying to convey.
Please keep in mind that the icons for these message types can't be changed.
To apply a type to your alert message simply add one of the following classes: .alert-success, .alert-info, .alert-warning or .alert-danger.
Success .alert-success
Well done!
You successfully read this important alert message.
Info .alert-info
Heads up!
This alert needs your attention, but it's not super important.
Warning .alert-warning
Warning!
Better check yourself, you're not looking too good.
Danger .alert-danger
Oh snap!
Change a few things up and try submitting again.
Title
A bolded title is optional. Use a title to quickly summarise the purpose of the notice. Keep titles short, no more than 60 characters, and avoid repeating the body text.
Alert with title
Alert title
You've confirmed [email protected]. You're all ready to start a new group for your team.
Link
We include the ability to add a link within an alert message because an alert by itself is often just the start of a conversation. The link transforms the alert from a passive notification into an actionable next step.
Alert with link
Alert title
You've confirmed [email protected]. You're all ready to start a new group for your team.
LinkDismiss
Alert notices can include a dismiss button that removes the notice from the page layout. This is helpful for general or supplemental information. The user needs to actively close the alert.
Build on any alert by adding an optional .alert-dismissible and close button.
Warning! Are you sure you want to do this?
You are trying to do something useful, for this you require a proper computer, a mouse with more than one button. Ask an adult to help you out with this.
Close icon
The decision to hide the close icon should be deliberate and reserved only for alerts that represent a mandatory acknowledgement or a system-controlled status change. If the user can ignore the message, they must be given the option to dismiss it.
Warning!
Better check yourself, you're not looking too good.
Max/min width
Having a defined max and min width for an alert is crucial for readability and visual consistency.
A minimum width ensures the alert's content isn't cramped and remains easy to read, whilst a maximum width prevents text lines from becoming too long, which can strain the user's eyes and make the message harder to scan.
Alerts have a minimum width of 300px and a maximum width of 800px.
Max width max-width: 800px
Max width.
This alert will not grow beyond 800px, regardless of how much content you place inside it. Even with a very long message like this one, the alert container is capped at a maximum width of 800px to prevent text lines from becoming too long, which improves readability and keeps the layout visually consistent across wide screens and large viewports.
Min width min-width: 300px
Usage
Placing alerts in the top middle of the screen is a best practice in a design system for visibility and user focus. This position is a prime location that ensures the message is seen without being overly intrusive.
Accessibility
Keyboard interaction
All interactive elements within an alert should be reachable via TAB and SHIFT+TAB keys.
Always use role="alert" on alert containers to announce the alert to screen readers. Close buttons must include aria-label="Close" for screen reader users.
Add tabindex="0" to make alerts focusable via keyboard. A focus outline is displayed when the alert receives focus.
Focusable alert tabindex="0"
Alert title
You've confirmed [email protected]. You're all ready to start a new group for.
Best practices
One alert at a time
Show only one alert at a time. Once a user dismisses or addresses it, replace it with the next most important notice.
Avoid stacking alerts — they can quickly become overwhelming.
Sizing
Small alert
Fancy small alerts? Add .alert-sm for the small version.
Success .alert-success.alert-sm
Well done!
You successfully read this important alert message.
Info .alert-info.alert-sm
Heads up!
This alert needs your attention, but it's not super important.
Warning .alert-warning.alert-sm
Warning!
Better check yourself, you're not looking too good.
Danger .alert-danger.alert-sm
Oh snap!
Change a few things up and try submitting again.
Medium icons
Deprecated in v2.3
.alert-icon-md will be removed in v3.0. Use the default .alert class instead.
For a medium icon size add .alert-icon-md to the alert main wrapper.
Success .alert-success.alert-icon-md
Info .alert-info.alert-icon-md
Warning .alert-warning.alert-icon-md
Danger .alert-danger.alert-icon-md
Large icons
Deprecated in v2.3
.alert-icon-lg will be removed in v3.0. Use the default .alert class instead.
For a large icon size add .alert-icon-lg to the alert main wrapper.
Success .alert-success.alert-icon-lg
Info .alert-info.alert-icon-lg
Warning .alert-warning.alert-icon-lg
Danger .alert-danger.alert-icon-lg