Bootstrap 4 Center Form Tutorial

Ruth Jul 09, 2026

In the realm of web development, Bootstrap has emerged as a powerful tool for creating responsive and mobile-first websites. One of its standout features is the ability to center forms both vertically and horizontally using the Flexbox layout. In this article, we'll delve into the intricacies of centering forms in Bootstrap 4, ensuring your web applications maintain a clean, balanced, and user-friendly aesthetic.

How to center form using Bootstrap 4
How to center form using Bootstrap 4

Bootstrap 4's grid system, built on Flexbox, provides a robust foundation for aligning elements. By leveraging this system, we can effortlessly center forms within their containers, enhancing the overall user experience.

Bootstrap 4: Align a Div or Form Vertically and Horizontally | AZMIND
Bootstrap 4: Align a Div or Form Vertically and Horizontally | AZMIND

Centering Forms Horizontally

To center a form horizontally, we'll utilize the Flexbox utilities provided by Bootstrap 4. These utilities allow us to manipulate the alignment of elements along the main axis (horizontal) and the cross axis (vertical).

Wizard
Wizard

First, let's apply the `justify-content-center` class to the parent container of our form. This class will center the form horizontally within its container.

Using Flexbox Utilities

Bootstrap Forms
Bootstrap Forms

Here's a simple example demonstrating how to center a form horizontally using Flexbox utilities:

<div class="d-flex justify-content-center">
  <form>
    <input type="text" class="form-control" placeholder="Enter text">
    <button type="submit" class="btn btn-primary">Submit</button>
  </form>
</div>

In this example, the `d-flex` class makes the container a flex container, while `justify-content-center` centers the form horizontally.

Centering Nested Forms

37 Free Bootstrap Form Templates You Can Try Right Now
37 Free Bootstrap Form Templates You Can Try Right Now

What if you want to center a form that's nested within another form? You can still use the same approach by applying the Flexbox utilities to the appropriate parent container:

<form>
  <div class="d-flex justify-content-center">
    <form>
      <input type="text" class="form-control" placeholder="Enter text">
      <button type="submit" class="btn btn-primary">Submit</button>
    </form>
  </div>
</form>

In this case, the inner form is centered horizontally within its parent form.

Centering Forms Vertically

the homepage for an employee portal with a rocket ship in the background and text that reads, apply as a employee
the homepage for an employee portal with a rocket ship in the background and text that reads, apply as a employee

Centering forms vertically is equally important for maintaining a balanced layout. Bootstrap 4 provides utilities to achieve this as well. We'll use the `align-items-center` class in conjunction with `h-100` to ensure the form takes up the full height of its container and is centered vertically.

To implement this, apply the `d-flex` and `flex-column` classes to the parent container to make it a column flex container. Then, use `h-100` to make the form take up the full height of its container, and `align-items-center` to center it vertically.

Free 22+ HTML5 Signup & Registration Forms - HTML, CSS
Free 22+ HTML5 Signup & Registration Forms - HTML, CSS
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
Bootstrap 4 Admin Dashboard Template
Bootstrap 4 Admin Dashboard Template
Bootstrap Responsive Design Registration Form
Bootstrap Responsive Design Registration Form
55 Best Free Bootstrap Registration Form Designs 2026 - Colorlib
55 Best Free Bootstrap Registration Form Designs 2026 - Colorlib
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
BOOTSTRAP INPUT FORM (2020) | HOW TO MAKE FORM IN BOOTSTRAP
BOOTSTRAP INPUT FORM (2020) | HOW TO MAKE FORM IN BOOTSTRAP
100+ Best Free Bootstrap Templates 2024
100+ Best Free Bootstrap Templates 2024
Halaman Tidak Ditemukan - 404
Halaman Tidak Ditemukan - 404
the bootstap login and register forms page
the bootstap login and register forms page
Qixa Admin Template
Qixa Admin Template
Bootstrap Registration Forms: 3 Free Responsive Templates | AZMIND
Bootstrap Registration Forms: 3 Free Responsive Templates | AZMIND
the front page of an email form to book a demo
the front page of an email form to book a demo
Drixo - Admin & Dashboard Template
Drixo - Admin & Dashboard Template
Ynex - Blazor Server Bootstrap Admin Template
Ynex - Blazor Server Bootstrap Admin Template
an image of a computer screen with blue lights and black trees in the back ground
an image of a computer screen with blue lights and black trees in the back ground
100+ Admin Templates & Dashboards - Free Download
100+ Admin Templates & Dashboards - Free Download
Design Better Forms - Sergii Vergulenko
Design Better Forms - Sergii Vergulenko
AdminKit PRO - Bootstrap 5 Admin Template
AdminKit PRO - Bootstrap 5 Admin Template
Toner - eCommerce Template + Admin Pages
Toner - eCommerce Template + Admin Pages

Using Flexbox for Vertical Centering

Here's an example demonstrating how to center a form vertically using Flexbox:

<div class="d-flex flex-column h-100 align-items-center">
  <form>
    <input type="text" class="form-control mb-3" placeholder="Enter text">
    <button type="submit" class="btn btn-primary">Submit</button>
  </form>
</div>

In this example, the form is centered both horizontally and vertically within its container.

Centering Forms with Fixed Heights

What if your form has a fixed height, and you want to center it vertically within its container? In this case, you can use the `align-self-center` class on the form itself:

<div class="d-flex flex-column h-100">
  <form class="align-self-center">
    <input type="text" class="form-control mb-3" placeholder="Enter text">
    <button type="submit" class="btn btn-primary">Submit</button>
  </form>
</div>

In this scenario, the form is centered vertically within its container, despite having a fixed height.

By mastering these techniques, you'll be well-equipped to create visually appealing and responsive forms using Bootstrap 4. Now go forth and build stunning web applications with centered forms that enhance the user experience!