Search...

Alert

Bootstrap 5 Alert

Bootstrap 5 Alerts are used to send feedback messages to users after they perform particular activities.

Bootstrap 5 Alerts have an optional dismiss button. It is used with text of varying lengths to pass information to users. Contextual props (e.g., color="success") are used to give Bootstrap Alerts a suitable style. The dismiss prop is used for inline dismissal of the Alert component.

Default Alert

Bootstrap Alert Component can by used by adding alert to a div element's class. Our alerts can be styled with backdrop colors by adding the alert's color ( alert-primary, alert-secondary, alert-success, etc.) to the class of the div element.

HTML
html
<div>
<div className="alert alert-primary">
A simple alert built with contrast design check it out!
</div>
<div className="alert alert-secondary">
A simple alert built with contrast design check it out!
</div>
<div className="alert alert-success">
A simple alert built with contrast design check it out!
</div>
<div className="alert alert-danger">
A simple alert built with contrast design check it out!
</div>
<div className="alert alert-warning">
A simple alert built with contrast design check it out!
</div>
<div className="alert alert-info">
A simple alert built with contrast design check it out!
</div>
<div className="alert alert-dark">
A simple alert built with contrast design check it out!
</div>
</div>

Dismissible Alert Button

HTML
html
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<strong>Holy guacamole!</strong> You should check in on some of those fields below.
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>

Dismissible Alert Button with Javascript

HTML
html
<div
class="alert alert-warning alert-dismissible fade show"
id="alert1"
role="alert"
>
Hey Dismiss me using Javascript
</div>
<button id="dismiss1" class="btn btn-dark btn-flat mt-4">
Dismiss Alert
</button>
</div>
JavaScript
js
<script>
document.querySelector('#dismiss1').addEventListener('click', () => {
var alertNode = document.querySelector('#alert1');
var alert = new bootstrap.Alert(alertNode);
alert.close();
});
</script>

Build modern projects using Bootstrap 5 and Contrast

Trying to create components and pages for a web app or website from scratch while maintaining a modern User interface can be very tedious. This is why we created Contrast, to help drastically reduce the amount of time we spend doing that. so we can focus on building some other aspects of the project.

Contrast Bootstrap PRO consists of a Premium UI Kit Library featuring over 10000+ component variants. Which even comes bundled together with its own admin template comprising of 5 admin dashboards and 23+ additional admin and multipurpose pages for building almost any type of website or web app.
See a demo and learn more about Contrast Bootstrap Pro by clicking here.

ad-banner