Bootstrap 5 Modal

Modal

The Modal component is a dialog/popup window displayed at the 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>
<!-- Modal -->
<div class="modal" id="myModal">
  <div class="modal-dialog">
    <div class="modal-content">
      <!-- Modal title -->
      <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

to add animation

Please use .fade The class adds fade-in and fade-out effects 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

by adding .modal-sm class (max-width 300px) to add .modal-lg class (max-width 800px) or add .modal-xl to change the size of the modal (max-width 1140 pixels). The default maximum width is 500 pixels.

Please replace .modal-dialog Add the class and size class to <div> Element:

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, the size of the modal is "medium" (max-width of 500px).

Fullscreen Modal

If you want the modal to span the entire width and height of the page, please use .modal-fullscreen Class:

Example

<div class="modal-dialog modal-fullscreen">

Try It Yourself

Responsive Fullscreen Modal

You can also use .modal-fullscreen-*-* Class controls when the modal should be displayed in full screen:

Class Description Example
.modal-fullscreen-sm-down Full screen below 576px Try It Yourself
.modal-fullscreen-md-down Full screen below 768px Try It Yourself
.modal-fullscreen-lg-down Full screen below 992px Try It Yourself
.modal-fullscreen-xl-down Full screen below 1200px Try It Yourself
.modal-fullscreen-xxl-down Full screen below 1400px Try It Yourself

Centered Modal

By using .modal-dialog-centric Class, vertically and horizontally center the modal within the page:

Example

<div class="modal-dialog modal-dialog-centered">

Try It Yourself

Scrollable Modal

When there is a lot of content in the modal, it will add a scrollbar to the page. Please see the following example to understand:

Example

<div class="modal-dialog">

Try It Yourself

However, by using .modal-dialog-scrollable Add to .modal-dialog Can be scrolled within the modal itself, not the page itself:

Example

<div class="modal-dialog modal-dialog-scrollable">

Try It Yourself