According to Material Design a
Snackbar or Toast provides "brief messages about app processes at the bottom of the screen."
Generally, they should not have an icon associated with it and should be only one line on most
While this version of a Snackbar follows the Material Design semantics closely, it strays in several
You can read more about those differences on the GitHub page.
The most basic option, and probably the one that will be used with every SnackBar.
By default, the snackbar will display the message "Operation performed successfully".
Messages should be short and descriptive;
If your message expands to a second line, it is probably too long.
message: "Hi there"
The message can be any HTML string, but it is best to keep the HTML simple, using tags like
<em> and <strong> to provide emphasis. For links, you should utilize the
actions instead, to provide a pre-formatted link.
message: "Do <em>NOT</em> do that again"
Don't listen to the button above, just click it
The SnackBars will resize based on the content passed in to them.
However it may be desirable for them to have a fixed width,
which you can set using the width property on the options.
The width can be set to any valid CSS value for the width property.
If you set your width too low, the snackbar will not display correctly.
For example, setting a width of 1rem is far
too small for any text to fit within, and the text will
collapse fully and be hidden.
The width must, at minimum, fit a whole word for the
SnackBar to be displayed correct.
Use this feature with caution.
By default, there are several color options for showing notifications.
When a notification is displayed, it can either have one of these context colors attached to it, or no indicator at all (the default behavior). Click one of the buttons below to view an example.
The possible options can be found in the table below
"info" or any other string
Icons can add additional flair to your messages, so the SnackBar comes with several built-in.
These icons are simply monospace text, and so can also be customized to any single character.
Keep in mind, however, that monospaces characters are serif fonts in all modern browsers.
If you are looking for more customization, then you'll need to roll some custom CSS to
target the icons.
While the icons and the colors can be mixed and matched, the icons
require a status color to be set in order to appear.
A snackbar can be configured to stay on screen for a certain amount of time.
For warnings or messages with actions, it is best to increase this time.
In general, the timeout should be no shorter than 4 seconds long.
timeout: 5000 // ms
Additionally, a SnackBar can also be configured to hide its close button.
This is useful in scenarios where a message is particularly important, or where the message has a custom close
If you don't want to the SnackBar to timeout and instead want the user to manually intervene,
you can set the timeout to any value less than 1 or false
timeout: 0 // less than or equal to 0
You may want the SnackBar to come on screen quicker or slower.
To that end, you can specify the speed property to set the transition-duration
for the element.
If you send in a number, then it will be applied as milliseconds (e.g. 500 will become "500ms").
If you send in a string, then it will be applied directly to the property with no modifications, making the valid
options any valid CSS property for the transformation-duration property.
Sending in any other type of value will result in no change to the animation duration.
By default, the Snackbar will appear in the bottom-right corner of the container.
This can be changed by setting the position option to one of the values below
"tc" or "tm"
"bc" or "bm"
SnackBars can appear in multiple positions simultaneously without interfering with one another,
but it is best to avoid changing the position of your SnackBar.
If your page's body scrolls as the page resizes, it may be necessary to use the fixed option.
By default the SnackBars have absolute positioning and will stay within the container they are created in, but setting fixed: true will keep them in the corner of the screen.
Buttons can be added to SnackBars to allow for additional actions.
This can be useful in scenarios where a snackbar may warrant additional user interaction (ie an undo button).
Actions can also be configured to close the snackbar.
By default, the SnackBars will appear in the body tag.
However, in some layouts, it may be more desirable for them to appear within an inner container.
The container property can accept any string that the document.querySelector method can,
including classes and IDs. See MDN for more details.
Note: This requires the containing element to have a non-static position (e.g. position: relative;)