Modal
React Bootstrap 5 Modal component
Use MDB modal plugin to add dialogs to your site for lightboxes, user notifications, or completely custom content.
Note: Read the API tab to find all available options and advanced customization
Basic example
Click the button to launch the modal.
Advanced examples
Click the buttons to launch the modals.
Frame modal

Position
Side modal

Position
Central modal

Size
How it works
Before getting started with MDB modal component, be sure to read the following as our menu options have recently changed.
-
Modals are positioned over everything else in the document and remove scroll from the
<body>
so that modal content scrolls instead. - Clicking on the modal “backdrop” will automatically close the modal.
- Bootstrap only supports one modal window at a time. Nested modals aren’t supported as we believe them to be poor user experiences.
-
Modals use
position: fixed
, which can sometimes be a bit particular about its rendering. Whenever possible, place your modal HTML in a top-level position to avoid potential interference from other elements. You’ll likely run into issues when nesting aMDBModal
within another fixed element. -
Once again, due to
position: fixed
, there are some caveats with using modals on mobile devices. -
Due to how HTML5 defines its semantics,
the
autofocus
HTML attribute has no effect in Bootstrap modals. To achieve the same effect, use some custom JavaScript:
Modal components
Below is a static modal example (meaning its position
and
display
have been overridden). Included are the modal header, modal body
(required for padding
), and modal footer (optional). We ask that you include
modal headers with dismiss actions whenever possible, or provide another explicit dismiss
action.
Position
This component requires MDB Pro package.
Learn more
To change the position of the modal add one of the following props to the MDBModalDialog
Top right:
side
+ position="top-right"
Top left:
side
+ position="top-left"
Bottom right:
side
+ position="bottom-right"
Bottom left:
side
+ position="bottom-left"
Note: If you want to change the direction of modal animation, add the prop{' '}
animationDirection
, top
, bottom
or left
to the{' '}
Modal
component.
Frame
This component requires MDB Pro package.
Learn more
To make the modal "frame-like" add frame
prop to the
MDBModalDialog
element. You also need to specify the direction by adding
position="bottom"
or position="top"
to the MDBModalDialog
.
Static backdrop
When backdrop is set to static, the modal will not close when clicking outside it. Click the button below to try it.
Scrolling long content
When modals become too long for the user’s viewport or device, they scroll independent of the page itself. Try the demo below to see what we mean.
You can also create a scrollable modal that allows scroll the modal body by adding
scrollable
to MDBModalDialog
.
Vertically centered
Add centered
to MDBModalDialog
to vertically center the modal.
Tooltips and popovers
Tooltips and popovers can be placed within modals as needed. When modals are closed, any tooltips and popovers within are also automatically dismissed.
Using the grid
Utilize the Bootstrap grid system within a modal by nesting
.container-fluid
within the .modal-body
. Then, use the normal grid
system classes as you would anywhere else.
Varying modal content
Have a bunch of buttons that all trigger the same modal with slightly different contents? Use
event.relatedTarget
and
HTML data-mdb-*
attributes
to vary the contents of the modal depending on which button was clicked.
Below is a live demo followed by example HTML and JavaScript. For more information, read the
modal API/events doc for details on relatedTarget
.
Toggle between modals
Toggle between multiple modals with some clever placement of the
data-mdb-target
and data-mdb-toggle
attributes. For example, you
could toggle a password reset modal from within an already open sign in modal.
Please note multiple modals cannot be open at the same time—this method
simply toggles between two separate modals.
Below is a live demo followed by example HTML and JavaScript. For more information, read the
modal API/events doc for details on relatedTarget
.
Accessibility
Be sure to add aria-labelledby="..."
, referencing the modal title, to
MDBModal
. Additionally, you may give a description of your modal dialog with
aria-describedby
on MDBModal
.
Embedding YouTube videos
Embedding YouTube videos in modals requires additional JavaScript not in Bootstrap to automatically stop playback and more. See this helpful Stack Overflow post for more information.
Optional sizes
Modals have three optional sizes, available via modifier props to be placed on a MDBModalDialog
.
These sizes kick in at certain breakpoints to avoid horizontal scrollbars on narrower viewports.
Size | Prop | Modal max-width |
---|---|---|
Small | size="sm" |
300px |
Default | None | 500px |
Large | size="lg" |
800px |
Extra large | size="xl" |
1140px |
Fullscreen Modal
Another override is the option to pop up a modal that covers the user viewport, available via
modifier props that are placed on a MDBModalDialog
.
Prop | Availability |
---|---|
size="fullscreen" |
Always |
size="fullscreen-sm-down" |
Below 576px |
size="fullscreen-md-down" |
Below 768px |
size="fullscreen-lg-down" |
Below 992px |
size="fullscreen-xl-down" |
Below 1200px |
size="fullscreen-xxl-down" |
Below 1400px |
Non-invasive Modal
This component requires MDB Pro package.
Learn more
This type of modal does not block any interaction on the page. Simply set nonInvasive
property to true.
Modal - API
Import
Properties
MDBModal
Name | Type | Default | Description | Example |
---|---|---|---|---|
animationDirection
|
String | '' |
Defines animation direction of the modal |
<MDBModal animationDirection="top" />
|
appendToBody
|
Boolean | false |
Appends element to the end of the body |
<MDBModal appendToBody />
|
backdrop
|
Boolean | true |
Sets a backrop for modal |
<MDBModal backdrop={false} />
|
closeOnEsc
|
Boolean | true |
Allows to close modal on Escape keydown |
<MDBModal closeOnEsc={false} />
|
leaveHiddenModal
|
Boolean | true |
Defines whether the hidden modal stays in VDOM |
<MDBModal leaveHiddenModal={false} />
|
modalRef
|
Reference | '' |
Reference to the modal element |
<MDBModal modalRef={modalReference} />
|
nonInvasive
|
Boolean | false |
Changes the type of modal to Non-Invasive modal |
<MDBModal nonInvasive={true} />
|
setOpen
|
React.SetStateAction | '' |
Allows to pass the setState action to the Modal component which defines if modal is opened or not |
<MDBModal setOpen={setExample} />
|
open
|
Boolean | false |
Sets visibility of the modal |
<MDBModal open={true} />
|
staticBackdrop
|
Boolean | false |
Creates static backdrop for the modal |
<MDBModal staticBackdrop />
|
tag
|
String | 'div' |
Defines tag of the MDBModal element |
<MDBModal tag="section" />
|
MDBModalDialog
Name | Type | Default | Description | Example |
---|---|---|---|---|
centered
|
Boolean | false |
Vertically centeres modal dialog window |
<MDBModalDialog centered />
|
scrollable
|
Boolean | false |
Allows to scroll through long contents with a scrollbar |
<MDBModalDialog scrollable />
|
size
|
String | '' |
Defines the size of MDBModal component. |
<MDBModalDialog size="lg" />
|
tag
|
String | 'div' |
Defines tag of the MDBModalDialog element |
<MDBModalDialog tag="section" />
|
MDBModalContent
Name | Type | Default | Description | Example |
---|---|---|---|---|
tag
|
String | 'div' |
Defines tag of the MDBModalContent element |
<MDBModalContent tag="section" />
|
MDBModalHeader
Name | Type | Default | Description | Example |
---|---|---|---|---|
tag
|
String | 'div' |
Defines tag of the MDBModalHeader element |
<MDBModalHeader tag="section" />
|
MDBModalTitle
Name | Type | Default | Description | Example |
---|---|---|---|---|
tag
|
String | 'h5' |
Defines tag of the MDBModalTitle element |
<MDBModalTitle tag="h3" />
|
MDBModalBody
Name | Type | Default | Description | Example |
---|---|---|---|---|
tag
|
String | 'div' |
Defines tag of the MDBModalBody element |
<MDBModalBody tag="section" />
|
Events
Name | Type | Description |
---|---|---|
onClose
|
() => any | Fired when the modal demands to be closed. |
onClosePrevented
|
() => any | This event is fired when the modal is shown, its backdrop is static and a click outside the modal or an escape key press is performed with the keyboard option. |
onOpen
|
() => any | Fires when the modal demands to be opened. |
CSS variables
As part of MDB’s evolving CSS variables approach, modal now use local CSS variables on .modal
for
enhanced real-time customization. Values for the CSS variables are set via Sass, so Sass customization is still
supported, too.
Modal's CSS variables are in different classes which belong to this component. To make it easier to use them, you can find below all of the used CSS variables.