Modal
Add dialogs to your site for lightboxes, user notifications, or completely custom content
Before getting started with Bootstrap???s modal component, be sure to read the following as our menu options have recently changed.
- Modals are built with HTML, CSS, and JavaScript. They???re 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 a.modalwithin another fixed element. - Once again, due to
position: fixed, there are some caveats with using modals on mobile devices. See our browser support docs for details. - Due to how HTML5 defines its semantics, the
autofocusHTML attribute has no effect in Bootstrap modals. To achieve the same effect, use some custom JavaScript:
Basic Modal
Above 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.
<div class="modal position-relative d-block" tabindex="-1" role="dialog">
<div class="modal-dialog modal-demo" role="document">
<div class="modal-content modal-content-demo">
<div class="modal-header">
<h6 class="modal-title">Modal Title</h6>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<i class="ti-close font-sm"></i>
</button>
</div>
<div class="modal-body">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus non tortor sit amet magna luctus iaculis. Sed at sollicitudin turpis, vel tempus nibh. </p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-brand btn-sm pr-10 pl-10"> Save changes </button>
</div>
</div>
</div>
</div>
Static backdrop
When backdrop is set to static, the modal will not close when clicking outside it. Click the button below to try it.
<button type="button" class="btn btn-brand btn-sm" data-toggle="modal" data-target="#staticBackdrop">
qLaunch static backdrop modal
</button>
<div class="modal fade" id="staticBackdrop" data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content modal-content-demo">
<div class="modal-header">
<h6 class="modal-title">Modal Title</h6>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<i class="ti-close font-sm"></i>
</button>
</div>
<div class="modal-body">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus non tortor sit amet magna luctus iaculis. Sed at sollicitudin turpis, vel tempus nibh. </p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-brand btn-sm pr-10 pl-10"> Save changes </button>
</div>
</div>
</div>
</div>
Live Demo
Toggle a working modal demo by clicking the button below. It will slide down and fade in from the top of the page.
<button type="button" class="btn btn-brand" data-toggle="modal" data-target="#exampleModal">
Launch demo modal
</button>
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h6 class="modal-title" >Modal title</h6>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<i class="ti-close font-sm"></i>
</button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-light btn-sm" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-brand btn-sm">Save changes</button>
</div>
</div>
</div>
</div>
Vertically centered
Add .modal-dialog-centered to .modal-dialog to vertically center the modal.
<button type="button" class="btn btn-brand btn-sm" data-toggle="modal" data-target="#exampleModalCenter">
Vertically centered
</button>
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h6 class="modal-title" id="exampleModalCenterTitle">Modal title</h6>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<i class="ti-close font-sm"></i>
</button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-light" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-brand">Save changes</button>
</div>
</div>
</div>
</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.
<div class="modal-dialog modal-xl" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" >Modal Title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<i aria-hidden="true" class="ti-close"></i>
</button>
</div>
<div class="modal-body">...</div>
<div class="modal-footer">
<button type="button" class="btn btn-light" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>