BBS5 Modal

Learn how to create modal dialog boxes.

BS5 Modal

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

Creating a Modal

A modal involves a container with .modal, a dialog .modal-dialog, and content .modal-content.

The .modal-content is usually divided into .modal-header, .modal-body, and .modal-footer.

Fading Modal

Add the .fade class to the .modal container to add a fade effect when opening and closing the modal.

Examples

Basic Modal

html/css

A standard modal dialog.

<!-- 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>

Centered Modal

html/css

Vertically centering the modal.

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

Scrolling Modal

html/css

Allows scrolling within the modal body.

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

Test Your Knowledge

1. Which attribute opens the modal?

2. Which class centers the modal vertically?