The Wayback Machine - https://web.archive.org/web/20240927193615/https://www.geeksforgeeks.org/bootstrap-4-toast/
Open In App

Bootstrap 4 | Toast

Last Updated : 04 Apr, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Toast is used to create something like an alert box which is shown for a short time like a couple of seconds when something happens. Like when the user clicks on a button or submits a form and many other actions.

  • .toast: It helps to create a toast
  • .toast-header : It helps to create the toast header
  • .toast-body : It helps to create toast body

Toast Methods:

  • .toast(options): It helps to activate the toast with a parameter of option. In the below implementation we remove the fading transition effect from the toast, and we delay the hiding of the toast to 8000 milliseconds when it is shown. It has three options animation, autohide, delay. Refer this link for more information on these options.
    Example:  

HTML




<!DOCTYPE html>
<html lang="en">
<head>
    <title>Bootstrap Example</title>
    <meta charset="utf-8">
    <meta name="viewport" 
        content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href=
    <script src=
    </script>
    <script src=
    </script>
    <script src=
    </script>
</head>
<body style="text-align: center">
    <h1 style="color:green">GeeksforGeeks</h1>
    <div class="container mt-3">
        <h3>.toast(options)</h3>
          
<p>
            When we click the button below there
            would be delay of the toast to 8000
            milliseconds.
        </p>
  
        <button type="button" class="btn btn-primary" 
            id="myBtn">Show Toast</button>
        <div class="toast mt-3">
            <div class="toast-header">
                Toast Header
            </div>
            <div class="toast-body">
                Some text inside the toast body
            </div>
        </div>
    </div>
    <script>
        $(document).ready(function () {
            $('#myBtn').click(function () {
                $('.toast').toast({
                    animation: false,
                    delay: 2000
                });
                $('.toast').toast('show');
            });
        });
    </script>
</body>
</html>


  • Output: 
     

 

  • .toast(“show”): It shows the toast
  • .toast(“hide”): It hides the toast
  • .toast(“dispose”): It disposes the toast

Toast Events: 
Example: 
 

HTML




<!DOCTYPE html>
<html lang="en">
<head>
    <title>Bootstrap Example</title>
    <meta charset="utf-8">
    <meta name="viewport" 
        content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href=
    <script src=
    </script>
    <script src=
    </script>
    <script src=
    </script>
</head>
<body style="text-align:center">
    <h1 style="color:green">GeeksforGeeks</h1>
    <div class="container mt-3">
        <h3>Toast Events</h3>
        <strong>show.bs.toast, </strong>
        <strong>shown.bs.toast, </strong>
        <strong>hide.bs.toast, </strong>
        <strong>hidden.bs.toast </strong>
          
<p>Click on the button below to perform toast.</p>
  
        <button type="button" class="btn btn-primary" 
            id="myShowBtn">
            Show Toast
        </button>
        <div class="toast mt-3">
            <div class="toast-header">
                Toast Header
            </div>
            <div class="toast-body">
                Some text inside the toast body
            </div>
        </div>
    </div>
    <script>
        $(document).ready(function () {
            $("#myShowBtn").click(function () {
                $('.toast').toast('show');
            });
            $('.toast').on('show.bs.toast', function () {
                alert('The toast is about to be shown.');
            });
            $('.toast').on('shown.bs.toast', function () {
                alert('The toast is now fully shown.');
            });
            $('.toast').on('hide.bs.toast', function () {
                alert('The toast is about to be hidden.');
            });
            $('.toast').on('hidden.bs.toast', function () {
                alert('The toast is now hidden.');
            });
        });
    </script>
</body>
</html>


Output: 
 

show.bs.toast : It happens when the toast is about to be shown. 
 

shown.bs.toast : It happens when the toast is shown. 
 

hide.bs.toast : It happens when the toast is about to be hidden. 
 

hidden.bs.toast : It happens when the toast is fully hidden. 
 

Supported Browser:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari


Previous Article
Next Article

Similar Reads

