settings

Toasts

bookmark

Materialize provides an easy way for you to send unobtrusive alerts to your users through toasts. These toasts are also placed and sized responsively, try it out by clicking the button below on different device sizes.

Basic
Toast!
<a class="btn" href="#!" onclick="M.toast({html: 'I am a toast!'})">Toast!</a>
Custom HTML

You can pass in an HTML String as the first argument as well. Take a look at the example below, where we pass in text as well as a flat button. If you call an external function instead of in-line JavaScript, you will not need to escape quotation marks.

Toast with Action
<a class="btn" href="#!" onclick="displayCustomHTMLToast()">Toast with Action</a>
function displayCustomHTMLToast() {    var toastHTML = '<span>I am toast content</span><button class="btn-flat toast-action">Undo</button>';    M.toast({        html: toastHTML    });}
Callback

You can have the toast callback a function when it has been dismissed.

Toast!
<a class="btn" href="#!" onclick="M.toast({html: 'I am a toast', completeCallback: function(){alert('Your toast was dismissed')}})">Toast!</a>
Styling Toasts

We've added the ability to customize your toasts easily. You can pass in classes as an optional parameter into the toast function. We've added a rounded class for you, but you can create your own CSS classes and apply them to toasts. Checkout out our full example below.

Round Toast!
<a class="btn" href="#!" onclick="M.toast({html: 'I am a toast!', classes: 'rounded'});">Round Toast!</a>
Dismiss a Toast Programatically

To remove a specific toast using JavaScript, access the M_Toasttoast HTML element and call the dismiss function

// Get toast DOM Element, get instance, then call dismiss functionvar toastElement = document.querySelector('.toast');var toastInstance = M.Toast.getInstance(toastElement);toastInstance.dismiss();//Dismiss all ToastsM.Toast.dismissAll();