How to Center Modal Vertically in Bootstrap 5, 4, and 3

Last Updated on January 3, 2025 by Roshan Parihar

Learn how to center align modal vertically in Bootstrap 5 and other versions. The short answer is to use the class .modal-dialog-centered to the div element. Let’s find out with the examples.

Center Modal Vertically in Bootstrap 5

To center align a modal vertically in Bootstrap 5, you have to add the class .modal-dialog-centered to the <div> element having class .modal-dialog.

Test it Live

Output

Center Modal Vertically in Bootstrap 5

When you click the above button, you will get the live preview when you can check the center aligned button in Bootstrap 5.

Make Modal Vertical Center in Bootstrap 4

Bootstrap 4 also provides the same class .modal-dialog-centered which you have to add the same <div> element having class .modal-dialog. This makes the modal align center vertically and horizontally.

Test it Live

Output

Make Modal Vertical Center in Bootstrap 4

You can click the button given above to see the live preview and check the centred modal alignment.

Vertical Alignment in Bootstrap 3

In higher versions of Bootstrap, you can easily make alignment centrally by adding a single class. However, in Bootstrap 3, there is not class available that you can use for center alignment. But, you can add some CSS given below for this.

Test it Live

Output

Make Modal Vertical Center in Bootstrap 3

If you want to check the alignment in Bootstrap 3, you can click the button given above.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.