Center Bootstrap 5 Form: A Comprehensive Guide

Ruth Jul 09, 2026

Centering a form in Bootstrap 5 is a common task when designing responsive web layouts. Bootstrap 5, the latest version of the popular CSS framework, provides several classes and utilities to help you achieve this with ease. In this guide, we'll explore how to center a form both horizontally and vertically using Bootstrap 5.

How to Center and Justify a form in bootstrap 5
How to Center and Justify a form in bootstrap 5

Before we dive into the specifics, ensure you have included the Bootstrap 5 CDN or the compiled files in your project. You'll need the following CDN links for this guide: <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet"> and <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>.

Free 22+ HTML5 Signup & Registration Forms - HTML, CSS
Free 22+ HTML5 Signup & Registration Forms - HTML, CSS

Horizontally Centering a Form

To center a form horizontally, you can use Bootstrap 5's flexbox utilities. The key class you'll need is .d-flex.justify-content-center. Here's how you can apply it:

Stylish and Functional Footer Design for Modern Websites
Stylish and Functional Footer Design for Modern Websites

First, wrap your form in a container with the mentioned classes. Then, apply the .mx-auto class to the form itself to center it within its container.

Using a Container

Bootstrap Responsive Design Registration Form
Bootstrap Responsive Design Registration Form

Bootstrap 5's grid system provides various container classes. For this example, let's use .container and .container-fluid.

```html

```

Using a Row

Google Map Autocomplete to Form (Bootstrap)
Google Map Autocomplete to Form (Bootstrap)

Alternatively, you can use a row (.row) to center your form. This approach is useful when you want to combine the form with other elements in the same row.

```html

```

Vertically Centering a Form

Modern Footer Design with Social Icons and Payment Options
Modern Footer Design with Social Icons and Payment Options

Centering a form vertically is a bit trickier due to the varying heights of forms. Bootstrap 5's flexbox utilities can help, but you might need to adjust the form's height or use JavaScript to achieve the desired result.

For this example, let's assume your form has a fixed height. We'll use the .align-items-center class along with .h-100 to vertically center the form within its container.

Bootstrap Fieldset Legend: How To + Examples + Template | AZMIND
Bootstrap Fieldset Legend: How To + Examples + Template | AZMIND
the bootstap login and register forms page
the bootstap login and register forms page
📝 Create Forms in HTML
📝 Create Forms in HTML
Ynex - Blazor Server Bootstrap Admin Template
Ynex - Blazor Server Bootstrap Admin Template
an image of a dashboard screen with different colors and numbers on it, as well as the
an image of a dashboard screen with different colors and numbers on it, as well as the
Business Sign Up Form Responsive Widget Template | ThemeVault | ThemeVault
Business Sign Up Form Responsive Widget Template | ThemeVault | ThemeVault
BOOTSTRAP INPUT FORM (2020) | HOW TO MAKE FORM IN BOOTSTRAP
BOOTSTRAP INPUT FORM (2020) | HOW TO MAKE FORM IN BOOTSTRAP
55 Best Free Bootstrap Registration Form Designs 2026 - Colorlib
55 Best Free Bootstrap Registration Form Designs 2026 - Colorlib
Design Better Forms - Sergii Vergulenko
Design Better Forms - Sergii Vergulenko
a screenshot of a web page with an image of the user's profile
a screenshot of a web page with an image of the user's profile
Datta Able Bootstrap 5 Admin Template
Datta Able Bootstrap 5 Admin Template
Complete Beginner CSS Master Notes
Complete Beginner CSS Master Notes
Wizard
Wizard
Drixo - Admin & Dashboard Template
Drixo - Admin & Dashboard Template
an image of a web page with many different things on it, including food and drinks
an image of a web page with many different things on it, including food and drinks
Azan – Islamic Center Responsive HTML Template Bootstrap website
Azan – Islamic Center Responsive HTML Template Bootstrap website
20,000+ Free Online Form Templates & Form Examples | Jotform
20,000+ Free Online Form Templates & Form Examples | Jotform
Bootstrap Forms
Bootstrap Forms
Student Registration Form in HTML with CSS | Completely Free
Student Registration Form in HTML with CSS | Completely Free
Booking Form Builder | SaaS Admin Dashboard UIUX by Be Confidency on Muzli
Booking Form Builder | SaaS Admin Dashboard UIUX by Be Confidency on Muzli

Using a Container with Fixed Height

First, set a fixed height for your container. Then, apply the .d-flex.align-items-center.h-100 classes to it. Finally, set the form's height to match the container's height.

```html

```

Using JavaScript (with Bootstrap 5's Modal)

If your form's height varies, you can use Bootstrap 5's Modal component to center it both horizontally and vertically. The modal will automatically center the form within its viewport.

```html

```

In conclusion, centering a form in Bootstrap 5 is a straightforward task once you understand the framework's flexbox utilities. By combining the .d-flex, .justify-content-center, .align-items-center, and .mx-auto classes, you can create responsive and visually appealing forms that are perfectly centered both horizontally and vertically. Happy coding!