Bootstrap 5 (Updated 2021)

Bootstrap 5 is still flexbox based so vertical centering works the same way as it did in Bootstrap 4. For example, align-items-center (flex-direction: row) and justify-content-center (flex-direction: column) can used on the flexbox parent (row or d-flex).

Centering examples in Bootstrap 5

Vertical center (don't forget the parent must have a defined height!):

  • my-auto for centering inside flex (.d-flex) elements
  • my-auto can be used to center columns (.col-) inside row
  • align-items-center to center columns (col-*) inside row

Horizontal center:

  • text-center to center display:inline elements & column content
  • mx-auto for centering inside flex elements
  • mx-auto can be used to center columns (.col-) inside row
  • justify-content-center to center columns (col-*) inside row

Bootstrap 4.3+ (Update 2019)

There's no need for extra CSS. What's already included in Bootstrap will work. Make sure the container(s) of the form are full height. Bootstrap 4 now has a h-100 class for 100% height...

Vertical center:

<div class="container h-100">
  <div class="row h-100 justify-content-center align-items-center">
    <form class="col-12">
      <div class="form-group">
        <label for="formGroupExampleInput">Example label</label>
        <input type="text" class="form-control" id="formGroupExampleInput" placeholder="Example input">
      </div>
      <div class="form-group">
        <label for="formGroupExampleInput2">Another label</label>
        <input type="text" class="form-control" id="formGroupExampleInput2" placeholder="Another input">
      </div>
    </form>   
  </div>
</div>

https://codeply.com/go/raCutAGHre

the height of the container with the item(s) to center should be 100% (or whatever the desired height is relative to the centered item)

Note: When using height:100% (percentage height) on any element, the element takes in the height of it's container. In modern browsers vh units height:100vh; can be used instead of % to get the desired height.

Therefore, you can set html, body {height: 100%}, or use the new min-vh-100 class on container instead of h-100.


Horizontal center:

  • text-center to center display:inline elements & column content
  • mx-auto for centering inside flex elements
  • offset-* or mx-auto can be used to center columns (.col-)
  • justify-content-center to center columns (col-*) inside row

Vertical Align Center in Bootstrap
Bootstrap 4 full-screen centered form
Bootstrap 4 center input group
Bootstrap 4 horizontal + vertical center full screen

Answer from Carol Skelly on Stack Overflow
🌐
Bootstrap
getbootstrap.com › docs › 5.3 › utilities › text
Text · Bootstrap v5.3
<p class="text-start">Start aligned text on all viewport sizes.</p> <p class="text-center">Center aligned text on all viewport sizes.</p> <p class="text-end">End aligned text on all viewport sizes.</p> <p class="text-sm-end">End aligned text on viewports sized SM (small) or wider.</p> <p class="text-md-end">End aligned text on viewports sized MD (medium) or wider.</p> <p class="text-lg-end">End aligned text on viewports sized LG (large) or wider.</p> <p class="text-xl-end">End aligned text on viewports sized XL (extra large) or wider.</p> <p class="text-xxl-end">End aligned text on viewports sized XXL (extra extra large) or wider.</p>
🌐
Bootstrap
getbootstrap.com › docs › 4.0 › utilities › flex
Flex · Bootstrap
Use align-content utilities on flexbox containers to align flex items together on the cross axis. Choose from start (browser default), end, center, between, around, or stretch.
Top answer
1 of 16
539

Bootstrap 5 (Updated 2021)

Bootstrap 5 is still flexbox based so vertical centering works the same way as it did in Bootstrap 4. For example, align-items-center (flex-direction: row) and justify-content-center (flex-direction: column) can used on the flexbox parent (row or d-flex).

Centering examples in Bootstrap 5

Vertical center (don't forget the parent must have a defined height!):

  • my-auto for centering inside flex (.d-flex) elements
  • my-auto can be used to center columns (.col-) inside row
  • align-items-center to center columns (col-*) inside row

Horizontal center:

  • text-center to center display:inline elements & column content
  • mx-auto for centering inside flex elements
  • mx-auto can be used to center columns (.col-) inside row
  • justify-content-center to center columns (col-*) inside row

Bootstrap 4.3+ (Update 2019)

There's no need for extra CSS. What's already included in Bootstrap will work. Make sure the container(s) of the form are full height. Bootstrap 4 now has a h-100 class for 100% height...

Vertical center:

<div class="container h-100">
  <div class="row h-100 justify-content-center align-items-center">
    <form class="col-12">
      <div class="form-group">
        <label for="formGroupExampleInput">Example label</label>
        <input type="text" class="form-control" id="formGroupExampleInput" placeholder="Example input">
      </div>
      <div class="form-group">
        <label for="formGroupExampleInput2">Another label</label>
        <input type="text" class="form-control" id="formGroupExampleInput2" placeholder="Another input">
      </div>
    </form>   
  </div>
</div>

https://codeply.com/go/raCutAGHre

the height of the container with the item(s) to center should be 100% (or whatever the desired height is relative to the centered item)

Note: When using height:100% (percentage height) on any element, the element takes in the height of it's container. In modern browsers vh units height:100vh; can be used instead of % to get the desired height.

Therefore, you can set html, body {height: 100%}, or use the new min-vh-100 class on container instead of h-100.


Horizontal center:

  • text-center to center display:inline elements & column content
  • mx-auto for centering inside flex elements
  • offset-* or mx-auto can be used to center columns (.col-)
  • justify-content-center to center columns (col-*) inside row

Vertical Align Center in Bootstrap
Bootstrap 4 full-screen centered form
Bootstrap 4 center input group
Bootstrap 4 horizontal + vertical center full screen

2 of 16
37

This work for me:

<section class="h-100">
  <header class="container h-100">
    <div class="d-flex align-items-center justify-content-center h-100">
      <div class="d-flex flex-column">
        <h1 class="text align-self-center p-2">item 1</h1>
        <h4 class="text align-self-center p-2">item 2</h4>
        <button class="btn btn-danger align-self-center p-2" type="button" name="button">item 3</button>
      </div>
    </div>
  </header>
</section>
🌐
Bootstrap
getbootstrap.com › docs › 5.3 › layout › columns
Columns · Bootstrap v5.3
Change the vertical alignment with any of the responsive align-items-* classes. ... <div class="container text-center"> <div class="row align-items-start"> <div class="col"> One of three columns </div> <div class="col"> One of three columns </div> <div class="col"> One of three columns </div> </div> </div>
🌐
Pictogrammers
pictogrammers.com › library › mdi
Material Design Icons - Icon Library - Pictogrammers
The original. Following Google's Material Design guidelines for system icons, MDI is our largest library, touting over 7200 unique icons!
🌐
Bootstrap
getbootstrap.com › docs › 5.0 › utilities › flex
Flex · Bootstrap v5.0
Use justify-content utilities on flexbox containers to change the alignment of flex items on the main axis (the x-axis to start, y-axis if flex-direction: column). Choose from start (browser default), end, center, between, around, or evenly.
Find elsewhere
🌐
MUI
mui.com › material-ui › react-grid
React Grid component - Material UI
To center a grid item's content, specify display="flex" directly on the item. Then use justifyContent and/or alignItems to adjust the position of the content, as shown below:
🌐
Bootstrap
getbootstrap.com › docs › 4.0 › utilities › vertical-align
Vertical alignment · Bootstrap
<table style="height: 100px;"> <tbody> <tr> <td class="align-baseline">baseline</td> <td class="align-top">top</td> <td class="align-middle">middle</td> <td class="align-bottom">bottom</td> <td class="align-text-top">text-top</td> <td class="align-text-bottom">text-bottom</td> </tr> </tbody> </table>
🌐
Bootstrap
getbootstrap.com › docs › 4.0 › layout › grid
Grid system · Bootstrap
Containers provide a means to center and horizontally pad your site’s contents. Use .container for a responsive pixel width or .container-fluid for width: 100% across all viewport and device sizes. Rows are wrappers for columns. Each column has horizontal padding (called a gutter) for controlling the space between them. This padding is then counteracted on the rows with negative margins. This way, all the content in your columns is visually aligned down the left side.
🌐
GeeksforGeeks
geeksforgeeks.org › bootstrap › how-to-center-the-text-in-bootstrap
How to Center the Text in Bootstrap ? - GeeksforGeeks
July 23, 2025 - To center text in Bootstrap, you can use the class "text-center" on the parent element of the text you want to center. This class aligns the text horizontally in the center of its container, providing a simple and effective way to achieve centered ...
🌐
Bootstrap
getbootstrap.com › docs › 5.0 › utilities › text
Text · Bootstrap v5.0
<p class="text-start">Start aligned text on all viewport sizes.</p> <p class="text-center">Center aligned text on all viewport sizes.</p> <p class="text-end">End aligned text on all viewport sizes.</p> <p class="text-sm-start">Start aligned text on viewports sized SM (small) or wider.</p> <p class="text-md-start">Start aligned text on viewports sized MD (medium) or wider.</p> <p class="text-lg-start">Start aligned text on viewports sized LG (large) or wider.</p> <p class="text-xl-start">Start aligned text on viewports sized XL (extra-large) or wider.</p>
🌐
Feather Icons
feathericons.com
Feather – Simply beautiful open source icons
Feather is a collection of simply beautiful open source icons. Each icon is designed on a 24x24 grid with an emphasis on simplicity, consistency and readability.
🌐
Bootstrapclasses
bootstrapclasses.com › how-to-center-a-div-horizontally-in-bootstrap-4
How To Center a div Horizontally in Bootstrap 4 & 5 2026 - Bootstrap CSS Classes Cheat Sheets
February 19, 2024 - Then I added a utility class of .mx-auto that sets the margin left and right to auto centering it horizontally inside the .row container. <div class="row"> <div class="col-md-8 mx-auto"> <h3>Me Too!</h3> </div> </div> In this example, I am using Bootstrap’s width utility class of .w-50 to make the div 50% wide all the time.
🌐
Bootstrap
getbootstrap.com › docs › 5.0 › utilities › vertical-align
Vertical alignment · Bootstrap v5.0
There's a newer version of Bootstrap! ... Easily change the vertical alignment of inline, inline-block, inline-table, and table cell elements. Change the alignment of elements with the vertical-alignment utilities. Please note that vertical-align only affects inline, inline-block, inline-table, and table cell elements. Choose from .align-baseline, .align-top, .align-middle, .align-bottom, .align-text-bottom, and .align-text-top as needed. To vertically center non-inline content (like <div>s and more), use our flex box utilities.
🌐
Bootstrap Shuffle
bootstrapshuffle.com › classes › flexbox › align-items-*-center
align-items-*-center - Bootstrap CSS class
<div class="d-flex align-items-center"> <div class="p-2">Flex item 1</div> <div class="p-2">Flex item 2</div> <div class="p-2">Flex item 3</div> </div> <!-- responsive variations --> <div class="d-flex align-items-sm-center">...</div> <div class="d-flex align-items-md-center">...</div> <div class="d-flex align-items-lg-center">...</div> <div class="d-flex align-items-xl-center">...</div>Copy code ... You don't need to remember all CSS classes. Just use the Bootstrap Editor instead.
🌐
FastBootstrap
fastbootstrap.com › docs › align-self
Bootstrap Align Self CSS - FastBootstrap
Use align-self-center to align an item along the center of the container’s cross axis, despite the container’s align-items value:
🌐
Bootstrap Shuffle
bootstrapshuffle.com › classes › flexbox › align-self-*-center
align-self-*-center - Bootstrap CSS class
<div class="align-self-center">Aligned flex item</div> <!-- responsive variations --> <div class="align-self-sm-center">Aligned flex item</div> <div class="align-self-md-center">Aligned flex item</div> <div class="align-self-lg-center">Aligned flex item</div> <div class="align-self-xl-center">Aligned flex item</div>Copy code ... You don't need to remember all CSS classes. Just use the Bootstrap Editor instead.
🌐
freeCodeCamp
forum.freecodecamp.org › html-css
Vertical and horizontal text align bootstrap - HTML-CSS - The freeCodeCamp Forum
January 25, 2021 - I have the following below: <section class="m-5"> <div class="container"> <div class="row text-center justify-content-center" style="height:75px"> <div id="one" class="col-2 border ">1</div> <…
🌐
Bootstrap Shuffle
bootstrapshuffle.com › classes › flexbox › align-content-*-center
align-content-*-center - Bootstrap CSS class
<div class="d-flex flex-wrap align-content-center"> <div class="p-2">Flex item</div> <div class="p-2">Flex item</div> <div class="p-2">Flex item</div> ... </div> <!-- responsive variations --> <div class="d-flex align-content-sm-center">...</div> <div class="d-flex align-content-md-center">...</div> <div class="d-flex align-content-lg-center">...</div> <div class="d-flex align-content-xl-center">...</div>Copy code ... You don't need to remember all CSS classes. Just use the Bootstrap Editor instead.