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
🌐
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.
Discussions

css - In a bootstrap responsive page how to center a div - Stack Overflow
I need to create a responsive page using bootstrap by position a div at the centre of a page as like in the below mentioned layout. More on stackoverflow.com
🌐 stackoverflow.com
How do I center an 8 column Div in Bootstrap
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 ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
0
0
May 27, 2020
Center div in div horizontally - Tips and Tricks - Bootstrap Studio Forum
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 can help me? What is the easiest way to do this? Is the Flex module the right one? More on forum.bootstrapstudio.io
🌐 forum.bootstrapstudio.io
0
October 11, 2021
How to center a div in Bootstrap 4? - HTML & CSS - SitePoint Forums | Web Development & Design Community
Hello! I am developing a “one-page website”. As you can see on the picture bellow, the first two div is centered and the third one is not. The strange thing is that I am using pretty much the same code on the last two but different results are generated, I am using Flexbox. More on sitepoint.com
🌐 sitepoint.com
0
June 24, 2017
🌐
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.
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-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 ...
🌐
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>
🌐
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> ...
Find elsewhere
🌐
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>
🌐
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 ...
🌐
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.
🌐
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.
🌐
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…
🌐
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.
🌐
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.
🌐
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.
🌐
SitePoint
sitepoint.com › html & css
How to center a div in Bootstrap 4? - HTML & CSS - SitePoint Forums | Web Development & Design Community
June 24, 2017 - Hello! I am developing a “one-page website”. As you can see on the picture bellow, the first two div is centered and the third one is not. The strange thing is that I am using pretty much the same code on the last two b…
🌐
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!
🌐
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;
🌐
Bootstrap
getbootstrap.com › docs › 4.0 › utilities › flex
Flex · Bootstrap
Choose from the same options as align-items: start, end, center, baseline, or stretch (browser default). ... <div class="align-self-start">Aligned flex item</div> <div class="align-self-end">Aligned flex item</div> <div class="align-self-center">Aligned flex item</div> <div class="align-self-baseline">Aligned flex item</div> <div class="align-self-stretch">Aligned flex item</div>
🌐
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