Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

Bootstrap 5 Modal


Modals

The Modal component is a dialog box/popup window that is displayed on top of the current page:


How To Create a Modal

The following example shows how to create a basic modal:

Example

<!-- Button to Open the Modal -->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#myModal">
  Open modal
</button>

<!-- The Modal -->
<div class="modal" id="myModal">
  <div class="modal-dialog">
    <div class="modal-content">

      <!-- Modal Header -->
      <div class="modal-header">
        <h4 class="modal-title">Modal Heading</h4>
        <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
      </div>

      <!-- Modal body -->
      <div class="modal-body">
        Modal body..
      </div>

      <!-- Modal footer -->
      <div class="modal-footer">
        <button type="button" class="btn btn-danger" data-bs-dismiss="modal">Close</button>
      </div>

    </div>
  </div>
</div>
Try it Yourself »

Add animation

Use the .fade class to add a fading effect when opening and closing the modal:

Example

<!-- Fading modal -->
<div class="modal fade"></div>

<!-- Modal without animation -->
<div class="modal"></div>
Try it Yourself »


Modal Size

Change the size of the modal by adding the .modal-sm class for small modals (max-width 300px), .modal-lg class for large modals  (max-width 800px), or .modal-xl for extra large modals  (max-width 1140px). Default is 500px max-width.

Add the size class to the <div> element with class .modal-dialog:

Small Modal

<div class="modal-dialog modal-sm">
Try it Yourself »

Large Modal

<div class="modal-dialog modal-lg">
Try it Yourself »

Extra Large Modal

<div class="modal-dialog modal-xl">
Try it Yourself »

By default, modals are "medium" in size (500px max-width).


Fullscreen Modals

If you want the modal to span the whole width and height of the page, use the .modal-fullscreen class:

Example

<div class="modal-dialog modal-fullscreen">
Try it Yourself »

Responsive Fullscreen Modals

You can also control when the modal should be in fullscreen, with the .modal-fullscreen-*-* classes:

Class Description Example
.modal-fullscreen-sm-down Fullscreen below 576px Try it
.modal-fullscreen-md-down Fullscreen below 768px Try it
.modal-fullscreen-lg-down Fullscreen below 992px Try it
.modal-fullscreen-xl-down Fullscreen below 1200px Try it
.modal-fullscreen-xxl-down Fullscreen below 1400px Try it

Centered Modal

Center the modal vertically and horizontally within the page, with the .modal-dialog-centered class:

Example

<div class="modal-dialog modal-dialog-centered">
Try it Yourself »

Scrolling Modal

When you have a lot of content inside the modal, a scrollbar is added to the page. See the examples below to understand it:

Example

<div class="modal-dialog">
Try it Yourself »

However, it is possible to only scroll inside the modal, instead of the page itself, by adding .modal-dialog-scrollable to .modal-dialog:

Example

<div class="modal-dialog modal-dialog-scrollable">
Try it Yourself »


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.