Bootstrap5 Modal
A modal is a child window overlaid on the parent window. Typically, its purpose is to display content from a separate source, allowing some interaction without leaving the parent window. A child window can provide information, interaction, etc.
How to Create a Modal
The following example creates a simple modal effect:
Example
<button type="button" class=">btn btn-primary
"
data-bs-toggle
=
"
modal
"
data-bs-target
=
"
#myModal
"
Open Modal
button
<div class="modal" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Modal title
h4
<button type="button" class="btn-close" data-bs-dismiss="modal" button div>
<div class="modal-body">Modal Content..
div
<div class="modal-footer">
<button type="button" class=">btn btn-danger
"
data-bs-dismiss
=
"
modal
"
Close
button
div
div
div
div
Try it »
Adding Animation
Use the .fade class to set the effect of the modal popping in or closing:
Example
<div class=">modal fade
"
div
<div class="modal" div>Try it »
Modal Size
We can create a small modal by adding the .modal-sm class, and a large modal with the .modal-lg class.
The size class is placed on the
Example - Small Modal
<div class=">modal-dialog modal-sm
"
Try it »
Example - Large Modal
<div class=">modal-dialog modal-lg
"
Try it »
Example - Extra Large Modal
<div class=">modal-dialog modal-xl
"
Try it »
Full-screen Display
Use the .modal-fullscreen class to make the modal display full-screen:
Example - Full-screen Display
<div class=">modal-dialog modal-fullscreen
"
Try it »
Using the .modal-fullscreen-- class to control at what sizes it displays full-screen:
| class | Description | Example |
|---|---|---|
.modal-fullscreen-sm-down |
Full-screen display at sizes below 576px | Try it |
.modal-fullscreen-md-down |
Full-screen display at sizes below 768px | Try it |
.modal-fullscreen-lg-down |
Full-screen display at sizes below 992px | Try it |
.modal-fullscreen-xl-down |
Full-screen display at sizes below 1200px | Try it |
.modal-fullscreen-xxl-down |
Full-screen display at sizes below 1400px | Try it |
Modal Centered Display
Use the .modal-dialog-centered class to center the modal both horizontally and vertically:
Example
<div class=">modal-dialog modal-dialog-centered
"
Try it »
Modal Scrollbar
By default, if a modal contains a lot of content, the page automatically generates a scroll, and the modal scrolls with the page:
Example
<div class="modal-dialog">Try it »
If we only want to set a scrollbar inside the modal, we can use the .modal-dialog-scrollable class:
Example
<div class=">modal-dialog modal-dialog-scrollable
"
Try it »