--- productId: material-ui title: React Snackbar component components: Snackbar, SnackbarContent githubLabel: 'scope: snackbar' materialDesign: https://m2.material.io/components/snackbars waiAria: https://www.w3.org/TR/wai-aria-1.1/#alert githubSource: packages/mui-material/src/Snackbar --- # Snackbar
Snackbars (also known as toasts) are used for brief notifications of processes that have been or will be performed.
{{"component": "@mui/docs/ComponentLinkHeader"}} ## Introduction The Snackbar component appears temporarily and floats above the UI to provide users with (non-critical) updates on an app's processes. The demo below, inspired by Google Keep, shows a basic Snackbar with a text element and two actions: {{"demo": "SimpleSnackbar.js"}} ### Usage Snackbars differ from [Alerts](/material-ui/react-alert/) in that Snackbars have a fixed position and a high z-index, so they're intended to break out of the document flow; Alerts, on the other hand, are usually part of the flow—except when they're [used as children of a Snackbar](#use-with-alerts). Snackbars also differ from [Dialogs](/material-ui/react-dialog/) in that Snackbars are not intended to convey _critical_ information or block the user from interacting with the rest of the app; Dialogs, by contrast, require input from the user in order to be dismissed. ## Basics ### Import ```jsx import Snackbar from '@mui/material/Snackbar'; ``` ### Position Use the `anchorOrigin` prop to control the Snackbar's position on the screen. {{"demo": "PositionedSnackbar.js"}} ### Content ```jsx import SnackbarContent from '@mui/material/SnackbarContent'; ``` Use the Snackbar Content component to add text and actions to the Snackbar. {{"demo": "LongTextSnackbar.js"}} ### Automatic dismiss Use the `autoHideDuration` prop to automatically trigger the Snackbar's `onClose` function after a set period of time (in milliseconds). Make sure to [provide sufficient time](https://www.w3.org/TR/UNDERSTANDING-WCAG20/time-limits.html) for the user to process the information displayed on it. {{"demo": "AutohideSnackbar.js"}} ### Transitions You can use the `TransitionComponent` prop to change the transition of the Snackbar from [Grow](/material-ui/transitions/#grow) (the default) to others such as [Slide](/material-ui/transitions/#slide). {{"demo": "TransitionsSnackbar.js"}} ## Customization ### Preventing default click away event If you would like to prevent the default onClickAway behavior, you can set the event's `defaultMuiPrevented` property to `true`: ```jsx