Alerts display brief messages for the user without interrupting their use of the app.
The Alert component can be used to provide important and potentially time-sensitive information in a way that does not interfere with the user's tasks. (Source: ARIA APG.)
import Alert from '@mui/joy/Alert';
The Alert component wraps around its content, and stretches to fill its enclosing container, as shown below:
The Alert component supports Joy UI's four global variants:
Every palette included in the theme is available via the
The demo below shows how the values for the
color prop are affected by the global variants:
endDecorator props to append actions and icons to either side of the Alert:
The Alert component supports Joy UI's color inversion by using
Success is walking from failure to failure with no loss of enthusiam.
Please verify your network connection and try again.
This is a time-sensitive Success Alert.
This is a time-sensitive Warning Alert.
This is a time-sensitive Error Alert.
This is a time-sensitive Neutral Alert.
Here are some factors to consider to ensure that your Alert is accessible:
- Because alerts are not intended to interfere with the use of the app, your Alert component should never affect the keyboard focus.
- If an alert contains an action, that action must have a
0so it can be reached by keyboard-only users.
- Essential alerts should not disappear automatically—timed interactions can make your app inaccessible to users who need extra time to understand or locate the alert.
- Alerts that occur too frequently can inhibit the usability of your app.
- Dynamically rendered alerts are announced by screen readers; alerts that are already present on the page when it loads are not announced.
- Color does not add meaning to the UI for users who require assistive technology. You must ensure that any information conveyed through color is also denoted in other ways, such as within the text of the alert itself, or with additional hidden text that's read by screen readers.
The Alert component is composed of a single root
<div> element with its
role set to
<div role="alert" class="MuiAlert-root"> <!-- Alert contents --> </div>
See the documentation below for a complete reference to all of the props and classes available to the components mentioned here.