Modal

Use Bootstrap’s JavaScript modal plugin to add dialogs to your site for lightboxes, user notifications, or completely custom content.

Bootstrap 4 documentation
How it works

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 .modal within 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 autofocus HTML attribute has no effect in Bootstrap modals. To achieve the same effect, use some custom JavaScript:
                                        
$('#myModal').on('shown.bs.modal', function () {
    $('#myInput').trigger('focus');
})
                                        
                                    

The animation effect of this component is dependent on the prefers-reduced-motion media query. See the reduced motion section of our accessibility documentation.

Examples

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.

                                                        
<!-- Modal -->
<div class="modal static-example" tabindex="-1" role="dialog">
    <div class="modal-dialog" 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">
            <span aria-hidden="true">&times;</span>
            </button>
        </div>
        <div class="modal-body">
            <p>Modal body text goes here.</p>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
            <button type="button" class="btn btn-primary">Save changes</button>
        </div>
        </div>
    </div>
</div>
<!-- End of modal -->
                                                        
                                                    
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 Modal -->
<button type="button" class="btn btn-block btn-secondary mb-3" data-toggle="modal" data-target="#modal-default">Default</button>
<!-- Modal Content -->
<div class="modal fade" id="modal-default" tabindex="-1" role="dialog" aria-labelledby="modal-default"
    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="modal-title-default">Terms of Service</h6> 
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
            <div class="modal-body">
                <p>With less than a month to go before the European Union enacts new consumer privacy laws for its citizens, companies around the world are updating their terms of service agreements to comply.</p>
                <p>The European Union’s General Data Protection Regulation (G.D.P.R.) goes into effect on May 25 and is meant to ensure a common set of data rights in the European Union. It requires organizations to notify users as soon as possible of high-risk data breaches that could personally affect them.</p>  
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-sm btn-secondary">I Got It</button>
            </div>
        </div>
    </div>
</div>
<!-- End of Modal Content -->
                                                        
                                                    

Vertically centered

Add .modal-dialog-centered to .modal-dialog to vertically center the modal.

Notification
                                                        
<!-- Button Modal -->
<button type="button" class="btn btn-block btn-secondary mb-3" data-toggle="modal" data-target="#modal-notification">Notification</button>
<!-- Modal Content -->
<div class="modal fade" id="modal-notification" tabindex="-1" role="dialog" aria-labelledby="modal-notification"
    aria-hidden="true">
    <div class="modal-dialog modal-info modal-dialog-centered" role="document">
        <div class="modal-content bg-gradient-secondary">
            <div class="modal-header">
                <p class="modal-title" id="modal-title-notification">A new experience, personalized for you.</p>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
            <div class="modal-body">
                <div class="py-3 text-center">
                    <span class="modal-icon display-1-lg"><i class="far fa-envelope-open"></i></span>
                    <h4 class="modal-title my-3">Important message!</h4>
                    <p>Do you know that you can assign status and relation to a company right in the visit list?.</p>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-sm btn-white">Go to Inbox</button>
            </div>
        </div>
    </div>
</div>
<!-- End of Modal Content -->
                                                        
                                                    
Subscribe
                                                        
<!-- Button Modal -->
<button type="button" class="btn btn-block btn-secondary mb-3" data-toggle="modal" data-target="#modal-subscribe">Subscribe</button>
<!-- Modal Content -->
<div class="modal fade" id="modal-subscribe" tabindex="-1" role="dialog" aria-labelledby="modal-subscribe"
    aria-hidden="true">
    <div class="modal-dialog modal-tertiary modal-dialog-centered modal-lg" role="document">
        <div class="modal-content section-image overlay-dark" data-background="../../../../img/blog/image-4.jpg">
            <div class="modal-header">
                <button type="button" class="close ml-auto" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
            <div class="modal-body">
                <div class="py-3 text-center">
                    <span class="modal-icon display-1-lg"><i class="fas fa-envelope-open-text"></i></span>
                    <h4 class="modal-title my-2">Join our 1,360,462 subscribers</h4>
                    <p>Get exclusive access to freebies, premium products and news.</p>
                    <div class="form-group">
                        <div class="d-sm-flex flex-column flex-sm-row mb-3 justify-content-center">
                            <input type="text" placeholder="Enter your email adress here" class="mr-sm-1 mb-2 mb-sm-0 form-control form-control-lg">
                            <button type="submit" class="ml-sm-1 btn btn-secondary">Subscribe</button>
                        </div>
                        
                    </div>
                </div>
            </div>
            <div class="modal-footer z-2 mx-auto text-center">
                <p class="text-white">
                    We’ll never share your details with third parties.
                    <br class="visible-md">View our <a href="#">Privacy Policy</a> for more info.
                </p>
            </div>
        </div>
    </div>
</div>
<!-- End of Modal Content -->
                                                        
                                                    
Usage

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.

For more information, see the official Bootstrap documentation.