Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

How to create dismissible alerts in Bootstrap ?

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Alerts are a very important component in the Bootstrap library. They are used to display any message to the users like a form being submitted, OTP being sent, or incorrect input entered in the form. In other words, alerts are used to provide feedback messages to the user based on their interaction with the website.

In this article, we will learn how to create a dismissible alert using the Bootstrap library. Dismissible alerts make our website like a modern website where we can dismiss the alert after reading it. We will need to load the alert plugin by including the compiled Bootstrap JavaScript on our HTML page.

We can add the close button and use the .alert-dismissible class, which adds extra padding to the right of the alert and positions the close button. On the close button, we use the data-bs-dismiss=”alert” attribute, which triggers the JavaScript functionality. The <button> element is recommended here for proper behavior across all devices. We can use the .fade and .show classes to animate alerts when they are dismissed.


<div class="alert alert-warning alert-dismissible" role="alert">
    <strong>Alert!</strong>This is a dismissible alert
    <button type="button" class="btn-close" 

Example: In this example, we will add a .alert-dismissible class of Bootstrap.


<!DOCTYPE html>
<html lang="en">
    <!-- Bootstrap CSS -->
    <link href=
    <!-- Bootstrap JS -->
    <script src=
<body class="container">
    <h1>Dismissible Alert</h1>
    <div class="alert alert-warning
                fade show" role="alert">
        This is a dismissible
        alert that can be dismissed after
        clicking on the close button.
        <button type="button"
    <p>This is some page text.</p>


My Personal Notes arrow_drop_up
Last Updated : 17 May, 2023
Like Article
Save Article
Similar Reads
Related Tutorials