Robert's Resume

Alerts

Code

.alert .alert-(contextual class)

.alert-link

.alert-dismissible

.btn-close

data-bs-dismiss="alert"

.fade

.show

Top

Definitions

Alert
▪ Components that provide contextual feedback messages for typical user actions.
Alert Link
▪ Styles the links inside an alert similarly.
Alert Dismissible
▪ Allows an alert to be closed by the user.
Button Close
▪ Renders an 'x' indicating a close button.
data-bs-close="alert"
▪ Links the button to the element to close (in this case, an alert).
Fade
▪ Adds a brief animation when the alert is dismissed.
Show
▪ When an alert is animated, show displays the alert. It is hidden by default.
Top

Key Points

  • You can add additional elements to alerts like headings, paragraphs and dividers.
  • You can place Bootstrap Icons or third-party icons like Font Awesome inside alerts.
  • Make sure text inside an alert has sufficient color contrast for accessibility standards.
  • As alerts are typically inside a <div>, add role="alert" for accessibility.
  • Top

Basic

Add .alert .alert-* to an element, where * indicates a contextual class.

Top

Closing Alerts

Add .alert-dismissible to the <div>.

Create a button with .btn-close and data-bs-dismiss="alert".

Warning: Don't forget your aria-label on the button!

Top

Animated Alerts

Add .fade and .show to a dismissible alert.

Add the icons by adding a link to the Bootstrap icons and adding the appropriate class to an <i> element.

Top