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

Bootstrap4 Alerts

Bootstrap4 Alerts

Bootstrap 4 makes it easy to create 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="close" and data-dismiss="alert" to the close button's link to set up the dismiss action.

Example

<div class=">

alert alert-success alert-dismissible

"

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

Success!

strong

Specifies a success message for an operation.

div

Try it »

Tip: × (×) is an HTML entity used to represent the close action, not the letter "x".


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 »