1.0 alpha has been released! Learn More 1.0 Docs
menu
Become a Patron

Dialogs are content that are not originally visible on a page but show up with extra information if needed. The transitions should make the appearance of the dialog make sense and not jarring to the user.

Toasts

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.

Toast!

To do this, call the Materialize.toast() function programatically in JavaScript.


  // Materialize.toast(message, displayLength, className, completeCallback);
  Materialize.toast('I am a toast!', 4000) // 4000 is the duration of the toast
        

One way to add this into your application is to add this as an onclick event to a button.


  <a class="btn" onclick="Materialize.toast('I am a toast', 4000)">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

  var $toastContent = $('<span>I am toast content</span>').add($('<button class="btn-flat toast-action">Undo</button>'));
  Materialize.toast($toastContent, 10000);
        

Callback

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

Toast!

  <a class="btn" onclick="Materialize.toast('I am a toast', 4000,'',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!

  Materialize.toast('I am a toast!', 3000, 'rounded') // 'rounded' is the class I'm applying to the toast
        

Dismiss a Toast Programatically

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


  // Get toast DOM Element, get instance, then call remove function
  var toastElement = $('.toast').first()[0];
  var toastInstance = toastElement.M_Toast;
  toastInstance.remove();
        

Dismiss all Toasts


  Materialize.Toast.removeAll();
        

Tooltips

Tooltips are small, interactive, textual hints for mainly graphical elements. When using icons for actions you can use a tooltip to give people clarification on its function.

Add the Tooltipped class to your element and add either top, bottom, left, right on data-tooltip to control the position.


  <!-- data-position can be : bottom, top, left, or right -->
  <!-- data-delay controls delay before tooltip shows (in milliseconds)-->
  <a class="btn tooltipped" data-position="bottom" data-delay="50" data-tooltip="I am a tooltip">Hover me!</a>
        

Initialization

Tooltips are initialized automatically, but if you have dynamically added tooltips, you will need to initialize them.


  $(document).ready(function(){
    $('.tooltipped').tooltip({delay: 50});
  });
        

jQuery Plugin Options

Option Name Description
delay Delay time before tooltip appears. (Default: 350)
tooltip Tooltip text. Can use custom HTML if you set the html option.
position Set the direction of the tooltip. 'top', 'right', 'bottom', 'left'. (Default: 'bottom')
html Allow custom html inside the tooltip. (Default: false)

Removal

To remove the tooltip from the button, pass in 'remove' as the option to the tooltip function


  // This will remove the tooltip functionality for the buttons on this page
  $('.tooltipped').tooltip('remove');