To position the content of the column div you can use the responsive versions of justify-content-* class with d-flex

<div class="row">
    <div class="col-md-4 d-flex justify-content-md-end justify-content-center">
      Email
    </div>
</div>

Just add the classes d-flex to display flex and justify-content-md-end to align at the end of the column for display md and upwards and justify-content-center to align to center for display xs and upwards.

Demo

Answer from Shiblu on Stack Overflow
🌐
Bootstrap Shuffle
bootstrapshuffle.com › classes › flexbox › justify-content-*-center
justify-content-*-center - Bootstrap CSS class
<div class="d-flex justify-content-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 justify-content-sm-center">...</div> <div class="d-flex justify-content-md-center">...</div> <div class="d-flex justify-content-lg-center">...</div> <div class="d-flex justify-content-xl-center">...</div>Copy code ... Click one of the examples listed below to open the Shuffle Visual Editor with the UI library that uses the selected component. ... You don't need to remember all CSS classes. Just use the Bootstrap Editor instead.
🌐
Educative
educative.io › answers › what-is-justify-content-in-bootstrap-4
What is justify-content in Bootstrap 4?
Lines 45–58: Using justify-content-center to align the buttons at the center of the flex-box container.
🌐
W3Schools
w3schools.com › bootstrap4 › tryit.asp
Justify content center
The W3Schools online code editor allows you to edit code and view the result in your browser
🌐
Bootstrap
getbootstrap.com › docs › 5.3 › utilities › flex
Flex · Bootstrap v5.3
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.
🌐
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.
🌐
W3Schools
w3schools.com › bootstrap4 › bootstrap_flex.asp
Bootstrap 4 Flex
Use the .justify-content-* classes to change the alignment of flex items. Valid classes are start (default), end, center, between or around:
🌐
GeeksforGeeks
geeksforgeeks.org › bootstrap › bootstrap-5-flex-justify-content
Bootstrap 5 Flex Justify Content - GeeksforGeeks
April 10, 2024 - <!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"> <link href= "https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css" rel="stylesheet"> <script src= "https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.min.js"> </script> </head> <body> <div class="container text-center "> <h1 class="text-success">GeeksforGeeks</h1> <h5>Bootstrap 5 Flex Justify content </h5> </div> <div class="d-flex justify-content-start flex-row border"> <div cl
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › Reference › Properties › justify-content
justify-content - CSS - MDN Web Docs
/* Positional alignment */ justify-content: center; justify-content: start; justify-content: end; justify-content: flex-start; justify-content: flex-end; justify-content: left; justify-content: right; /* Normal alignment */ justify-content: normal; /* Distributed alignment */ justify-content: space-between; justify-content: space-around; justify-content: space-evenly; justify-content: stretch; /* Overflow alignment (for positional alignment only)*/ justify-content: safe center; justify-content: unsafe center; /* Global values */ justify-content: inherit; justify-content: initial; justify-content: revert; justify-content: revert-layer; justify-content: unset;
Find elsewhere
🌐
Shuffle
shuffle.dev › bootstrap › classes › flexbox › justify-content-*-center
Bootstrap CSS class: justify-content-*-center - Shuffle
<div class="d-flex justify-content-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 justify-content-sm-center">...</div> <div class="d-flex justify-content-md-center">...</div> <div class="d-flex justify-content-lg-center">...</div> <div class="d-flex justify-content-xl-center">...</div>
Top answer
1 of 7
262

Bootstrap 5 (update 2021)

Since flexbox is still used the centering methods in Bootstrap 5 work the same way. Columns can be centered using offset, auto-margins or justify-content-center (flexbox).

Demo of the Bootstrap 5 Centering Methods

Bootstrap 4 (original answer)

There are multiple horizontal centering methods in Bootstrap 4...

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

mx-auto (auto x-axis margins) will center display:block or display:flex elements that have a defined width, (%, vw, px, etc..). Flexbox is used by default on grid columns, so there are also various flexbox centering methods.

Demo of the Bootstrap 4 Centering Methods

In your case, use mx-auto to center the col-3 and text-center to center it's content..

<div class="row">
    <div class="col-3 mx-auto">
        <div class="text-center">
            center
        </div>
    </div>
</div>

https://codeply.com/go/GRUfnxl3Ol

or, using justify-content-center on flexbox elements (.row):

<div class="container">
    <div class="row justify-content-center">
        <div class="col-3 text-center">
            center
        </div>
    </div>
</div>

Also see:
Vertical Align Center in Bootstrap

2 of 7
19

<div class="container">
    <div class="row">
        <div class="col d-flex justify-content-center">
             CenterContent
        </div>
    </div>
</div>

Enable 'flex' for the column as we want & use justify-content-center

Top answer
1 of 2
2

I'm not sure if you want horizontal or vertical center. The simplest way to horizontal center is to use mx-auto (auto-margins) on the inner w-75 divs...

https://www.codeply.com/go/orlziQBanZ