How to create smoking hot toast notifications in ReactJS with React Hot Toast module ?
In React, Toast notifications or alerts are modal-like components that display information, or any message to users, usually via buttons. Toast notifications are commonly used to display :  A notification or a custom message. A success message upon submission of a form.An error message if the API request fails.PrerequisitesReact JSNode.js & NPM
3 min read
Angular ng Bootstrap Toast Component
Angular ng bootstrap is a bootstrap framework used with angular to create components with great styling and this framework is very easy to use and is used to make responsive websites. In this article, we will see how to use Toast in angular ng bootstrap. The Toast component is used to make a component that will provide feedback messages to the user
2 min read
How to show Toast at Bottom-left after Scroll Down in Bootstrap 5 ?
Toasts are quick, gentle pop-up messages that keep users informed without interrupting. To achieve this functionality bootstrap does not provide any built-in class. But we can achieve it by combining utility classes like position-fixed, bottom-0, and start-0, and you can position the toast at the bottom-left corner of the viewport. Syntaxif (scroll
3 min read
Onsen UI Toast CSS Components
Onsen UI CSS is used to create beautiful HTML components. It is one of the most efficient ways to create HTML5 hybrid components that are compatible with both mobile and desktop. Toasts are components used to notify the users and take immediate action on them. The toast contains a message and action buttons. Material toasts have sharp corner boxes
2 min read
ReactJS Onsen UI Toast Component
ReactJS Onsen-UI is a popular front-end library with a set of React components that are designed to developing HTML5 hybrid and mobile web apps in a beautiful and efficient way. Toast Component allows the user to display dismissible information or simple actions at the bottom of the page. We can use the following approach in ReactJS to use the Onse
2 min read
ReactJS Blueprint Toast Component
BlueprintJS is a React-based UI toolkit for the web. This library is very optimized and popular for building interfaces that are complex data-dense for desktop applications. Toast Component provides a way for users to the user to show an ephemeral message as an overlay. We can use the following approach in ReactJS to use the ReactJS Blueprint Toast
3 min read
Primer CSS Toast with Loading Animation
Primer CSS is a free open-source CSS framework that is built upon systems that create the foundation of the basic style elements such as spacing, typography, and color. This systematic method makes sure our patterns are steady and interoperable with every other. Its approach to CSS is influenced by object-oriented CSS principles, functional CSS, an
3 min read
Angular PrimeNG Toast Template
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. In this article, we will learn how to use the Toast Template in Angular PrimeNG. We will also learn about the properties, along with their syntaxes th
4 min read
Primer CSS Toast animation in
Primer CSS is a free open-source CSS framework that is built upon systems that create the foundation of the basic style elements such as spacing, typography, and color. This systematic method makes sure our patterns are steady and interoperable with every other. Its approach to CSS is influenced by Object-Oriented CSS principles, functional CSS, an
2 min read
Primer CSS Toasts Toast Position
Primer CSS is a free open-source CSS framework that is built upon systems that create the foundation of the basic style elements such as spacing, typography, and color. This systematic method makes sure our patterns are steady and interoperable with every other. Its approach to CSS is influenced by Object-Oriented CSS principles, functional CSS, an
2 min read
Primer CSS Toast with Link
The Primer CSS Toast element is used to show important messages to the user to enhance the user experience. In this article, we will be discussing Primer CSS Toast with Link. By including a link in the toast, we can allow users to take necessary actions in response to the toast message. To include a link in the toast message we wrap the action text
2 min read
Primer CSS Toast with Dismiss
Primer CSS is a free open-source CSS framework that is built upon systems that create the foundation of the basic style elements such as spacing, typography, and color. This systematic method makes sure our patterns are steady and interoperable with every other. Primer CSS Toast with dismiss is used to create an interface where the user is allowed
3 min read
Onsen UI CSS Component Basic Toast
Onsen UI CSS is used to create beautiful HTML components. It is one of the most efficient ways to create HTML5 hybrid components that are compatible with both mobile and desktop. In this article, we are going to implement the Onsen UI CSS Component Basic Toast component. Toasts are components used to notify the users and take some immediate action
2 min read
Onsen UI CSS Component Material Toast
Onsen UI CSS is used to create beautiful HTML components. It is one of the most efficient ways to create HTML5 hybrid components that are compatible with both mobile and desktop. In this article, we are going to implement the Onsen UI CSS Component Material Toast component. Toasts are components used to notify the users and take some immediate acti
2 min read
Angular PrimeNG Toast Severities
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. This article will show us how to use the Toast Severities in Angular PrimeNG. We will also learn about the properties along with their syntaxes that w
3 min read
Angular PrimeNG Toast Positions
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. This article will show us how to use the Toast Positions in Angular PrimeNG. We will also learn about the properties along with their syntaxes that wi
4 min read
Angular PrimeNG Toast Clear
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. This article will show us how to use Toast Clear in Angular PrimeNG. We will also learn about the properties along with their syntaxes that will be us
3 min read
Angular PrimeNG Toast Multiple
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. This article will show us how to use Toast Multiple in Angular PrimeNG. We will also learn about the properties along with their syntaxes that will be
3 min read
Angular PrimeNG Toast Component
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. It provides a lot of templates, components, theme design, an extensive icon library, and much more. In this article, we will see the Angular PrimeNG T
5 min read
Chakra UI Feedback Toast
Chakra Feedback Toast allows developers to display brief, non-intrusive messages to users. The Chakra toast is designed to provide lightweight feedback about an operation or notification. For example, a toast can alert a user that their settings were saved successfully after submitting a form. Toasts will display for a few seconds and then automati
3 min read
React JS Toast Notification
Toast Notifications are popup messages that are added so as to display a message to a user. It can be a success message, warning message, or custom message. Toast Notification is also called Toastify Notifications. All toast notification comes under-react-toastify module so to use them we need to import this module. Prerequisites: NPM & Node.js
4 min read
ReactJS Reactstrap Toast Component
Reactstrap is a popular front-end library that is easy to use React Bootstrap 4 components. This library contains the stateless React components for Bootstrap 4. The Toast Component allows the user to display dismissible information or simple actions at the bottom of the page. We can use the following approach in ReactJS to use the ReactJS Reactstr
3 min read
How to create toast in React Native ?
React Native is an open-source UI software framework created by Meta Platforms, Inc. It is used to develop applications for Android, Android TV, iOS, macOS, tvOS, Web, Windows, and UWP by enabling developers to use the React framework along with native platform capabilities. In this article, we will be learning how to create toast in React Native.
2 min read
How to Customize Toast Position for Specific Use Cases with ngx-toastr in Angular 18?
ngx-toastr is a popular npm package that allows the developers to show and configure toast messages easily in an angular web application. In this article, we will learn how to position a specific toast message in angular 18. Steps to Change the Position of a Specific ToastStep 1: Setting up the Angular ProjectFirst, we will set up an angular projec
5 min read
How to Create a Snackbar or Toast using CSS & JavaScript?
Snackbar or toast notifications are brief messages that pop up on a webpage to convey information or feedback to users. They are versatile tools for signaling different states, like success, error, or invalid input, and can appear at various positions on the screen. ApproachFirst, create a basic HTML structure for your need and create a container t
4 min read
How to make a Toast Notification in HTML CSS and JavaScript ?
A Toast Notification is a small, non-intrusive popup message that briefly appears on the screen to provide feedback or updates. It features 4 distinct toast types triggered by buttons: "Submit" for a green "Success" toast, each with unique CSS animations. JavaScript manages their display duration. Typically used for alerts or confirmations, it fade
5 min read
Include Bootstrap in AngularJS using ng-bootstrap
AngularJS can be integrated with Bootstrap CSS and Javascript and can be used to create creative forms, tables, navigation bars, etc. Steps: Make sure the Angular CLI present in your system if not then run the command in the terminal to do so. npm install -g @angular/cli Create a new project on visual studio code by running the code ng new project-
2 min read
Difference between bootstrap.css and bootstrap-theme.css
Bootstrap is an HTML, CSS and JS front-end-framework used for developing responsive and mobile-first projects on the web. It is the framework that comes up with predefined terms, thus giving you the ability to use these codes instead of having to create the codes from scratch. It is a collection of HTML, CSS and JS code that is designed to help bui
5 min read
Difference Between Bootstrap 3 and Bootstrap 4
Bootstrap: Bootstrap was developed by Mark Otto and Jacob Thorton at Twitter in August 2011. It is an open-source framework that is used to design responsive websites faster and easier. It is the most popular open-source framework that includes HTML, CSS, and JavaScript. It can create web applications with any server-side Technology like Java, PHP,
2 min read
Difference between Bootstrap 4 and Bootstrap 5
What is Bootstrap? It is an open-source framework from late 2011 that is used for designing responsive websites with a mobile-first approach faster and easier. Bootstrap is available for HTML, CSS, and JS. According to server-side languages like PHP, Node, etc. bootstrap helps to design the frontend. Bootstrap has made the work for developers easie
3 min read