Use Bootstrap’s JavaScript modal plugin to add dialogs to your site for lightboxes, user notifications, or completely custom content.
Bootstrap 4 documentationBefore getting started with Bootstrap’s modal component, be sure to read the following as our menu options have recently changed.
<body>
so that modal content scrolls instead.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.position: fixed
, there are some caveats with using modals on mobile devices. See
our browser support docs for details.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.
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">×</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 -->
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 -->
Add .modal-dialog-centered
to .modal-dialog
to vertically center the modal.
<!-- 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 -->
<!-- Button Modal -->
<button type="button" class="btn btn-block btn-primary" data-toggle="modal" data-target="#modal-form">Sign In</button>
<!-- Modal Content -->
<div class="modal fade" id="modal-form" tabindex="-1" role="dialog" aria-labelledby="modal-form"
aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-sm" role="document">
<div class="modal-content">
<div class="modal-body p-0">
<div class="card bg-soft shadow-md border-0">
<div class="card-header bg-white py-4">
<div class="text-muted text-center mb-3">
<h4>Log-in to your account </h4>
<small>Enter your account details below</small>
</div>
<div class="btn-wrapper text-center">
<a href="#" class="btn btn-sm btn-icon btn-github animate-up-1">
<span class="btn-inner-icon">
<i class="fab fa-github-alt"></i>
</span>
<span class="btn-inner-text">Github</span>
</a>
<a href="#" class="btn btn-sm btn-icon btn-twitter animate-up-1">
<span class="btn-inner-icon">
<i class="fab fa-twitter"></i>
</span>
<span class="btn-inner-text">Twitter</span>
</a>
</div>
</div>
<div class="card-body section-image overlay-dark position-relative" data-background="../../assets/img/sign-in-image.jpg">
<form>
<div class="form-group">
<input type="email" name="login-email" placeholder="Email Address" class="form-control">
</div>
<div class="form-group">
<input type="password" name="login-password" placeholder="Password" class="form-control">
<small class="form-text text-white"><a href="#">Forgot your password?</a>
</small>
</div>
<div class="text-center">
<button type="button" class="btn btn-block btn-white text-dark mt-4">Sign in</button>
</div>
<div class="form-check mb-3">
<label class="form-check-label">
<input class="form-check-input" type="checkbox">
<span class="form-check-sign"></span>
<span class="text-white">Keep me signed in</span>
</label>
</div>
<div class="position-relative mt-4">
<small class="form-text text-white">Don't have an account yet? <a href="#">Create one</a>
</small>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- End of Modal Content -->
<!-- Button Modal -->
<button type="button" class="btn btn-block btn-tertiary" data-toggle="modal" data-target="#modal-form-signup">Sign Up</button>
<!-- Modal Content -->
<div class="modal fade" id="modal-form-signup" tabindex="-1" role="dialog" aria-labelledby="modal-form-signup"
aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-sm" role="document">
<div class="modal-content">
<div class="modal-body p-0">
<div class="card bg-soft shadow-md border-0">
<div class="card-header bg-white py-4">
<div class="text-muted text-center mb-3">
<h4>Sign up for free</h4>
<small>No setup fees. No requirements.</small>
</div>
<div class="btn-wrapper text-center">
<a href="#" class="btn btn-sm btn-icon btn-github animate-up-1">
<span class="btn-inner-icon">
<i class="fab fa-github-alt"></i>
</span>
<span class="btn-inner-text">Github</span>
</a>
<a href="#" class="btn btn-sm btn-icon btn-twitter animate-up-1">
<span class="btn-inner-icon">
<i class="fab fa-twitter"></i>
</span>
<span class="btn-inner-text">Twitter</span>
</a>
</div>
</div>
<div class="card-body section-image overlay-dark position-relative" data-background="../../assets/img/sign-in-image.jpg">
<form>
<div class="form-group">
<div class="input-group mb-4">
<div class="input-group-prepend">
<span class="input-group-text"><i class="far fa-envelope"></i></span>
</div>
<input class="form-control" placeholder="Email" type="text">
</div>
</div>
<div class="form-group">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-unlock-alt"></i></span>
</div>
<input class="form-control" placeholder="Password" type="password">
</div>
<small class="text-white">Must be at least 8 characters</small>
</div>
<div class="form-group">
<div class="input-group">
<input class="form-control" placeholder="Confirm password" type="password">
</div>
</div>
<div class="form-check mb-3">
<label class="form-check-label">
<input class="form-check-input" type="checkbox">
<span class="form-check-sign"></span>
<span class="text-white">I agree to the <a href="#">Terms & Conditions</a></span>
</label>
</div>
<div class="text-center">
<button type="button" class="btn btn-block btn-white text-secondary mt-4">Sign up</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- End of Modal Content -->
<!-- Button Modal -->
<button type="button" class="btn btn-block btn-secondary mb-3" data-toggle="modal" data-target="#modal-achievement">Achievement</button>
<!-- Modal Content -->
<div class="modal fade" id="modal-achievement" tabindex="-1" role="dialog" aria-labelledby="modal-achievement"
aria-hidden="true">
<div class="modal-dialog modal-tertiary modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header mx-auto">
<p class="lead mb-0">You just unlocked a new badge</p>
</div>
<div class="modal-body">
<div class="py-3 text-center">
<span class="modal-icon display-1-lg"><i class="fas fa-medal"></i></span>
<h4 class="modal-title my-2">Author Level 5</h4>
<p>One Thousand Dollars! Well done mate - heads are turning your way.</p>
<div class="progress-wrapper">
<div class="progress">
<div class="progress-bar bg-primary" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-sm btn-white text-tertiary">All badges</button>
<button type="button" class="close ml-auto" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
</div>
</div>
</div>
<!-- End of Modal Content -->
<!-- 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="../../../../assets/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 -->
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.