Modal
Use Bootstrap's JavaScript modal plugin to add dialogs to your site for lightboxes, user notifications, or completely custom content.
Examples
Modal components
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.
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.
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.
Login modal
<button class="btn btn-primary" data-toggle="modal" data-target="#loginModal">
<i class="now-ui-icons users_single-02"></i>
Login Modal
</button>
<div class="modal fade modal-primary" id="loginModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-login">
<div class="modal-content">
<div class="card card-login card-plain">
<div class="modal-header justify-content-center">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
<i class="now-ui-icons ui-1_simple-remove"></i>
</button>
<div class="header header-primary text-center">
<div class="logo-container">
<img src="../../../assets/img/now-logo.png" alt="">
</div>
</div>
</div>
<div class="modal-body" data-background-color>
<form class="form" method="" action="">
<div class="card-body">
<div class="input-group form-group-no-border input-lg">
<div class="input-group-prepend">
<span class="input-group-text"><i class="now-ui-icons users_circle-08"></i></span>
</div>
<input type="text" class="form-control" placeholder="First Name...">
</div>
<div class="input-group form-group-no-border input-lg">
<div class="input-group-prepend">
<span class="input-group-text"><i class="now-ui-icons ui-1_lock-circle-open"></i></span>
</div>
<input type="text" class="form-control" placeholder="Password...">
</div>
</div>
</form>
</div>
<div class="modal-footer text-center">
<a href="#pablo" class="btn btn-neutral btn-round btn-lg btn-block">Get Started</a>
</div>
</div>
</div>
</div>
</div>
Notice modal
<button class="btn btn-primary" data-toggle="modal" data-target="#noticeModal">
<i class="now-ui-icons travel_info"></i>
Notice
</button>
<div class="modal fade" id="noticeModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-notice">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
<i class="now-ui-icons ui-1_simple-remove"></i>
</button>
<h5 class="modal-title" id="myModalLabel">How Do You Become an Affiliate?</h5>
</div>
<div class="modal-body">
<div class="instruction">
<div class="row">
<div class="col-md-8">
<strong>1. Register</strong>
<p class="description">The first step is to create an account at <a href="http://www.creative-tim.com/">Creative Tim</a>. You can choose a social network or go for the classic version, whatever works best for you.</p>
</div>
<div class="col-md-4">
<div class="picture">
<img src="../../../assets/img/pricing1.jpg" alt="Thumbnail Image" class="rounded img-raised">
</div>
</div>
</div>
</div>
<div class="instruction">
<div class="row">
<div class="col-md-8">
<strong>2. Apply</strong>
<p class="description">The first step is to create an account at <a href="http://www.creative-tim.com/">Creative Tim</a>. You can choose a social network or go for the classic version, whatever works best for you.</p>
</div>
<div class="col-md-4">
<div class="picture">
<img src="../../../assets/img/project9.jpg" alt="Thumbnail Image" class="rounded img-raised">
</div>
</div>
</div>
</div>
<p>If you have more questions, don't hesitate to contact us or send us a tweet @creativetim. We're here to help!</p>
</div>
<div class="modal-footer justify-content-center">
<button type="button" class="btn btn-info btn-round" data-dismiss="modal">Sounds good!</button>
</div>
</div>
</div>
</div>
Tooltips and popovers
Tooltips and popovers can be placed within modals as needed. When modals are closed, any tooltips and popovers within are also automatically dismissed.
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 two 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.
Usage
The modal plugin toggles your hidden content on demand, via data attributes or JavaScript. It also adds .modal-open
to the <body>
to override default scrolling behavior and generates a .modal-backdrop
to provide a click area for dismissing shown modals when clicking outside the modal.
Via data attributes
Activate a modal without writing JavaScript. Set data-toggle="modal"
on a controller element, like a button, along with a data-target="#foo"
or href="#foo"
to target a specific modal to toggle.
Via JavaScript
Call a modal with id myModal
with a single line of JavaScript:
Options
Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-
, as in data-backdrop=""
.
Name | Type | Default | Description |
---|---|---|---|
backdrop | boolean or the string 'static' |
true | Includes a modal-backdrop element. Alternatively, specify static for a backdrop which doesn't close the modal on click. |
keyboard | boolean | true | Closes the modal when escape key is pressed |
focus | boolean | true | Puts the focus on the modal when initialized. |
show | boolean | true | Shows the modal when initialized. |
If you want to see more examples and properties please check the official Bootstrap Documentation