Alert API
API reference docs for the React Alert component. Learn about the props, CSS, and other APIs of this exported module.
Component demos
Import
import Alert from '@mui/material/Alert';
// or
import { Alert } from '@mui/material';
Props of the Paper component are also available.
Name | Type | Default | Description |
---|---|---|---|
action | node | The action to display. It renders after the message, at the end of the alert. | |
children | node | The content of the component. | |
classes | object | Override or extend the styles applied to the component. See CSS API below for more details. | |
closeText | string | 'Close' | Override the default label for the close popup icon button. |
color | 'error' | 'info' | 'success' | 'warning' | string | The color of the component. Unless provided, the value is taken from the | |
components | { CloseButton?: elementType, CloseIcon?: elementType } | {} | The components used for each slot inside. |
componentsProps | { closeButton?: object, closeIcon?: object } | {} | The extra props for the slot components. You can override the existing props or add new ones. |
icon | node | Override the icon displayed before the children. Unless provided, the icon is mapped to the value of the | |
iconMapping | { error?: node, info?: node, success?: node, warning?: node } | The component maps the | |
onClose | func | Callback fired when the component requests to be closed. When provided and no Signature: function(event: React.SyntheticEvent) => void
| |
role | string | 'alert' | The ARIA role attribute of the element. |
severity | 'error' | 'info' | 'success' | 'warning' | string | 'success' | The severity of the alert. This defines the color and icon used. |
slotProps | { closeButton?: object, closeIcon?: object } | {} | The extra props for the slot components. You can override the existing props or add new ones. |
slots | { closeButton?: elementType, closeIcon?: elementType } | {} | The components used for each slot inside. |
sx | Array<func | object | bool> | func | object | The system prop that allows defining system overrides as well as additional CSS styles. See the `sx` page for more details. | |
variant | 'filled' | 'outlined' | 'standard' | string | 'standard' | The variant to use. |
ref
is forwarded to the root element.Inheritance
While not explicitly documented above, the props of the Paper component are also available in Alert. You can take advantage of this to target nested components.
Theme default props
You can use MuiAlert
to change the default props of this component with the theme.
These class names are useful for styling with CSS. They are applied to the component's slots when specific states are triggered.
Class name | Rule name | Description |
---|---|---|
.MuiAlert-action | action | Styles applied to the action wrapper element if action is provided. |
.MuiAlert-filled | filled | Styles applied to the root element if variant="filled" . |
.MuiAlert-filledError | filledError | Styles applied to the root element if variant="filled" and color="error" . |
.MuiAlert-filledInfo | filledInfo | Styles applied to the root element if variant="filled" and color="info" . |
.MuiAlert-filledSuccess | filledSuccess | Styles applied to the root element if variant="filled" and color="success" . |
.MuiAlert-filledWarning | filledWarning | Styles applied to the root element if variant="filled" and color="warning" . |
.MuiAlert-icon | icon | Styles applied to the icon wrapper element. |
.MuiAlert-message | message | Styles applied to the message wrapper element. |
.MuiAlert-outlined | outlined | Styles applied to the root element if variant="outlined" . |
.MuiAlert-outlinedError | outlinedError | Styles applied to the root element if variant="outlined" and color="error" . |
.MuiAlert-outlinedInfo | outlinedInfo | Styles applied to the root element if variant="outlined" and color="info" . |
.MuiAlert-outlinedSuccess | outlinedSuccess | Styles applied to the root element if variant="outlined" and color="success" . |
.MuiAlert-outlinedWarning | outlinedWarning | Styles applied to the root element if variant="outlined" and color="warning" . |
.MuiAlert-root | root | Styles applied to the root element. |
.MuiAlert-standard | standard | Styles applied to the root element if variant="standard" . |
.MuiAlert-standardError | standardError | Styles applied to the root element if variant="standard" and color="error" . |
.MuiAlert-standardInfo | standardInfo | Styles applied to the root element if variant="standard" and color="info" . |
.MuiAlert-standardSuccess | standardSuccess | Styles applied to the root element if variant="standard" and color="success" . |
.MuiAlert-standardWarning | standardWarning | Styles applied to the root element if variant="standard" and color="warning" . |
You can override the style of the component using one of these customization options:
- With a global class name.
- With a rule name as part of the component's
styleOverrides
property in a custom theme.