<div class="container">
        <div class="row align-items-center">
            <div class="col">
                <div class="w-75 mx-auto" style="background-color: grey;">
                    <form>
                        <h3>Sign In</h3>
                        <label class="sr-only" for="email">Email</label>
                        <div class="input-group mb-2 mr-sm-2">
                            <input type="email" class="form-control" id="email" placeholder="Email">
                        </div>
                        <div class="input-group mb-2 mr-sm-2">
                            <input type="email" class="form-control" id="password" placeholder="Password">
                        </div>
                        <button type="submit" class="btn btn-primary mb-2">Sign In</button>
                    </form>
                </div>
            </div>
            <div class="col-1 mx-auto">
                <h2 class="text-center">OR</h2>
            </div>
            <div class="col">
                <div class="w-75 mx-auto" style="background-color: grey;">
                    <form>
                        <h3>Sign Up</h3>
                        <label class="sr-only" for="email">Email</label>
                        <div class="input-group mb-2 mr-sm-2">
                            <input type="email" class="form-control" id="email" placeholder="Email">
                        </div>
                        <div class="input-group mb-2 mr-sm-2">
                            <input type="email" class="form-control" id="password" placeholder="Password">
                        </div>
                        <button type="submit" class="btn btn-primary mb-2">Sign Up</button>
                    </form>
                </div>
            </div>
        </div>
    </div>

The align-items-center on the row is for vertical centering.

2 of 2
1

To enable flexbox for the columns (and thus make the justify-content-center class work) you need to add the d-flex class to each column as shown in the code snippet below.

And if you only want to center text within a column like the "OR" text, then you only need the text-center class for that column.

Note: That "OR" text will squeeze out of the column when the column gets too narrow for the content to fit. So, you should use responsive column classes there and use responsive column classes for the other columns as well. Because as the screen gets smaller, you'd probably want them to stack.

Here's the code snippet (without responsive column classes i.e. based on your code):

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<section id="login">
    <div class="container">
        <div class="row">
            <div class="col d-flex justify-content-center">
                <div class="w-75" style="background-color: grey;">
                    <form>
                        <h3>Sign In</h3>
                        <label class="sr-only" for="email">Email</label>
                        <div class="input-group mb-2 mr-sm-2">
                            <input type="email" class="form-control" id="email" placeholder="Email">
                        </div>
                        <div class="input-group mb-2 mr-sm-2">
                            <input type="email" class="form-control" id="password" placeholder="Password">
                        </div>
                        <button type="submit" class="btn btn-primary mb-2">Sign In</button>
                    </form>
                </div>
            </div>
            <div class="col-2 text-center" style="background-color: grey;">
                <h2>OR</h2>
            </div>
            <div class="col d-flex justify-content-center">
                <div class="w-75" style="background-color: grey;">
                    <form>
                        <h3>Sign Up</h3>
                        <label class="sr-only" for="email">Email</label>
                        <div class="input-group mb-2 mr-sm-2">
                            <input type="email" class="form-control" id="email" placeholder="Email">
                        </div>
                        <div class="input-group mb-2 mr-sm-2">
                            <input type="email" class="form-control" id="password" placeholder="Password">
                        </div>
                        <button type="submit" class="btn btn-primary mb-2">Sign Up</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</section>    

🌐
Bootstrap
getbootstrap.com › docs › 5.3 › layout › columns
Columns · Bootstrap v5.3
<div class="container text-center"> <div class="row"> <div class="col align-self-start"> One of three columns </div> <div class="col align-self-center"> One of three columns </div> <div class="col align-self-end"> One of three columns </div> </div> </div> Change the horizontal alignment with any of the responsive justify-content-* classes.
🌐
TutorialsPoint
tutorialspoint.com › Bootstrap-4-justify-content-center-class
Bootstrap 4 .justify-content-*-center class
June 18, 2020 - Use the justify-content-*-center class in Bootstrap 4 to center content on different screen sizes. For different screen sizes − justify-content-sm-center: Small Screen Size
🌐
FastBootstrap
fastbootstrap.com › docs › justify-content
Bootstrap Justify Content CSS - FastBootstrap
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.
🌐
Shuffle
shuffle.dev › bootstrap › classes › flexbox › justify-content-md-center
Bootstrap CSS class: justify-content-md-center - Shuffle
<div class="d-flex flex-wrap justify-content-md-center bg-secondary" style="height: 50px;"> <div class="px-4 bg-primary"></div> <div class="px-4 bg-info"></div> <div class="px-4 bg-primary"></div> <div class="px-4 bg-info"></div> <div class="px-4 bg-primary"></div> <div class="px-4 bg-info"></div> </div>
🌐
Bootstrap
getbootstrap.com › docs › 4.0 › utilities › flex
Flex · Bootstrap
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, or around.
🌐
Bootstrap Shuffle
bootstrapshuffle.com › classes › flexbox › justify-content-*-between
justify-content-*-between - Bootstrap CSS class
Just use the Bootstrap Editor instead. flex-*-nowrap · flex-*-column · flex-*-row · flex-*-row-reverse · flex-*-column-reverse · flex-*-wrap-reverse · flex-*-grow-1 · flex-*-grow-0 · flex-*-shrink-1 · flex-*-shrink-0 · flex-*-wrap · justify-content-*-start · flex-fill · justify-content-*-end · justify-content-*-center ·
🌐
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>