Bootstrap 4 alerts system 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. Step 2: These contextual classes are: .alert-success
,.alert-info
,.alert-warning
,.alert-danger
,.alert-primary
,.alert-secondary
,.alert-light
or .alert-dark
.
Example
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.
General Syntax
<div class="alert alert-success">
<strong>Success!</strong> This is a success alert box.
</div>
Source Code
<div class="container mt-5">
<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 class="alert alert-warning"><strong>Warning!</strong> This is a warning alert box.</div>
<div class="alert alert-danger"><strong>Danger!</strong> This is a danger alert box..</div>
<div class="alert alert-primary"><strong>Primary!</strong> This is a primary alert box..</div>
<div class="alert alert-secondary"><strong>Secondary!</strong> This is secondary alert box.</div>
<div class="alert alert-dark"><strong>Dark!</strong> This is dark alert boix.</div>
<div class="alert alert-light"><strong>Light!</strong> This is light alert box.</div>
</div>
Try it yourself
Source Code : Output
Note: Please keep in mind that contextual classes are used to provide a colored alert box.
Creating bootstrap alert link:
Step1: To create a bootstrap alert link, you have to apply the .alert-link
class to any hyperlink base class.
Step2:To create alert colored bootstrap alert link,you have to applyalert-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.
General Syntax
<div class="alert alert-success">
<strong>Success!</strong> This is a <a href="#" class="alert-link">success alert link</a>
</div>
Source Code
<div class="container">
<h2>Boostrap Alert link</h2>
<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>
Try it yourself
Source Code : Output
Note:You must have to provide a .alert-link
to the hyperlink base class.
alert container
and then add .close
and data-dismiss="alert"
to a link or a button element.
General Syntax
<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>
Source Code
<div class="container">
<div class="alert alert-success alert-dismissible">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"></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>
<!--/container-->
Try it yourself
Source Code : Output
Note:This alert box has a close button therefore after performing a click operation on the button, then it disappears from the web page.