BS5 Alerts

In Bootstrap 5, the Alert component is used to display important messages or notifications to the user. It provides a simple way to highlight information or communicate certain states or actions. Here's an example of how to use the Alert component in Bootstrap 5:

html
<div class="alert alert-primary" role="alert">
    This is a primary alert—check it out!
</div>

In the above example, the `<div>` element with the classes `alert` and `alert-primary` creates an alert. The `alert` class is the base class for all alerts, and the `alert-primary` class sets the alert with a primary color.

You can customize the appearance and behavior of the alert by using different alert classes and adding optional elements inside it, such as a close button or additional content.


Here are a few examples of different types of alerts you can create:

html
<div class="alert alert-primary" role="alert">
    This is a primary alert—check it out!
</div>

<div class="alert alert-secondary" role="alert">
    This is a secondary alert—check it out!
</div>

<div class="alert alert-success" role="alert">
    This is a success alert—check it out!
</div>

<div class="alert alert-danger" role="alert">
    This is a danger alert—check it out!
</div>

<div class="alert alert-warning" role="alert">
    This is a warning alert—check it out!
</div>

<div class="alert alert-info" role="alert">
    This is an info alert—check it out!
</div>

<div class="alert alert-light" role="alert">
    This is a light alert—check it out!
</div>

<div class="alert alert-dark" role="alert">
    This is a dark alert—check it out!
</div>

In addition to the different alert classes, you can also add additional elements to the alerts, such as a close button or additional content. For example:

html
<div class="alert alert-success alert-dismissible fade show" role="alert">
This is a success alert with a close button.
    <button type="button" class="btn-close" data-bs-dismiss="alert" aria-
label="Close"></button>
</div>

    <div class="alert alert-warning" role="alert">
    <h4 class="alert-heading">Warning!</h4>
    <p>This is a warning alert with some additional content.</p>
    <hr>
    <p class="mb-0">Make sure to pay attention to it.</p>
</div>

Remember to include the Bootstrap CSS and JavaScript files in your HTML document to ensure that the Alert component and other Bootstrap components work properly.


For more details and advanced options, refer to the official Bootstrap documentation on the
Alert component: [Bootstrap Alerts](https://getbootstrap.com/docs/5.0/components/alerts/)



About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





 PreviousNext