You can use with d-flex align-items-center justify-content-center like below demo:

body{
    height: 100vh;
} 
.container{
    height: 100%;
}
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"/>


<div class="container d-flex align-items-center justify-content-center">
        <div>
                <h1>You Div</h1>
            </div>
    </div>

Answer from Tuan Dao on Stack Overflow
🌐
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 - You can use Bootstrap offset classes to horizontally shift columns left or right. This is helpful when you want one column to have a max width but center it in a row. ... <div class="row"> <div class="col-md-8 offset-md-2"> <h3>Look!
🌐
Bootstrap
getbootstrap.com › docs › 4.0 › layout › grid
Grid system · Bootstrap
<div class="container"> <div class="row"> <div class="col-sm"> One of three columns </div> <div class="col-sm"> One of three columns </div> <div class="col-sm"> One of three columns </div> </div> </div> The above example creates three equal-width columns on small, medium, large, and extra large devices using our predefined grid classes. Those columns are centered in the page with the parent .container.
🌐
SheCodes
shecodes.io › athena › 1830-center-a-bootstrap-div-with-the-mx-auto-class
[Bootstrap] - Center a Bootstrap Div with the mx-auto Class | SheCodes
Learn how to use the mx-auto class to center a div with Bootstrap and also how to use Bootstrap's flex and justify-content utilities.
🌐
ShapeBootstrap
shapebootstrap.net › home › mastering div centering in bootstrap 5
How to Center a Div in Bootstrap 5: A Comprehensive Guide
July 11, 2023 - When it comes to centering multiple elements, using the flexbox utility and the “justify-content-center” and “align-items-center” classes is an effective approach. This ensures that elements within the div are centrally aligned, both horizontally and vertically, particularly when working with responsive design. Ultimately, it’s crucial to keep in mind that Bootstrap 5 provides an array of tools and utilities capable of helping you attain the precise centering effect you’re seeking.
Top answer
1 of 16
256

Update for 2025

https://caniuse.com/mdn-css_properties_align-content_block_context

All modern browsers added a way to center vertically without using Flex/Grid by adding align-content: center; on any block element

div { align-content: center; } /* one-line vertical centering */

Super cool update for 2024

WebKit Features in Safari 17.4 is adding a way to center vertically without using Flex/Grid by adding align-content: center; on any block element

div { align-content: center; } /* one-line vertical centering */

Soon is going to be available in all browsers

https://webkit.org/blog/15063/webkit-features-in-safari-17-4/#css

Update for Bootstrap 5

Simpler vertical grid alignement with flex-box

@import url('https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.0.1/css/bootstrap.min.css');
html,
body {
  height: 100%
}
<div class="h-100 d-flex align-items-center justify-content-center">
  <div style="background:red">
    TEXT
  </div>
</div>

Solution for Bootstrap 4

Simpler vertical grid alignement with flex-box

@import url('https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css');
html,
body {
  height: 100%
}
<div class="h-100 d-flex align-items-center justify-content-center">
  <div style="background:red">
    TEXT
  </div>
</div>

Solution for Bootstrap 3

@import url('http://getbootstrap.com/dist/css/bootstrap.css');
 html, body, .container-table {
    height: 100%;
}
.container-table {
    display: table;
}
.vertical-center-row {
    display: table-cell;
    vertical-align: middle;
}
<script src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.1.0/bootstrap.min.js"></script>

<div class="container container-table">
    <div class="row vertical-center-row">
        <div class="text-center col-md-4 col-md-offset-4" style="background:red">TEXT</div>
    </div>
</div>

It's a simple example of a horizontally and vertically div centered in all screen sizes.

2 of 16
63

CSS:

html,
body {
    height: 100%;
}

