Performance: Scrollable and centered modals
This affects page interaction speed and visual stability when modals appear and scroll within the viewport.
<div class="modal fade" tabindex="-1" role="dialog"> <div class="modal-dialog modal-dialog-scrollable modal-dialog-centered" role="document"> <div class="modal-content"> <!-- content --> </div> </div> </div>
<div class="modal" tabindex="-1" role="dialog"> <div class="modal-dialog" role="document"> <div class="modal-content"> <!-- content --> </div> </div> </div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Basic modal without scrollable or centered classes | Low (few nodes) | Multiple reflows on large content overflow | High due to layout shifts | [X] Bad |
| Modal with modal-dialog-scrollable and modal-dialog-centered classes | Low (few nodes) | Single reflow on open | Low paint cost with stable layout | [OK] Good |
modal-dialog-scrollable do in a modal?modal-dialog-scrollable is designed to allow the modal content area to scroll if the content is too long.modal-dialog-centered which centers the modal, this class specifically controls scrolling inside the modal.modal-dialog-scrollable and modal-dialog-centered as separate classes to add scroll and vertical centering.<div class='modal-dialog modal-dialog-scrollable modal-dialog-centered'>
<div class='modal-content'>
<div class='modal-body'>
<p>Very long content here...</p>
</div>
</div>
</div>modal-dialog-scrollable and modal-dialog-centered classes.modal-dialog-scrollable but the modal content is not scrolling. What is the likely mistake?modal-dialog-scrollable class must be on the modal-dialog element, not on modal-content or others.modal-dialog-scrollable and modal-dialog-centered on the modal-dialog element.modal-content, include modal-header and modal-footer which remain fixed, while modal-body scrolls.Pass the test and this pattern moves unknown