<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dialog modal-dialog-scrollable modal-dialog-centered"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="exampleModalLabel">Modal title</h5> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> <p>Line 1</p> <p>Line 2</p> <p>Line 3</p> <p>Line 4</p> <p>Line 5</p> <p>Line 6</p> <p>Line 7</p> <p>Line 8</p> <p>Line 9</p> <p>Line 10</p> <p>Line 11</p> <p>Line 12</p> <p>Line 13</p> <p>Line 14</p> <p>Line 15</p> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button> <button type="button" class="btn btn-primary">Save changes</button> </div> </div> </div> </div>
The modal-dialog-centered class centers the modal vertically in the viewport. The modal-dialog-scrollable class makes the modal body scrollable if content is too long. So the modal appears centered and the body scrolls to show all lines.
The modal-dialog-scrollable class enables scrolling inside the modal body when content is long. Other classes control positioning or do not exist.
modal-dialog wrapper div inside a Bootstrap modal?modal-dialog div:
<div class="modal fade" id="myModal" tabindex="-1" aria-hidden="true">
<div class="modal-content">
<div class="modal-header">...</div>
<div class="modal-body">...</div>
</div>
</div>
What happens when you try to open this modal?The modal-dialog div is required to apply positioning and scrolling styles. Without it, the modal content is not centered and scroll behavior breaks, but no JS error occurs.
The aria-labelledby attribute on the modal container points to the modal title's id. This helps screen readers announce the modal's purpose when it opens.
.modal-dialog or its parent achieves vertical centering?Bootstrap sets the modal container to display: flex and uses align-items: center to vertically center the modal dialog. The container also has min-height: 100vh to fill the viewport height.