To use Bootstrap’s JavaScript modal plugin to add dialogs to your site for lightboxes, user notifications, or completely custom content.
Modals are built with HTML, CSS, and JavaScript. They’re positioned over everything else in the document and remove scroll from the <body> 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.
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.
When modals become too long for the user’s device, they scroll independent of the page itself.
Sample Code
<!doctype html><htmllang="en"><head><metacharset="utf-8"><metaname="viewport"content="width=device-width, initial-scale=1"><linkhref="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css"rel="stylesheet"><linkhref="https://getbootstrap.com/docs/5.2/assets/css/docs.css"rel="stylesheet"><title>Bootstrap Example</title><scriptsrc="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script></head><bodyclass="p-3 m-0 border-0 bd-example"><divclass="modal fade"id="exampleModalLong"tabindex="-1"aria-labelledby="exampleModalLongTitle"aria-hidden="true"><divclass="modal-dialog"><divclass="modal-content"><divclass="modal-header"><h1class="modal-title fs-5"id="exampleModalLongTitle">Title</h1><buttontype="button"class="btn-close"data-bs-dismiss="modal"aria-label="Close"></button></div><divclass="modal-body"style="min-height: 1500px"><p>In general HTML webpage will be developed by using various technologies such as JAVASCRIPT, CSS, AJAX, JSON but HTML is the base for the Webpages, we can create webpages by using only HTML, no webpages cannot be developed without HTML.</p></div><divclass="modal-footer"><buttontype="button"class="btn btn-secondary"data-bs-dismiss="modal">Close</button><buttontype="button"class="btn btn-primary">Save changes</button></div></div></div></div><divclass="bd-example"><buttontype="button"class="btn btn-primary"data-bs-toggle="modal"data-bs-target="#exampleModalLong">
Demo modal
</button></div></body></html>
Output
Bootstrap Model Scrolling long content Example 2
Sample Code
<!doctype html><htmllang="en"><head><metacharset="utf-8"><metaname="viewport"content="width=device-width, initial-scale=1"><linkhref="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css"rel="stylesheet"><linkhref="https://getbootstrap.com/docs/5.2/assets/css/docs.css"rel="stylesheet"><title>Bootstrap Example</title><scriptsrc="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script></head><bodyclass="p-3 m-0 border-0 bd-example"><divclass="modal fade"id="exampleModalScrollable"tabindex="-1"aria-labelledby="exampleModalScrollableTitle"aria-hidden="true"><divclass="modal-dialog modal-dialog-scrollable"><divclass="modal-content"><divclass="modal-header"><h1class="modal-title fs-5"id="exampleModalScrollableTitle">Title</h1><buttontype="button"class="btn-close"data-bs-dismiss="modal"aria-label="Close"></button></div><divclass="modal-body"><p>In general HTML webpage will be developed by using various technologies such as JAVASCRIPT, CSS, AJAX, JSON but HTML is the base for the Webpages, </p><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><p>we can create webpages by using only HTML, no webpages cannot be developed without HTML.</p></div><divclass="modal-footer"><buttontype="button"class="btn btn-secondary"data-bs-dismiss="modal">Close</button><buttontype="button"class="btn btn-primary">Save changes</button></div></div></div></div><divclass="bd-example"><buttontype="button"class="btn btn-primary"data-bs-toggle="modal"data-bs-target="#exampleModalScrollable">
Demo modal
</button></div></body></html>
Output
Bootstrap Model Vertically Centered
Add .modal-dialog-centered to .modal-dialog to vertically center the modal.
Sample Code
<!doctype html><htmllang="en"><head><metacharset="utf-8"><metaname="viewport"content="width=device-width, initial-scale=1"><linkhref="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css"rel="stylesheet"><linkhref="https://getbootstrap.com/docs/5.2/assets/css/docs.css"rel="stylesheet"><title>Bootstrap Example</title><scriptsrc="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script></head><bodyclass="p-3 m-0 border-0 bd-example"><divclass="modal fade"id="exampleModalCenter"tabindex="-1"aria-labelledby="exampleModalCenterTitle"aria-hidden="true"><divclass="modal-dialog modal-dialog-centered"><divclass="modal-content"><divclass="modal-header"><h1class="modal-title fs-5"id="exampleModalCenterTitle">Title</h1><buttontype="button"class="btn-close"data-bs-dismiss="modal"aria-label="Close"></button></div><divclass="modal-body"><p>HTML - Hyper Text Markup Language.</p></div><divclass="modal-footer"><buttontype="button"class="btn btn-secondary"data-bs-dismiss="modal">Close</button><buttontype="button"class="btn btn-primary">Save changes</button></div></div></div></div><divclass="modal fade"id="exampleModalCenteredScrollable"tabindex="-1"aria-labelledby="exampleModalCenteredScrollableTitle"aria-hidden="true"><divclass="modal-dialog modal-dialog-centered modal-dialog-scrollable"><divclass="modal-content"><divclass="modal-header"><h1class="modal-title fs-5"id="exampleModalCenteredScrollableTitle">Modal title</h1><buttontype="button"class="btn-close"data-bs-dismiss="modal"aria-label="Close"></button></div><divclass="modal-body"><p>In general HTML webpage will be developed by using various technologies such as JAVASCRIPT, CSS, AJAX, JSON but HTML is the base for the Webpages, we can create webpages by using only HTML, no webpages cannot be developed without HTML.</p><br><br><br><br><br><br><br><br><br><br><p>Just like.</p></div><divclass="modal-footer"><buttontype="button"class="btn btn-secondary"data-bs-dismiss="modal">Close</button><buttontype="button"class="btn btn-primary">Save changes</button></div></div></div></div><divclass="bd-example"><buttontype="button"class="btn btn-primary"data-bs-toggle="modal"data-bs-target="#exampleModalCenter">
Centered modal
</button><buttontype="button"class="btn btn-primary"data-bs-toggle="modal"data-bs-target="#exampleModalCenteredScrollable">
Centered scrollable modal
</button></div></body></html>
Output
Bootstrap Model 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.
Sample Code
<!doctype html><htmllang="en"><head><metacharset="utf-8"><metaname="viewport"content="width=device-width, initial-scale=1"><linkhref="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css"rel="stylesheet"><linkhref="https://getbootstrap.com/docs/5.2/assets/css/docs.css"rel="stylesheet"><title>Bootstrap Example</title><scriptsrc="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script></head><bodyclass="p-3 m-0 border-0 bd-example"><divclass="modal fade"id="exampleModalPopovers"tabindex="-1"aria-labelledby="exampleModalPopoversLabel"aria-hidden="true"><divclass="modal-dialog"><divclass="modal-content"><divclass="modal-header"><h1class="modal-title fs-5"id="exampleModalPopoversLabel">Title</h1><buttontype="button"class="btn-close"data-bs-dismiss="modal"aria-label="Close"></button></div><divclass="modal-body"><h2class="fs-5">Modal</h2><p>This <ahref="#"role="button"class="btn btn-secondary"data-bs-toggle="popover"title="Popover title"data-bs-content="Popover body content is set in this attribute."data-bs-container="#exampleModalPopovers">button</a> triggers a popover on click.</p><hr><h2class="fs-5">Tooltips in a modal</h2><p><ahref="#"data-bs-toggle="tooltip"title="Tooltip"data-bs-container="#exampleModalPopovers">This link</a> and <ahref="#"data-bs-toggle="tooltip"title="Tooltip"data-bs-container="#exampleModalPopovers">that link</a> have tooltips on hover.</p></div><divclass="modal-footer"><buttontype="button"class="btn btn-secondary"data-bs-dismiss="modal">Close</button><buttontype="button"class="btn btn-primary">Save changes</button></div></div></div></div><divclass="bd-example"><buttontype="button"class="btn btn-primary"data-bs-toggle="modal"data-bs-target="#exampleModalPopovers">
Demo modal
</button></div></body></html>
Output
Bootstrap Model Using the grid
Grid system within a modal by nesting .container-fluid within the .modal-body.
Use event.relatedTarget and HTML data-bs-* attributes to vary the contents of the modal depending on which button was clicked.
Sample Code
<!doctype html><htmllang="en"><head><metacharset="utf-8"><metaname="viewport"content="width=device-width, initial-scale=1"><linkhref="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css"rel="stylesheet"><linkhref="https://getbootstrap.com/docs/5.2/assets/css/docs.css"rel="stylesheet"><title>Bootstrap Example</title><scriptsrc="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script></head><bodyclass="p-3 m-0 border-0 bd-example"><buttontype="button"class="btn btn-primary"data-bs-toggle="modal"data-bs-target="#exampleModal"data-bs-whatever="@mdo">Open modal for @KaashvInfotech</button><buttontype="button"class="btn btn-primary"data-bs-toggle="modal"data-bs-target="#exampleModal"data-bs-whatever="@fat">Open modal for @Wikitechy</button><buttontype="button"class="btn btn-primary"data-bs-toggle="modal"data-bs-target="#exampleModal"data-bs-whatever="@getbootstrap">Open modal for @Kaashiv</button><divclass="modal fade"id="exampleModal"tabindex="-1"aria-labelledby="exampleModalLabel"aria-hidden="true"style="display: none;"><divclass="modal-dialog"><divclass="modal-content"><divclass="modal-header"><h1class="modal-title fs-5"id="exampleModalLabel">New message to @KaashvInfotech</h1><buttontype="button"class="btn-close"data-bs-dismiss="modal"aria-label="Close"></button></div><divclass="modal-body"><form><divclass="mb-3"><labelfor="recipient-name"class="col-form-label">Recipient:</label><inputtype="text"class="form-control"id="recipient-name"></div><divclass="mb-3"><labelfor="message-text"class="col-form-label">Message:</label><textareaclass="form-control"id="message-text"></textarea></div></form></div><divclass="modal-footer"><buttontype="button"class="btn btn-secondary"data-bs-dismiss="modal">Close</button><buttontype="button"class="btn btn-primary">Send message</button></div></div></div></div></body></html>
Output
Bootstrap Toggle between modals
Multiple modals with some clever placement of the data-bs-target and data-bs-toggle attributes.
For example, you could toggle a password reset modal from within an already open sign in modal. Please note multiple modals cannot be open at the same time
Sample Code
<!doctype html><htmllang="en"><head><metacharset="utf-8"><metaname="viewport"content="width=device-width, initial-scale=1"><linkhref="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css"rel="stylesheet"><linkhref="https://getbootstrap.com/docs/5.2/assets/css/docs.css"rel="stylesheet"><title>Bootstrap Example</title><scriptsrc="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script></head><bodyclass="p-3 m-0 border-0 bd-example"><divclass="modal fade"id="exampleModalToggle"aria-labelledby="exampleModalToggleLabel"tabindex="-1"aria-hidden="true"style="display: none;"><divclass="modal-dialog modal-dialog-centered"><divclass="modal-content"><divclass="modal-header"><h1class="modal-title fs-5"id="exampleModalToggleLabel">Modal 1</h1><buttontype="button"class="btn-close"data-bs-dismiss="modal"aria-label="Close"></button></div><divclass="modal-body">
HTML - Hyper Text Markup Language.
</div><divclass="modal-footer"><buttonclass="btn btn-primary"data-bs-target="#exampleModalToggle2"data-bs-toggle="modal">Open second modal</button></div></div></div></div><divclass="modal fade"id="exampleModalToggle2"aria-labelledby="exampleModalToggleLabel2"tabindex="-1"aria-hidden="true"style="display: none;"><divclass="modal-dialog modal-dialog-centered"><divclass="modal-content"><divclass="modal-header"><h1class="modal-title fs-5"id="exampleModalToggleLabel2">Modal 2</h1><buttontype="button"class="btn-close"data-bs-dismiss="modal"aria-label="Close"></button></div><divclass="modal-body">
HTML is a typical markup language used for building a web pages.
</div><divclass="modal-footer"><buttonclass="btn btn-primary"data-bs-target="#exampleModalToggle"data-bs-toggle="modal">Back to first</button></div></div></div></div><aclass="btn btn-primary"data-bs-toggle="modal"href="#exampleModalToggle"role="button">Open first modal</a></body></html>