Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

Bootstrap JS Toasts


Toast CSS Classes

The Toast component is like an alert box that is only shown for a couple of seconds when something happens (i.e. when the user clicks on a button, submits a form, etc.).

For a tutorial about Toasts, read our Bootstrap Toast Tutorial.

Class Description Example
.toast Creates the toast Try it
.toast-header Creates the toast header Try it
.toast-body Creates the toast body Try it

Activate Via JavaScript

Toasts must be initialized with jQuery: select the specified element and call the toast() method.

Example

<script>
$(document).ready(function(){
  $('.toast').toast('show');
});
</script>
Try it Yourself »

Toast Options

Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-, as in data-animation="".

Name Type Default Description Try it
animation boolean true

Specifies whether to add a CSS fade transition effect when showing and hiding the toast.

  • true - Add a fading effect
  • false - Do not add a fading effect
Try it
autohide boolean true Specifies whether to hide the toast by default Try it
delay number 500 Specifies the number of milliseconds it will take to hide the toast once it is shown. Try it

Toast Methods

The following table lists all available toast methods.

Method Description Try it
.toast(options) Activates the toast with an option. See options above for valid values Try it
.toast("show") Shows the toast Try it
.toast("hide") Hides the toast Try it
.toast("dispose") Hides and destroys the toast Try it

Toast Events

The following table lists all available toast events.

Event Description Try it
show.bs.toast Occurs when the toast is about to be shown Try it
shown.bs.toast Occurs when the toast is fully shown (after CSS transitions have completed) Try it
hide.bs.toast Occurs when the toast is about to be hidden Try it
hidden.bs.toast Occurs when the toast is fully hidden (after CSS transitions have completed) Try it

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.