Modal
Vue 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 MDBModal
example (meaning its
position
and display
have been overridden). Included are the
MDBModalHeader
, MDBModalBody
(required for padding
),
and MDBModalFooter
(optional). MDBModalHeader
is by default included
with dismiss action button. You can also provide another explicit dismiss action, e.g. inside
MDBModalFooter
component.
Position
To change the position of the modal add one of the following properties to the
MDBModal
Top right: side
+
position="top-right"
Top left: side
+
position="top-left"
Bottom right: side
+
position="bottom-right"
Bottom left: side
+
position="bottom-right"
Note: If you want to change the direction of modal animation, add
position="top | right | bottom | left"
property to the MDBModal
.
Frame
To make the modal "frame-like" add frame
property to the
MDBModal
element. You also need to specify the position
property
with bottom
or top
values.
Static backdrop
When staticBackdrop
property is added to MDBModal
, 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
property to MDBModal
.
Vertically centered
Add centered
to MDBModal
to vertically center the modal.
Tooltips and popovers
Tooltips and
popovers can be placed within modals as
needed. You can add function on hide
event to manually close any opened popover
or tooltip when closing modal.
Using the grid
Utilize the Bootstrap grid system within a modal by nesting
MDBContainer fluid{
within the MDBModalBody{
. Then, use the normal
grid system properties/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
Vue
refs
to vary the contents of the modal depending on which button was clicked.
Below is a live demo followed by example Vue template and script.
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
.
Change animation
The $modal-fade-transform
variable determines the transform state of
modal dialog
content before the modal fade-in animation, the
$modal-show-transform
variable determines the transform of
.modal-dialog
at the end of the modal fade-in animation.
If you want for example a zoom-in animation, you can set
$modal-fade-transform: scale(.8)
.
Remove animation
For modals that simply appear rather than fade in to view, add the
:animation="false"
property to your modal markup.
Accessibility
Be sure to add labelledby="..."
>, referencing the modal title, to
MDBModal
>. Additionally, you may give a description of your modal dialog with
aria-describedby
> on MDBModal
>. Note that you don’t need to add
role="dialog"
> since we already add it inside component.
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 properties to be placed on a
MDBModal
. These sizes kick in at certain breakpoints to avoid horizontal
scrollbars on narrower viewports.
Size | Property | 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
fullscreen
properties that are placed on a MDBModal
.
Class | Availability |
---|---|
fullscreen |
Always |
fullscreen="sm-down" |
Below 576px |
fullscreen="md-down" |
Below 768px |
fullscreen="lg-down" |
Below 992px |
fullscreen="xl-down" |
Below 1200px |
fullscreen="xxl-down" |
Below 1400px |
Non-Invasive Modal
This type of modal does not block any interaction on the page.
Simply add property nonInvasive
to MDBModal
.
Modal - API
Import
Properties
Modal
Name | Type | Default | Description | Example |
---|---|---|---|---|
animation
|
Boolean | true |
Turn modal animation on or off |
<MDBModal :animation="false" />
|
bgSrc
|
String | -- |
Dark style necessitate having a picture background, but the feature is for all the modals, really |
<MDBModal bgSrc="/image/src" />
|
centered
|
Boolean | false |
Center modal vertically and horizonally |
<MDBModal centered />
|
duration
|
Number | 400 |
Sets animation duration in miliseconds |
<MDBModal :duration="500" />
|
focus
|
Boolean | true |
Puts the focus on the modal when initialized. |
<MDBModal :focus="false" />
|
fullscreen
|
Number | 400 |
Makes the modal cover user viewport on a specific breakpoint |
<MDBModal :fullscreen="lg-down" />
|
keyboard
|
Boolean | true |
Closes the modal when escape key is pressed |
<MDBModal :keyboard="false" />
|
labelledby
|
String | -- |
When having modal content with the title add labelledby to make modal
more accessible
|
<MDBModal labelledby="modalExampleTitle">
<MDBModalHeader>
<MDBModalTitle tag="h4" id="modalExampleTitle">
Modal title
</MDBModalTitle>
</MDBModalHeader>
</MDBModal>
|
nonInvasive
|
Boolean | false |
Removes the dark overlay from the background, allows to scroll through page and allows to open another modal while non-invasive modal is open. |
<MDBModal nonInvasive />
|
removeBackdrop
|
Boolean | false |
Removes the dark overlay from the background, along its functionality |
<MDBModal removeBackdrop />
|
scrollable
|
Boolean | false |
Allows to scroll through long contents with a scrollbar |
<MDBModal scrollable />
|
size
|
String | -- |
Sets size of MDBModal component. Use "sm | lg | xl" values |
<MDBModal size="sm" /> |
staticBackdrop
|
Boolean | false |
Will prevent modal close when clicking outside the backdrop |
<MDBModal staticBackdrop />
|
tag
|
String | 'div' |
Defines tag of the MDBModal element |
<MDBModal tag="span" />
|
v-model
|
String | false |
Opens / closes modal component |
<MDBModal v-model="true" />
|
Modal Header
Name | Type | Default | Description | Example |
---|---|---|---|---|
tag
|
String | 'div' |
Defines tag of the MDBModalHeader element |
<MDBModalHeader tag="header" />
|
close
|
Boolean | true |
Turning it to false removes the close "x" icon in the right top corner |
<MDBModalHeader :close="false" />
|
closeWhite
|
Boolean | false |
Makes the closing "x" sign works better with dark variant of the modal |
<MDBModalHeader :closeWhite />
|
color
|
String | -- |
Determines color of the header |
<MDBModalHeader color="secondary" />
|
Modal Title
Name | Type | Default | Description | Example |
---|---|---|---|---|
tag
|
String | 'h5' |
Defines tag of the MDBModalTitle element |
<MDBModalTitle tag="h6" />
|
bold
|
Boolean | false |
Makes title font bold |
<MDBModalTitle bold />
|
Events
Bootstrap’s modal class exposes a few events for hooking into modal functionality. All modal
events are fired at the modal itself (i.e. at the
<div class="modal">
).
Event type | Description |
---|---|
show |
This event fires immediately when the modal has been called to show. |
shown |
This event is fired when the modal has been made visible to the user (will wait for CSS transitions to complete). |
hide |
This event is fired immediately when the modal has been called to hide. |
hidden |
This event is fired when the modal has finished being hidden from the user (will wait for CSS transitions to complete). |
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.