Skip to content

Modal API

API reference docs for the React Modal 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 Modal from '@mui/material/Modal';
// or
import { Modal } from '@mui/material';
Learn about the difference by reading this guide on minimizing bundle size.

Modal is a lower-level construct that is leveraged by the following components:

If you are creating a modal dialog, you probably want to use the Dialog component rather than directly using Modal.

This component shares many concepts with react-overlays.

Props

Props of the native component are also available.

childrenRequired

A single child content element.

Type:

element
openRequired

If true, the component is shown.

Type:

bool
BackdropComponent

A backdrop component. This prop enables custom backdrop rendering.

Type:

elementType

Default:

styled(Backdrop, { name: 'MuiModal', slot: 'Backdrop', overridesResolver: (props, styles) => { return styles.backdrop; }, })({ zIndex: -1, })
BackdropProps

Props applied to the Backdrop element.

Type:

object
classes

Override or extend the styles applied to the component.

Type:

object
closeAfterTransition

When set to true the Modal waits until a nested Transition is completed before closing.

Type:

bool

Default:

false
component

The component used for the root node. Either a string to use a HTML element or a component.

Type:

elementType
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:

{ Backdrop?: elementType, Root?: 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:

{ backdrop?: func | object, root?: func | object }

Default:

{}
container

An HTML element or function that returns one. The container will have the portal children appended to it.
By default, it uses the body of the top-level document object, so it's simply document.body most of the time.

Type:

HTML element | func
disableAutoFocus

If true, the modal will not automatically shift focus to itself when it opens, and replace it to the last focused element when it closes. This also works correctly with any modal children that have the disableAutoFocus prop.
Generally this should never be set to true as it makes the modal less accessible to assistive technologies, like screen readers.

Type:

bool

Default:

false
disableEnforceFocus

If true, the modal will not prevent focus from leaving the modal while open.
Generally this should never be set to true as it makes the modal less accessible to assistive technologies, like screen readers.

Type:

bool

Default:

false
disableEscapeKeyDown

If true, hitting escape will not fire the onClose callback.

Type:

bool

Default:

false
disablePortal

The children will be under the DOM hierarchy of the parent component.

Type:

bool

Default:

false
disableRestoreFocus

If true, the modal will not restore focus to previously focused element once modal is hidden or unmounted.

Type:

bool

Default:

false
disableScrollLock

Disable the scroll lock behavior.

Type:

bool

Default:

false
hideBackdrop

If true, the backdrop is not rendered.

Type:

bool

Default:

false
keepMounted

Always keep the children in the DOM. This prop can be useful in SEO situation or when you want to maximize the responsiveness of the Modal.

Type:

bool

Default:

false
onBackdropClick

Callback fired when the backdrop is clicked.

Type:

func
onClose

Callback fired when the component requests to be closed. The reason parameter can optionally be used to control the response to onClose.

Type:

func

Signature:

function(event: object, reason: string) => void
  • event The event source of the callback.
  • reason Can be: "escapeKeyDown", "backdropClick".
onTransitionEnter

A function called when a transition enters.

Type:

func
onTransitionExited

A function called when a transition has exited.

Type:

func
slotProps

The props used for each slot inside the Modal.

Type:

{ backdrop?: func | object, root?: func | object }

Default:

{}
slots

The components used for each slot inside the Modal. Either a string to use a HTML element or a component.

Type:

{ backdrop?: elementType, root?: elementType }

Default:

{}
sx

The system prop that allows defining system overrides as well as additional CSS styles.

Type:

Array<func | object | bool> | func | object

The ref is forwarded to the root element.

CSS

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

.MuiModal-rootroot

Class name applied to the root element.

.MuiModal-hiddenhidden

Class name applied to the root element if the Modal has exited.

.MuiModal-backdropbackdrop

Class name applied to the backdrop element.

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