Reprence Html CSS javascript PHP MySQL Bootsrap

Alerts

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

Example

Alerts are available for any length of text, as well as an optional close button. For proper styling, use one of the eight required contextual classes (e.g., .alert-success). For inline dismissal, use the alerts JavaScript plugin.

alt1 alt2

Live example

Click the button below to show an alert (hidden with inline styles to start), then dismiss (and destroy) it with the built-in close button.

alt3

We use the following JavaScript to trigger our live alert demo:



Link color

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

alt4 alt5

Additional content

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

alt6

Icons

Similarly, you can use flexbox utilities and Bootstrap Icons to create alerts with icons. Depending on your icons and content, you may want to add more utilities or custom styles.

alt7

Need more than one icon for your alerts? Consider using more Bootstrap Icons and making a local SVG sprite like so to easily reference the same icons repeatedly.


alt8

Dismissing

Using the alert JavaScript plugin, it’s possible to dismiss any alert inline. Here’s how:

alt9

You can see this in action with a live demo:


alt10

CSS

Variables

As part of Bootstrap’s evolving CSS variables approach, alerts now use local CSS variables on .alert for enhanced real-time customization. Values for the CSS variables are set via Sass, so Sass customization is still supported, too.


Sass variables


Sass mixins

Used in combination with $theme-colors to create contextual modifier classes for our alerts.


Sass loops

Loop that generates the modifier classes with the alert-variant() mixin.


JavaScript behavior

Initialize

Initialize elements as alerts


Triggers

Dismissal can be achieved with the data-bs-dismiss attribute on a button within the alert as demonstrated below:

or on a button outside the alert using the additional data-bs-target as demonstrated below:


Note that closing an alert will remove it from the DOM.


Methods

You can create an alert instance with the alert constructor, for example:


This makes an alert listen for click events on descendant elements which have the data-bs-dismiss="alert" attribute. (Not necessary when using the data-api’s auto-initialization.)

alt11

Events

Bootstrap’s alert plugin exposes a few events for hooking into alert functionality.

alt12