Bootstrap 4 Alerts

Bootstrap 4 Alerts are the most useful and attention-grabbing messages to display information to users related to the actions they have taken. there are many flexible alert options that you can use to show different types of alerts to users.

You can also add dismiss buttons in alert message boxes to close the alert message after reading the purpose. Let’s find out alerts that you can easily create using Bootstrap 4.

Simple Bootstrap 4 Alerts

A simple alert box is useful to display any size alert messages to users. There is a total of 8 alert box types in Bootstrap 4. You can create alerts using the base class alert with the contextual class .alert-primary and others as given below:

Test it Live

Output

Bootstrap 4 simple alerts

The alert boxes given above are of different colors to display types of information to users. You can test them live to see the look and feel of alert boxes.

Matching Link Color Alerts in Bootstrap 4

You can add a link to alert boxes that match the specified contextual class color. To create an alert with the link, you have to add the class .alert-link to the anchor (<a>) link element as given below:

Test it Live

Output

Matching Link Color Alerts in Bootstrap 4

The above example shows the clickable link that points to a page. You add the links to your alerts to describe the message given in the alert box.

Additional HTML Elements Inside Alerts in Bootstrap 4

You can add more HTML elements to the alert box to display more content that match the specified alert contextual color. The content can be paragraphs, headings, dividers, and others as given below:

Test it Live

Output

Additional HTML Elements Inside Alerts in Bootstrap 4

Dismissing Alert Boxes

Dismissal alerts are useful to display alerts that contain a button to click and close alert boxes. It gets disappeared immediately on click on the close button.

You need to first create an alert box using the base class .alert with contextual class and .alert-dismissible class to the div element. After that, add a button inside the alert box with the class .close and attribute data-dismiss="alert" as given below:

Test it Live

Output

Dismissing Alerts in Bootstrap 4

The animation effect can be added to the alert boxes by adding the class .fade to the <div> element. You can test the above example live to see other alert boxes using all the contextual classes.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.