<metaname="description"content="Use Bootstrap’s JavaScript modal plugin to add dialogs to your site for lightboxes, user notifications, or completely custom content.">
<metaname="author"content="Mark Otto, Jacob Thornton, and Bootstrap contributors">
<metaname="twitter:description"content="Use Bootstrap’s JavaScript modal plugin to add dialogs to your site for lightboxes, user notifications, or completely custom content.">
<metaproperty="og:description"content="Use Bootstrap’s JavaScript modal plugin to add dialogs to your site for lightboxes, user notifications, or completely custom content.">
<aclass="btn btn-sm btn-bd-light my-2 my-md-0"href="https://github.com/twbs/bootstrap/blob/v4-dev/site/content/docs/4.6/components/modal.md"title="View and edit this file on GitHub"target="_blank"rel="noopener">View on GitHub</a>
<h1class="bd-title"id="content">Modal</h1>
</div>
<pclass="bd-lead">Use Bootstrap’s JavaScript modal plugin to add dialogs to your site for lightboxes, user notifications, or completely custom content.</p>
<p>Before getting started with Bootstrap’s modal component, be sure to read the following as our menu options have recently changed.</p>
<ul>
<li>Modals are built with HTML, CSS, and JavaScript. They’re positioned over everything else in the document and remove scroll from the <code><body></code> so that modal content scrolls instead.</li>
<li>Clicking on the modal “backdrop” will automatically close the modal.</li>
<li>Bootstrap only supports one modal window at a time. Nested modals aren’t supported as we believe them to be poor user experiences.</li>
<li>Modals use <code>position: fixed</code>, 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 <code>.modal</code> within another fixed element.</li>
<li>Once again, due to <code>position: fixed</code>, there are some caveats with using modals on mobile devices. <ahref="/docs/4.6/getting-started/browsers-devices/#modals-and-dropdowns-on-mobile">See our browser support docs</a> for details.</li>
<li>Due to how HTML5 defines its semantics, <ahref="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-autofocus">the <code>autofocus</code> HTML attribute</a> has no effect in Bootstrap modals. To achieve the same effect, use some custom JavaScript:</li>
The animation effect of this component is dependent on the <code>prefers-reduced-motion</code> media query. See the <ahref="/docs/4.6/getting-started/accessibility/#reduced-motion">reduced motion section of our accessibility documentation</a>.
</div>
<p>Keep reading for demos and usage guidelines.</p>
<h2id="examples">Examples</h2>
<h3id="modal-components">Modal components</h3>
<p>Below is a <em>static</em> modal example (meaning its <code>position</code> and <code>display</code> have been overridden). Included are the modal header, modal body (required for <code>padding</code>), and modal footer (optional). We ask that you include modal headers with dismiss actions whenever possible, or provide another explicit dismiss action.</p>
<spanclass="p"><</span><spanclass="nt">p</span><spanclass="p">></span>Modal body text goes here.<spanclass="p"></</span><spanclass="nt">p</span><spanclass="p">></span>
</code></pre></div><h3id="scrolling-long-content">Scrolling long content</h3>
<p>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.</p>
<p>What follows is just some placeholder text for this modal dialog. Sipping on Rosé, Silver Lake sun, coming up all lazy. It’s in the palm of your hand now baby. So we hit the boulevard. So make a wish, I'll make it like your birthday everyday. Do you ever feel already buried deep six feet under? It's time to bring out the big balloons. You could've been the greatest. Passport stamps, she's cosmopolitan. Your kiss is cosmic, every move is magic.</p>
<p>We're living the life. We're doing it right. Open up your heart. I was tryna hit it and quit it. Her love is like a drug. Always leaves a trail of stardust. The girl's a freak, she drive a jeep in Laguna Beach. Fine, fresh, fierce, we got it on lock. All my girls vintage Chanel baby.</p>
<p>Before you met me I was alright but things were kinda heavy. Peach-pink lips, yeah, everybody stares. This is no big deal. Calling out my name. I could have rewrite your addiction. She's got that, je ne sais quoi, you know it. Heavy is the head that wears the crown. 'Cause, baby, you're a firework. Like thunder gonna shake the ground.</p>
<p>Just own the night like the 4th of July! I’m gon’ put her in a coma. What you're waiting for, it's time for you to show it off. Can't replace you with a million rings. You open my eyes and I'm ready to go, lead me into the light. And here you are. I’m gon’ put her in a coma. Come on, let your colours burst. So cover your eyes, I have a surprise. As I march alone to a different beat. Glitter all over the room pink flamingos in the pool.</p>
<p>You just gotta ignite the light and let it shine! Come just as you are to me. Just own the night like the 4th of July. Infect me with your love and fill me with your poison. Come just as you are to me. End of the rainbow looking treasure.</p>
<p>I can't sleep let's run away and don't ever look back, don't ever look back. I can't sleep let's run away and don't ever look back, don't ever look back. Yes, we make angels cry, raining down on earth from up above. I'm walking on air (tonight). Let you put your hands on me in my skin-tight jeans. Stinging like a bee I earned my stripes. I went from zero, to my own hero. Even brighter than the moon, moon, moon. Make 'em go, 'Aah, aah, aah' as you shoot across the sky-y-y! Why don't you let me stop by?</p>
<p>Boom, boom, boom. Never made me blink one time. Yeah, you're lucky if you're on her plane. Talk about our future like we had a clue. Oh my God no exaggeration. You're original, cannot be replaced. The girl's a freak, she drive a jeep in Laguna Beach. It's no big deal, it's no big deal, it's no big deal. In another life I would make you stay. I'm ma get your heart racing in my skin-tight jeans. I wanna walk on your wave length and be there when you vibrate Never made me blink one time.</p>
<p>We'd keep all our promises be us against the world. If you get the chance you better keep her. It's time to bring out the big, big, big, big, big, big balloons. I hope you got a healthy appetite. Don't let the greatness get you down, oh, oh yeah. Yeah, she's footloose and so fancy free. I want the jaw droppin', eye poppin', head turnin', body shockin'. End of the rainbow looking treasure.</p>
<p>You can also create a scrollable modal that allows scroll the modal body by adding <code>.modal-dialog-scrollable</code> to <code>.modal-dialog</code>.</p>
<p>What follows is just some placeholder text for this modal dialog. You just gotta ignite the light and let it shine! Come just as you are to me. Just own the night like the 4th of July. Infect me with your love and fill me with your poison. Come just as you are to me. End of the rainbow looking treasure.</p>
<p>I can't sleep let's run away and don't ever look back, don't ever look back. I can't sleep let's run away and don't ever look back, don't ever look back. Yes, we make angels cry, raining down on earth from up above. I'm walking on air (tonight). Let you put your hands on me in my skin-tight jeans. Stinging like a bee I earned my stripes. I went from zero, to my own hero. Even brighter than the moon, moon, moon. Make 'em go, 'Aah, aah, aah' as you shoot across the sky-y-y! Why don't you let me stop by?</p>
<p>Boom, boom, boom. Never made me blink one time. Yeah, you're lucky if you're on her plane. Talk about our future like we had a clue. Oh my God no exaggeration. You're original, cannot be replaced. The girl's a freak, she drive a jeep in Laguna Beach. It's no big deal, it's no big deal, it's no big deal. In another life I would make you stay. I'm ma get your heart racing in my skin-tight jeans. I wanna walk on your wave length and be there when you vibrate Never made me blink one time.</p>
<p>We'd keep all our promises be us against the world. In another life I would be your girl. We can dance, until we die, you and I, will be young forever. And on my 18th Birthday we got matching tattoos. So open up your heart and just let it begin. 'Cause she's the muse and the artist. She eats your heart out. Like Jeffrey Dahmer (woo). Pop your confetti. (This is how we do) I know one spark will shock the world, yeah yeah. If you only knew what the future holds.</p>
<p>Sipping on Rosé, Silver Lake sun, coming up all lazy. It’s in the palm of your hand now baby. So we hit the boulevard. So make a wish, I'll make it like your birthday everyday. Do you ever feel already buried deep six feet under? It's time to bring out the big balloons. You could've been the greatest. Passport stamps, she's cosmopolitan. Your kiss is cosmic, every move is magic.</p>
<p>We're living the life. We're doing it right. Open up your heart. I was tryna hit it and quit it. Her love is like a drug. Always leaves a trail of stardust. The girl's a freak, she drive a jeep in Laguna Beach. Fine, fresh, fierce, we got it on lock. All my girls vintage Chanel baby.</p>
<p>Before you met me I was alright but things were kinda heavy. Peach-pink lips, yeah, everybody stares. This is no big deal. Calling out my name. I could have rewrite your addiction. She's got that, je ne sais quoi, you know it. Heavy is the head that wears the crown. 'Cause, baby, you're a firework. Like thunder gonna shake the ground.</p>
<p>Just own the night like the 4th of July! I’m gon’ put her in a coma. What you're waiting for, it's time for you to show it off. Can't replace you with a million rings. You open my eyes and I'm ready to go, lead me into the light. And here you are. I’m gon’ put her in a coma. Come on, let your colours burst. So cover your eyes, I have a surprise. As I march alone to a different beat. Glitter all over the room pink flamingos in the pool.</p>
<p>Placeholder text for this demonstration of a vertically centered modal dialog.</p>
<p>In this case, the dialog has a bit more content, just to show how vertical centering can be added to a scrollable modal.</p>
<p>What follows is just some placeholder text for this modal dialog. Sipping on Rosé, Silver Lake sun, coming up all lazy. It’s in the palm of your hand now baby. So we hit the boulevard. So make a wish, I'll make it like your birthday everyday. Do you ever feel already buried deep six feet under? It's time to bring out the big balloons. You could've been the greatest. Passport stamps, she's cosmopolitan. Your kiss is cosmic, every move is magic.</p>
<p>We're living the life. We're doing it right. Open up your heart. I was tryna hit it and quit it. Her love is like a drug. Always leaves a trail of stardust. The girl's a freak, she drive a jeep in Laguna Beach. Fine, fresh, fierce, we got it on lock. All my girls vintage Chanel baby.</p>
</code></pre></div><h3id="tooltips-and-popovers">Tooltips and popovers</h3>
<p><ahref="/docs/4.6/components/tooltips/">Tooltips</a> and <ahref="/docs/4.6/components/popovers/">popovers</a> can be placed within modals as needed. When modals are closed, any tooltips and popovers within are also automatically dismissed.</p>
<p>This <ahref="#"role="button"class="btn btn-secondary popover-test"title="Popover title"data-content="Popover body content is set in this attribute."data-container="#exampleModalPopovers">button</a> triggers a popover on click.</p>
<hr>
<h5>Tooltips in a modal</h5>
<p><ahref="#"class="tooltip-test"title="Tooltip"data-container="#exampleModalPopovers">This link</a> and <ahref="#"class="tooltip-test"title="Tooltip"data-container="#exampleModalPopovers">that link</a> have tooltips on hover.</p>
<spanclass="p"><</span><spanclass="nt">h5</span><spanclass="p">></span>Popover in a modal<spanclass="p"></</span><spanclass="nt">h5</span><spanclass="p">></span>
<spanclass="p"><</span><spanclass="nt">p</span><spanclass="p">></span>This <spanclass="p"><</span><spanclass="nt">a</span><spanclass="na">href</span><spanclass="o">=</span><spanclass="s">"#"</span><spanclass="na">role</span><spanclass="o">=</span><spanclass="s">"button"</span><spanclass="na">class</span><spanclass="o">=</span><spanclass="s">"btn btn-secondary popover-test"</span><spanclass="na">title</span><spanclass="o">=</span><spanclass="s">"Popover title"</span><spanclass="na">data-content</span><spanclass="o">=</span><spanclass="s">"Popover body content is set in this attribute."</span><spanclass="p">></span>button<spanclass="p"></</span><spanclass="nt">a</span><spanclass="p">></span> triggers a popover on click.<spanclass="p"></</span><spanclass="nt">p</span><spanclass="p">></span>
<spanclass="p"><</span><spanclass="nt">h5</span><spanclass="p">></span>Tooltips in a modal<spanclass="p"></</span><spanclass="nt">h5</span><spanclass="p">></span>
<spanclass="p"><</span><spanclass="nt">p</span><spanclass="p">><</span><spanclass="nt">a</span><spanclass="na">href</span><spanclass="o">=</span><spanclass="s">"#"</span><spanclass="na">class</span><spanclass="o">=</span><spanclass="s">"tooltip-test"</span><spanclass="na">title</span><spanclass="o">=</span><spanclass="s">"Tooltip"</span><spanclass="p">></span>This link<spanclass="p"></</span><spanclass="nt">a</span><spanclass="p">></span> and <spanclass="p"><</span><spanclass="nt">a</span><spanclass="na">href</span><spanclass="o">=</span><spanclass="s">"#"</span><spanclass="na">class</span><spanclass="o">=</span><spanclass="s">"tooltip-test"</span><spanclass="na">title</span><spanclass="o">=</span><spanclass="s">"Tooltip"</span><spanclass="p">></span>that link<spanclass="p"></</span><spanclass="nt">a</span><spanclass="p">></span> have tooltips on hover.<spanclass="p"></</span><spanclass="nt">p</span><spanclass="p">></span>
</code></pre></div><h3id="using-the-grid">Using the grid</h3>
<p>Utilize the Bootstrap grid system within a modal by nesting <code>.container-fluid</code> within the <code>.modal-body</code>. Then, use the normal grid system classes as you would anywhere else.</p>
<p>Have a bunch of buttons that all trigger the same modal with slightly different contents? Use <code>event.relatedTarget</code> and <ahref="https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes">HTML <code>data-*</code> attributes</a> (possibly <ahref="https://api.jquery.com/data/">via jQuery</a>) to vary the contents of the modal depending on which button was clicked.</p>
<p>Below is a live demo followed by example HTML and JavaScript. For more information, <ahref="#events">read the modal events docs</a> for details on <code>relatedTarget</code>.</p>
<divclass="bd-example">
<buttontype="button"class="btn btn-primary"data-toggle="modal"data-target="#exampleModal"data-whatever="@mdo">Open modal for @mdo</button>
<buttontype="button"class="btn btn-primary"data-toggle="modal"data-target="#exampleModal"data-whatever="@fat">Open modal for @fat</button>
<buttontype="button"class="btn btn-primary"data-toggle="modal"data-target="#exampleModal"data-whatever="@getbootstrap">Open modal for @getbootstrap</button>
</div><divclass="highlight"><preclass="chroma"><codeclass="language-html"data-lang="html"><spanclass="p"><</span><spanclass="nt">button</span><spanclass="na">type</span><spanclass="o">=</span><spanclass="s">"button"</span><spanclass="na">class</span><spanclass="o">=</span><spanclass="s">"btn btn-primary"</span><spanclass="na">data-toggle</span><spanclass="o">=</span><spanclass="s">"modal"</span><spanclass="na">data-target</span><spanclass="o">=</span><spanclass="s">"#exampleModal"</span><spanclass="na">data-whatever</span><spanclass="o">=</span><spanclass="s">"@mdo"</span><spanclass="p">></span>Open modal for @mdo<spanclass="p"></</span><spanclass="nt">button</span><spanclass="p">></span>
<spanclass="p"><</span><spanclass="nt">button</span><spanclass="na">type</span><spanclass="o">=</span><spanclass="s">"button"</span><spanclass="na">class</span><spanclass="o">=</span><spanclass="s">"btn btn-primary"</span><spanclass="na">data-toggle</span><spanclass="o">=</span><spanclass="s">"modal"</span><spanclass="na">data-target</span><spanclass="o">=</span><spanclass="s">"#exampleModal"</span><spanclass="na">data-whatever</span><spanclass="o">=</span><spanclass="s">"@fat"</span><spanclass="p">></span>Open modal for @fat<spanclass="p"></</span><spanclass="nt">button</span><spanclass="p">></span>
<spanclass="p"><</span><spanclass="nt">button</span><spanclass="na">type</span><spanclass="o">=</span><spanclass="s">"button"</span><spanclass="na">class</span><spanclass="o">=</span><spanclass="s">"btn btn-primary"</span><spanclass="na">data-toggle</span><spanclass="o">=</span><spanclass="s">"modal"</span><spanclass="na">data-target</span><spanclass="o">=</span><spanclass="s">"#exampleModal"</span><spanclass="na">data-whatever</span><spanclass="o">=</span><spanclass="s">"@getbootstrap"</span><spanclass="p">></span>Open modal for @getbootstrap<spanclass="p"></</span><spanclass="nt">button</span><spanclass="p">></span>
<spanclass="kd">var</span><spanclass="nx">button</span><spanclass="o">=</span><spanclass="nx">$</span><spanclass="p">(</span><spanclass="nx">event</span><spanclass="p">.</span><spanclass="nx">relatedTarget</span><spanclass="p">)</span><spanclass="c1">// Button that triggered the modal
</span><spanclass="c1"></span><spanclass="kd">var</span><spanclass="nx">recipient</span><spanclass="o">=</span><spanclass="nx">button</span><spanclass="p">.</span><spanclass="nx">data</span><spanclass="p">(</span><spanclass="s1">'whatever'</span><spanclass="p">)</span><spanclass="c1">// Extract info from data-* attributes
</span><spanclass="c1"></span><spanclass="c1">// If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
</span><spanclass="c1"></span><spanclass="c1">// Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
<spanclass="nx">modal</span><spanclass="p">.</span><spanclass="nx">find</span><spanclass="p">(</span><spanclass="s1">'.modal-title'</span><spanclass="p">).</span><spanclass="nx">text</span><spanclass="p">(</span><spanclass="s1">'New message to '</span><spanclass="o">+</span><spanclass="nx">recipient</span><spanclass="p">)</span>
<p>The <code>$modal-fade-transform</code> variable determines the transform state of <code>.modal-dialog</code> before the modal fade-in animation, the <code>$modal-show-transform</code> variable determines the transform of <code>.modal-dialog</code> at the end of the modal fade-in animation.</p>
<p>If you want for example a zoom-in animation, you can set <code>$modal-fade-transform: scale(.8)</code>.</p>
<h3id="remove-animation">Remove animation</h3>
<p>For modals that simply appear rather than fade in to view, remove the <code>.fade</code> class from your modal markup.</p>
<p>If the height of a modal changes while it is open, you should call <code>$('#myModal').modal('handleUpdate')</code> to readjust the modal’s position in case a scrollbar appears.</p>
<h3id="accessibility">Accessibility</h3>
<p>Be sure to add <code>aria-labelledby="..."</code>, referencing the modal title, to <code>.modal</code>. Additionally, you may give a description of your modal dialog with <code>aria-describedby</code> on <code>.modal</code>. Note that you don’t need to add <code>role="dialog"</code> since we already add it via JavaScript.</p>
<p>Embedding YouTube videos in modals requires additional JavaScript not in Bootstrap to automatically stop playback and more. <ahref="https://stackoverflow.com/questions/18622508/bootstrap-3-and-youtube-in-modal">See this helpful Stack Overflow post</a> for more information.</p>
<h2id="optional-sizes">Optional sizes</h2>
<p>Modals have three optional sizes, available via modifier classes to be placed on a <code>.modal-dialog</code>. These sizes kick in at certain breakpoints to avoid horizontal scrollbars on narrower viewports.</p>
<tableclass="table table-bordered table-striped">
<thead>
<tr>
<th>Size</th>
<th>Class</th>
<th>Modal max-width</th>
</tr>
</thead>
<tbody>
<tr>
<td>Small</td>
<td><code>.modal-sm</code></td>
<td><code>300px</code></td>
</tr>
<tr>
<td>Default</td>
<tdclass="text-muted">None</td>
<td><code>500px</code></td>
</tr>
<tr>
<td>Large</td>
<td><code>.modal-lg</code></td>
<td><code>800px</code></td>
</tr>
<tr>
<td>Extra large</td>
<td><code>.modal-xl</code></td>
<td><code>1140px</code></td>
</tr>
</tbody>
</table>
<p>Our default modal without modifier class constitutes the “medium” size modal.</p>
<divclass="bd-example">
<buttontype="button"class="btn btn-primary"data-toggle="modal"data-target="#exampleModalXl">Extra large modal</button>
<p>The modal plugin toggles your hidden content on demand, via data attributes or JavaScript. It also adds <code>.modal-open</code> to the <code><body></code> to override default scrolling behavior and generates a <code>.modal-backdrop</code> to provide a click area for dismissing shown modals when clicking outside the modal.</p>
<h3id="via-data-attributes">Via data attributes</h3>
<p>Activate a modal without writing JavaScript. Set <code>data-toggle="modal"</code> on a controller element, like a button, along with a <code>data-target="#foo"</code> or <code>href="#foo"</code> to target a specific modal to toggle.</p>
<p>Options can be passed via data attributes or JavaScript. For data attributes, append the option name to <code>data-</code>, as in <code>data-backdrop=""</code>.</p>
<tableclass="table table-bordered table-striped">
<thead>
<tr>
<thstyle="width: 100px;">Name</th>
<thstyle="width: 50px;">Type</th>
<thstyle="width: 50px;">Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>backdrop</td>
<td>boolean or the string <code>'static'</code></td>
<td>true</td>
<td>Includes a modal-backdrop element. Alternatively, specify <code>static</code> for a backdrop which doesn't close the modal on click.</td>
</tr>
<tr>
<td>keyboard</td>
<td>boolean</td>
<td>true</td>
<td>Closes the modal when escape key is pressed</td>
</tr>
<tr>
<td>focus</td>
<td>boolean</td>
<td>true</td>
<td>Puts the focus on the modal when initialized.</td>
</tr>
<tr>
<td>show</td>
<td>boolean</td>
<td>true</td>
<td>Shows the modal when initialized.</td>
</tr>
</tbody>
</table>
<h3id="methods">Methods</h3>
<divclass="bd-callout bd-callout-danger">
<h4id="asynchronous-methods-and-transitions">Asynchronous methods and transitions</h4>
<p>All API methods are <strong>asynchronous</strong> and start a <strong>transition</strong>. They return to the caller as soon as the transition is started but <strong>before it ends</strong>. In addition, a method call on a <strong>transitioning component will be ignored</strong>.</p>
<p><ahref="/docs/4.6/getting-started/javascript/#asynchronous-functions-and-transitions">See our JavaScript documentation for more information</a>.</p>
<p>Manually toggles a modal. <strong>Returns to the caller before the modal has actually been shown or hidden</strong> (i.e. before the <code>shown.bs.modal</code> or <code>hidden.bs.modal</code> event occurs).</p>
<p>Manually opens a modal. <strong>Returns to the caller before the modal has actually been shown</strong> (i.e. before the <code>shown.bs.modal</code> event occurs).</p>
<p>Manually hides a modal. <strong>Returns to the caller before the modal has actually been hidden</strong> (i.e. before the <code>hidden.bs.modal</code> event occurs).</p>
<p>Bootstrap’s modal class exposes a few events for hooking into modal functionality. All modal events are fired at the modal itself (i.e. at the <code><div class="modal"></code>).</p>
<tableclass="table table-bordered table-striped">
<thead>
<tr>
<thstyle="width: 150px;">Event Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>show.bs.modal</td>
<td>This event fires immediately when the <code>show</code> instance method is called. If caused by a click, the clicked element is available as the <code>relatedTarget</code> property of the event.</td>
</tr>
<tr>
<td>shown.bs.modal</td>
<td>This event is fired when the modal has been made visible to the user (will wait for CSS transitions to complete). If caused by a click, the clicked element is available as the <code>relatedTarget</code> property of the event.</td>
</tr>
<tr>
<td>hide.bs.modal</td>
<td>This event is fired immediately when the <code>hide</code> instance method has been called.</td>
</tr>
<tr>
<td>hidden.bs.modal</td>
<td>This event is fired when the modal has finished being hidden from the user (will wait for CSS transitions to complete).</td>
</tr>
<tr>
<td>hidePrevented.bs.modal</td>
<td>This event is fired when the modal is shown, its backdrop is <code>static</code> and a click outside the modal or an escape key press is performed with the keyboard option or <code>data-keyboard</code> set to <code>false</code>.</td>