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.

Demos

For examples and details on the usage of this React component, visit the component demo pages:

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

The following class names are useful for styling with CSS (the state classes are marked).
To learn more, visit the component customization page.


.MuiAlert-rootroot

Styles applied to the root element.


.MuiAlert-filledfilled

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


.MuiAlert-outlinedoutlined

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


.MuiAlert-standardstandard

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


.MuiAlert-standardSuccessstandardSuccess

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


.MuiAlert-standardInfostandardInfo

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


.MuiAlert-standardWarningstandardWarning

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


.MuiAlert-standardErrorstandardError

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


.MuiAlert-outlinedSuccessoutlinedSuccess

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


.MuiAlert-outlinedInfooutlinedInfo

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


.MuiAlert-outlinedWarningoutlinedWarning

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


.MuiAlert-outlinedErroroutlinedError

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


.MuiAlert-filledSuccessfilledSuccess

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


.MuiAlert-filledInfofilledInfo

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


.MuiAlert-filledWarningfilledWarning

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


.MuiAlert-filledErrorfilledError

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


.MuiAlert-iconicon

Styles applied to the icon wrapper element.


.MuiAlert-messagemessage

Styles applied to the message wrapper element.


.MuiAlert-actionaction

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


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