Skip to content

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';
Learn about the difference by reading this guide on minimizing bundle size.

Props

Props of the Paper component are also available.

NameTypeDefaultDescription
actionnode-

The action to display. It renders after the message, at the end of the alert.

childrennode-

The content of the component.

classesobject-

Override or extend the styles applied to the component.

See CSS classes API below for more details.

closeTextstring'Close'

Override the default label for the close popup icon button.
For localization purposes, you can use the provided translations.

color'error'
| 'info'
| 'success'
| 'warning'
| string
-

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.

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.

iconnode-

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.

iconMapping{ error?: node, info?: node, success?: node, warning?: 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.

onClosefunc-

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.

Signature:function(event: React.SyntheticEvent) => void
  • event The event source of the callback.
rolestring'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?: func
| object, closeIcon?: func
| object }
{}

The props used for each slot inside.

slots{ closeButton?: elementType, closeIcon?: elementType }{}

The components used for each slot inside.

sxArray<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.

The 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.


Slots

Slot nameClass nameDefault componentDescription
closeButtonIconButtonThe component that renders the close button.
closeIconsvgThe component that renders the close icon.

CSS classes

These class names are useful for styling with CSS. They are applied to the component's slots when specific states are triggered.

Class nameRule nameDescription
.MuiAlert-actionactionStyles applied to the action wrapper element if action is provided.
.MuiAlert-colorErrorcolorErrorStyles applied to the root element if color="error".
.MuiAlert-colorInfocolorInfoStyles applied to the root element if color="info".
.MuiAlert-colorSuccesscolorSuccessStyles applied to the root element if color="success".
.MuiAlert-colorWarningcolorWarningStyles applied to the root element if color="warning".
.MuiAlert-filledfilledStyles applied to the root element if variant="filled".
.MuiAlert-filledErrorfilledErrorStyles applied to the root element if variant="filled" and color="error".
.MuiAlert-filledInfofilledInfoStyles applied to the root element if variant="filled" and color="info".
.MuiAlert-filledSuccessfilledSuccessStyles applied to the root element if variant="filled" and color="success".
.MuiAlert-filledWarningfilledWarningStyles applied to the root element if variant="filled" and color="warning"
.MuiAlert-iconiconStyles applied to the icon wrapper element.
.MuiAlert-messagemessageStyles applied to the message wrapper element.
.MuiAlert-outlinedoutlinedStyles applied to the root element if variant="outlined".
.MuiAlert-outlinedErroroutlinedErrorStyles applied to the root element if variant="outlined" and color="error".
.MuiAlert-outlinedInfooutlinedInfoStyles applied to the root element if variant="outlined" and color="info".
.MuiAlert-outlinedSuccessoutlinedSuccessStyles applied to the root element if variant="outlined" and color="success".
.MuiAlert-outlinedWarningoutlinedWarningStyles applied to the root element if variant="outlined" and color="warning".
.MuiAlert-rootrootStyles applied to the root element.
.MuiAlert-standardstandardStyles applied to the root element if variant="standard".
.MuiAlert-standardErrorstandardErrorStyles applied to the root element if variant="standard" and color="error".
.MuiAlert-standardInfostandardInfoStyles applied to the root element if variant="standard" and color="info".
.MuiAlert-standardSuccessstandardSuccessStyles applied to the root element if variant="standard" and color="success".
.MuiAlert-standardWarningstandardWarningStyles 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: