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
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
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 type of modal does not block any interaction on the page. Simply set nonInvasive
property to true.