.container {
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

HTML:

<div class="container">
  <div>
    example
  </div>
</div>

Example fiddle

🌐
GeeksforGeeks
geeksforgeeks.org › bootstrap › how-to-set-column-in-center-using-bootstrap-5
How to set column in center using Bootstrap? - GeeksforGeeks
July 15, 2025 - To center a column using Bootstrap's flexbox utilities, apply d-flex justify-content-center to the column's parent, creating a flex container with content centered horizontally, thus centering the column within it.
🌐
freeCodeCamp
forum.freecodecamp.org › html-css
How do I center an 8 column Div in Bootstrap - HTML-CSS - The freeCodeCamp Forum
May 27, 2020 - I’m new to Bootstrap and frankly my CSS isn’t fabulous, so apologies for the possible stupid question. I’m trying to center an entire DIV of 8 columns on a page. (Responsive) How is that done? | | I’ve seen align-text-centre but that works with the text in the actual div, it doesn’t ...
Find elsewhere
🌐
Bootstrap
getbootstrap.com › docs › 5.3 › layout › columns
Columns · Bootstrap v5.3
<div class="container text-center"> <div class="row align-items-center"> <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>
🌐
GeeksforGeeks
geeksforgeeks.org › bootstrap › how-to-center-a-div-with-the-mx-auto-class-in-bootstrap-5
How to Center a Div with the mx-auto Class in Bootstrap 5 ? - GeeksforGeeks
February 8, 2024 - To center a div with the mx-auto class in Bootstrap 5, place the div within a container element and apply the mx-auto class to it. This approach utilizes the mx-auto class's automatic horizontal margin setting, which centers the element within ...
🌐
MDBootstrap
mdbootstrap.com › standard › horizontal alignment
Bootstrap Horizontal alignment - free examples & tutorial
By using flexbox you can center the entire the column of the grid. ... <!--Grid row--> <div class="row d-flex justify-content-center"> <!--Grid column--> <div class="col-md-6"> This column is centered </div> <!--Grid column--> </div> <!--Grid row-->
🌐
MDB
mdbootstrap.com › standard › how to center div vertically and horizontally
How to center div vertically and horizontally - code helpers
Add .justify-content-center to the parent element to center its content horizontally. ... <div class="d-flex align-items-center justify-content-center" style="height: 250px;"> <div class="p-2 m-2 bg-info text-white shadow rounded-2">Flex item</div> ...
🌐
Bootstrap Studio Forum
forum.bootstrapstudio.io › tips and tricks
Center div in div horizontally - Tips and Tricks - Bootstrap Studio Forum
October 11, 2021 - I would like to achieve the following: I would like to place text over an image, in such a way that the text is centered on image both horizontally and vertically. I tried this with Flexbox, but failed miserably. Who ca…
🌐
MDB
mdbootstrap.com › standard › how to center div
How to Center div
The outer div uses d-flex, justify-content-center, and align-items-center to center its content.
🌐
Tutorial Republic
tutorialrepublic.com › faq › how-to-vertical-align-a-div-in-bootstrap.php
How to Vertical Align a DIV in Bootstrap
In Bootstrap 4, if you want to vertically align a <div> element in the center or middle, you can simply apply the class align-items-center on the containing element.
🌐
Squash
squash.io › how-to-center-a-div-in-a-bootstrap-responsive-page
How to Center a Div in a Bootstrap Responsive Page
October 6, 2023 - Another method to center a div in a Bootstrap responsive page is by using CSS margin: auto.
🌐
Quora
quora.com › How-would-you-go-about-centering-the-content-of-a-div-using-Bootstrap
How would you go about centering the content of a div using Bootstrap? - Quora
Answer: Whether you are using bootstrap or not is irrelevant. It's just basic CSS. Centre text in a div - text-align:center. Centre an image or anything else in a div - margin: 0 auto; display:block;
🌐
AZMIND
azmind.com › home › tutorials › bootstrap 4: how to center align a “div” or “form” vertically and horizontally
Bootstrap 4: Align a Div or Form Vertically and Horizontally | AZMIND
June 11, 2019 - So, in a few words, we want to align the div with the class “div-to-align” in the center of its parent div which has the class “div-wrapper”. The parent div has a fixed height of 200 pixels (set with CSS).
🌐
W3Resource
w3resource.com › twitter-bootstrap › center-a-div.php
Center a Div, Twitter Bootstrap 3 | w3resource
August 19, 2022 - <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Center a Div in Twitter Bootstrap 3</title> <!-- Bootstrap --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> <style type="text/css"> .center-block { width:250px; padding:10px; background-color:#eceadc; color:#ec8007 } </style> <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries --> <!-- WARNING: Respond.js doesn't work if
🌐
Bootstrap Shuffle
bootstrapshuffle.com › classes › flexbox › align-content-*-center
align-content-*-center - Bootstrap CSS class
</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 · Flex item · Flex item · Flex item · Flex item · Flex item · Flex item · Flex item · Flex item · Flex item · Flex item · Flex item · Flex item · Flex item · Flex item · You don't need to remember all CSS classes. Just use the Bootstrap Editor instead.