Modal
Use Bootstrap’s JavaScript modal plugin to add dialogs to your site for lightboxes, user notifications, or completely custom content.
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 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.
Keep reading for demos and usage guidelines.
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.
Modal title
Modal body text goes here.
div class="modal" tabindex="-1"> div class="modal-dialog"> div class="modal-content"> div class="modal-header"> h5 class="modal-title">Modal titleh5> 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">Closebutton> button type="button" class="btn btn-primary">Save changesbutton> 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.
Modal title
Woohoo, you’re reading this text in a modal!
button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal"> Launch demo modal button> div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true"> div class="modal-dialog"> div class="modal-content"> div class="modal-header"> h5 class="modal-title" id="exampleModalLabel">Modal titleh5> button type="button" class="close" data-dismiss="modal" aria-label="Close"> span aria-hidden="true">×span> button> div> div class="modal-body"> . div> div class="modal-footer"> button type="button" class="btn btn-secondary" data-dismiss="modal">Closebutton> button type="button" class="btn btn-primary">Save changesbutton> 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.
Modal title
I will not close if you click outside me. Don’t even try to press escape key.
button type="button" class="btn btn-primary" data-toggle="modal" data-target="#staticBackdrop"> Launch static backdrop modal button> div class="modal fade" id="staticBackdrop" data-backdrop="static" data-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true"> div class="modal-dialog"> div class="modal-content"> div class="modal-header"> h5 class="modal-title" id="staticBackdropLabel">Modal titleh5> button type="button" class="close" data-dismiss="modal" aria-label="Close"> span aria-hidden="true">×span> button> div> div class="modal-body"> . div> div class="modal-footer"> button type="button" class="btn btn-secondary" data-dismiss="modal">Closebutton> button type="button" class="btn btn-primary">Understoodbutton> div> div> div> div>
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.
Modal title
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.
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.
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.
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.
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.
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?
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.
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.
You can also create a scrollable modal that allows scroll the modal body by adding .modal-dialog-scrollable to .modal-dialog .
Modal title
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.
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?
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.
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.
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.
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.
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.
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.
div class="modal-dialog modal-dialog-scrollable"> . div>