Bootstrap 4 alert box message can be used for the purpose of creating immediate attention of the end-user with respect to success, warning, and error.
.alert
followed by one of the contextual
classes to the parent container.
.alert-success
,.alert-info
,.alert-warning
,.alert-danger
,.alert-primary
,.alert-secondary
,.alert-light
or .alert-dark
.
Example
Source Code
<div class="container mt-4">
<b>Bootstrap Colored Alert Box</b>
<div class="alert alert-success">
<strong>Success!</strong> This is a success alert box.
</div>
<div class="alert alert-info">
<strong>Info!</strong> This is a info alert box.
</div>
</div>
Source Code: Output
Note:Place .alert
followed by one of the contextual classes to the parent container of the alert box. Basically, contextual classes are used to provide different background colors to the alert box.
Keep in mind that contextual classes are used to provide a colored alert box.
Steps to create bootstrap 4 alert link:
.alert-link
class to any hyperlink base class.
alert-link
class to any hyperlink base class and add one of the contextual classes like: .alert-success
,.alert-info
,.alert-warning
,.alert-danger
,.alert-primary
,.alert-secondary
,alert-light
or .alert-dark
to parent(i.e div) class.
Alert Link Example
General Syntax
<element class="alert alert-*">
<a href="#" class="alert-link">alert link</a>
</element>
Source Code
<div class="container mt-4">
<b>Bootstrap Alert link</b>
<div class="alert alert-success">
<strong>Success!</strong> This is a
<a href="#" class="alert-link">success alert link</a>
</div>
<div class="alert alert-primary">
<strong>Primary!</strong> This is a
<a href="#" class="alert-link">primary alert link</a>
</div>
<div class="alert alert-danger">
<strong>Danger!</strong> This is a
<a href="#" class="alert-link">danger alert link</a>
</div>
</div>
Source Code: Output
Note: You must have to provide a .alert-link
to the hyperlink base class.
.alert-dismissible
class to the
alert container
and then add .close
and data-dismiss="alert"
to a link or a
button element.
Example
General Syntax
<element class="alert alert-* alert-dismissible">
<button type="button" class="close" data-dismiss="alert">�</button>
<strong>Close!</strong> Alert Box
</element>
Source Code
<div class="container mt-4">
<b>Boostrap Alert Box</b>
<div class="alert alert-success alert-dismissible">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Success!</strong> A success alert box with close button.
</div>
<div class="alert alert-warning alert-dismissible">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Warning!</strong> A warning alert box with close button.
</div>
</div>
Source Code: Output
Note: Bootstrap 4 close alert box has a close button. When a user clicks on the close button of the alert box the alert box will disappear from the web page.