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.
Override or extend the styles applied to the component.
See CSS API below for more details.
Type:object
Override the default label for the close popup icon button.
For localization purposes, you can use the provided translations.
Type:string
Default:'Close'
The color of the component. Unless provided, the value is taken from the severity
prop. It supports both default and custom theme colors, which can be added as shown in the palette customization guide.
Type:'error'
| 'info'
| 'success'
| 'warning'
| string
The components used for each slot inside.
This prop is an alias for the slots
prop. It's recommended to use the slots
prop instead.
Type:{ CloseButton?: elementType, CloseIcon?: elementType }
Default:{}
The extra props for the slot components. You can override the existing props or add new ones.
This prop is an alias for the slotProps
prop. It's recommended to use the slotProps
prop instead, as componentsProps
will be deprecated in the future.
Type:{ closeButton?: object, closeIcon?: object }
Default:{}
Override the icon displayed before the children. Unless provided, the icon is mapped to the value of the severity
prop. Set to false
to remove the icon
.
Type:node
The component maps the severity
prop to a range of different icons, for instance success to <SuccessOutlined>
. If you wish to change this mapping, you can provide your own. Alternatively, you can use the icon
prop to override the icon displayed.
Type:{ error?: node, info?: node, success?: node, warning?: node }
Callback fired when the component requests to be closed. When provided and no action
prop is set, a close icon button is displayed that triggers the callback when clicked.
Type:func
function(event: React.SyntheticEvent) => void
event
The event source of the callback.
The severity of the alert. This defines the color and icon used.
Type:'error'
| 'info'
| 'success'
| 'warning'
Default:'success'
The extra props for the slot components. You can override the existing props or add new ones.
This prop is an alias for the componentsProps
prop, which will be deprecated in the future.
Type:{ closeButton?: object, closeIcon?: object }
Default:{}
The components used for each slot inside.
This prop is an alias for the components
prop, which will be deprecated in the future.
Type:{ closeButton?: elementType, closeIcon?: elementType }
Default:{}
The system prop that allows defining system overrides as well as additional CSS styles.
See the `sx` page for more details.
Type:Array<func
| object
| bool>
| func
| object
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.
Styles applied to the root element if variant="filled"
and color="error"
.
Rule name:filledError
Styles applied to the root element if variant="filled"
and color="info"
.
Rule name:filledInfo
Styles applied to the root element if variant="filled"
and color="success"
.
Rule name:filledSuccess
Styles applied to the root element if variant="filled"
and color="warning"
.
Rule name:filledWarning
Styles applied to the root element if variant="outlined"
and color="error"
.
Rule name:outlinedError
Styles applied to the root element if variant="outlined"
and color="info"
.
Rule name:outlinedInfo
Styles applied to the root element if variant="outlined"
and color="success"
.
Rule name:outlinedSuccess
Styles applied to the root element if variant="outlined"
and color="warning"
.
Rule name:outlinedWarning
Styles applied to the root element if variant="standard"
and color="error"
.
Rule name:standardError
Styles applied to the root element if variant="standard"
and color="info"
.
Rule name:standardInfo
Styles applied to the root element if variant="standard"
and color="success"
.
Rule name:standardSuccess
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.