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.

action

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

Type:node


children

The content of the component.

Type:node


classes

Override or extend the styles applied to the component.

See CSS API below for more details.

Type:object


closeText

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

Type:string

Default:'Close'


color

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


components

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:{}


componentsProps

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:{}


icon

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


iconMapping

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 }


onClose

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

Signature:
function(event: React.SyntheticEvent) => void
  • event The event source of the callback.

role

The ARIA role attribute of the element.

Type:string

Default:'alert'


severity

The severity of the alert. This defines the color and icon used.

Type:'error'
| 'info'
| 'success'
| 'warning'

Default:'success'


slotProps

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:{}


slots

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:{}


sx

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


variant

The variant to use.

Type:'filled'
| 'outlined'
| 'standard'
| string

Default:'standard'


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.


CSS classes

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

.MuiAlert-action

Styles applied to the action wrapper element if action is provided.

Rule name:action


.MuiAlert-filled

Styles applied to the root element if variant="filled".

Rule name:filled


.MuiAlert-filledError

Styles applied to the root element if variant="filled" and color="error".

Rule name:filledError


.MuiAlert-filledInfo

Styles applied to the root element if variant="filled" and color="info".

Rule name:filledInfo


.MuiAlert-filledSuccess

Styles applied to the root element if variant="filled" and color="success".

Rule name:filledSuccess


.MuiAlert-filledWarning

Styles applied to the root element if variant="filled" and color="warning".

Rule name:filledWarning


.MuiAlert-icon

Styles applied to the icon wrapper element.

Rule name:icon


.MuiAlert-message

Styles applied to the message wrapper element.

Rule name:message


.MuiAlert-outlined

Styles applied to the root element if variant="outlined".

Rule name:outlined


.MuiAlert-outlinedError

Styles applied to the root element if variant="outlined" and color="error".

Rule name:outlinedError


.MuiAlert-outlinedInfo

Styles applied to the root element if variant="outlined" and color="info".

Rule name:outlinedInfo


.MuiAlert-outlinedSuccess

Styles applied to the root element if variant="outlined" and color="success".

Rule name:outlinedSuccess


.MuiAlert-outlinedWarning

Styles applied to the root element if variant="outlined" and color="warning".

Rule name:outlinedWarning


.MuiAlert-root

Styles applied to the root element.

Rule name:root


.MuiAlert-standard

Styles applied to the root element if variant="standard".

Rule name:standard


.MuiAlert-standardError

Styles applied to the root element if variant="standard" and color="error".

Rule name:standardError


.MuiAlert-standardInfo

Styles applied to the root element if variant="standard" and color="info".

Rule name:standardInfo


.MuiAlert-standardSuccess

Styles applied to the root element if variant="standard" and color="success".

Rule name:standardSuccess


.MuiAlert-standardWarning

Styles applied to the root element if variant="standard" and color="warning".

Rule name:standardWarning



You can override the style of the component using one of these customization options:

Edit this page

Was this page helpful?


AccordionSummaryAlertTitle

Blog

Store