Modal
Example
<div class="modal"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">Modal title</h5> <button class="btn-close" data-bs-dismiss="modal"></button> </div> <div class="modal-body"> <p>Modal body text goes here.</p> </div> <div class="modal-footer"> <button class="btn btn-secondary" data-bs-dismiss="modal">Close</button> <button class="btn btn-primary">Save changes</button> </div> </div> </div> </div>
Live demo
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal1"> Launch demo modal </button> <div class="modal" id="exampleModal1"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">Modal title</h5> <button class="btn-close" data-bs-dismiss="modal"></button> </div> <div class="modal-body"> ... </div> <div class="modal-footer"> <button class="btn btn-secondary" data-bs-dismiss="modal">Close</button> <button class="btn btn-primary">Save changes</button> </div> </div> </div> </div>
Static backdrop
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#staticBackdrop"> Launch static backdrop modal </button> <div class="modal fade" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">Modal title</h5> <button class="btn-close" data-bs-dismiss="modal"></button> </div> <div class="modal-body"> ... </div> <div class="modal-footer"> <button class="btn btn-secondary" data-bs-dismiss="modal">Close</button> <button class="btn btn-primary">Save changes</button> </div> </div> </div> </div>
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 .modal-dialog-scrollable to .modal-dialog.
<div class="modal-dialog modal-dialog-scrollable">
...
</div>
Vertically centered
Add .modal-dialog-centered to .modal-dialog to vertically center the modal.
<div class="modal-dialog modal-dialog-centered">
...
</div>
Add animation
For modals that fade in rather than simply appearing in to view, add the .fade class to your modal markup.
<div class="modal fade">
...
</div>
Optional sizes
Modals have three optional sizes, available via modifier classes to be placed on a .modal-dialog. These sizes kick in at certain breakpoints to avoid horizontal scrollbars on narrower viewports.
Size | Class | Modal max-width |
---|---|---|
Small | .modal-sm | 300px |
Default | None | 500px |
Large | .modal-lg | 800px |
Extra large | .modal-xl | 1140px |
Our default modal without modifier class constitutes the “medium” size modal.
<div class="modal-dialog modal-sm>...</div> <div class="modal-dialog modal-lg>...</div> <div class="modal-dialog modal-xl>...</div>
Full screen modal
Another override is the option to pop up a modal that covers the user viewport, available via modifier classes that are placed on a .modal-dialog.
Class | Availability |
---|---|
.modal-fullscreen | Always |
.modal-fullscreen-sm-down | Below 576px |
.modal-fullscreen-md-down | Below 768px |
.modal-fullscreen-lg-down | Below 992px |
.modal-fullscreen-xl-down | Below 1200px |
.modal-fullscreen-xxl-down | Below 1400px |
<div class="modal-dialog modal-fullscreen>...</div> <div class="modal-dialog modal-fullscreen-sm-down>...</div> <div class="modal-dialog modal-fullscreen-md-down>...</div> <div class="modal-dialog modal-fullscreen-lg-down>...</div> <div class="modal-dialog modal-fullscreen-xl-down>...</div> <div class="modal-dialog modal-fullscreen-xxl-down>...</div>