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/joy/Modal';
// or
import { Modal } from '@mui/joy';
You can learn about the difference by reading this guide on minimizing bundle size.

Props

Props of the native component are also available.

NameTypeDefaultDescription
children*element
A single child content element.
⚠️ Needs to be able to hold a ref.
open*bool
If true, the component is shown.
componentelementType
The component used for the root node. Either a string to use a HTML element or a component.
containerHTML element
| func
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.
disableAutoFocusboolfalse
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.
disableEnforceFocusboolfalse
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.
disableEscapeKeyDownboolfalse
If true, hitting escape will not fire the onClose callback.
disablePortalboolfalse
The children will be under the DOM hierarchy of the parent component.
disableRestoreFocusboolfalse
If true, the modal will not restore focus to previously focused element once modal is hidden or unmounted.
disableScrollLockboolfalse
Disable the scroll lock behavior.
hideBackdropboolfalse
If true, the backdrop is not rendered.
keepMountedboolfalse
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.
onClosefunc
Callback fired when the component requests to be closed. The reason parameter can optionally be used to control the response to onClose.

Signature:
function(event: object, reason: string) => void
event: The event source of the callback.
reason: Can be: "escapeKeyDown", "backdropClick", "closeClick".
slotProps{ backdrop?: func
| object, root?: func
| object }
{}
The props used for each slot inside.
slots{ backdrop?: elementType, root?: elementType }{}
The components used for each slot inside. See Slots API below for more details.
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.

The ref is forwarded to the root element.

Slots

To learn how to customize the slot, check out the Overriding component structure guide.

NameDefault classDefault HTML tagDescription
root.MuiModal-root'div'The component that renders the root.
backdrop.MuiModal-backdrop'div'The component that renders the backdrop.

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