Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Bootstrap5 Alerts

Bootstrap5 Alerts

Bootstrap 5 can easily implement alerts.

Alerts can be created using the .alert class, followed by the .alert-success, .alert-info, .alert-warning, .alert-danger, .alert-primary, .alert-secondary, .alert-light or .alert-dark classes:

Example

<div class=">

alert alert-success

"

<

strong

Success!

strong

Specifies a success message for an operation.

div

Try it »


Adding Links to Alerts

Add the alert-link class to links inside an alert to set a link color that matches the alert:

Example

<div class=">

alert alert-success

"

<

strong

Success!

strong

You should read carefully

<a href="" class="alert-link">

this message

a

。

div

Try it »


Dismissing Alerts

We can add the .alert-dismissible class to the div in the alert, then add class="btn-close" and data-bs-dismiss="alert" to the close button link to set the alert's dismiss operation.

Example

<div class=">

alert alert-success alert-dismissible

"

<button type="button" class="btn-close" data-bs-dismiss="alert" button>
<strong>

Success!

strong

Specifies a success message for an operation.

div

Try it »


Alert Animations

The .fade and .show classes are used to set fade-out and fade-in effects when dismissing an alert:

Example

<div class=">

alert alert-danger alert-dismissible fade show

"

Try it »