Grid options

Bootstrap’s grid system uses a series of containers, rows, and columns to layout and align content. It’s built with flexbox and is fully responsive. Below is an example and an in-depth look at how the grid comes together.

While Bootstrap uses ems or rems for defining most sizes, pxs are used for grid breakpoints and container widths. This is because the viewport width is in pixels and does not change with the font size.

See how aspects of the Bootstrap grid system work across multiple devices with a handy table.

Extra small
<576px
Small
≥576px
Medium
≥768px
Large
≥992px
Extra large
≥1200px
Max container width None (auto) 540px 720px 960px 1140px
Class prefix .col- .col-sm- .col-md- .col-lg- .col-xl-
# of columns 12
Gutter width 30px (15px on each side of a column)
Nestable Yes
Column ordering Yes

Auto-layout columns

Utilize breakpoint-specific column classes for easy column sizing without an explicit numbered class like .col-sm-6.

Equal-width

For example, here are two grid layouts that apply to every device and viewport, from xsto xl. Add any number of unit-less classes for each breakpoint you need and every column will be the same width.

1 of 2
2 of 2
1 of 3
2 of 3
3 of 3
<div class="container">                                                                  <div class="row">                                                                   <div class="col">                                                                   1 of 2                                                                </div>                                                                    <div class="col">                                                                   2 of 2                                                                </div>                                                                  </div>                                                            <div class="row">                                                                   <div class="col">                                                                   1 of 3                                                                </div>                                                                    <div class="col">                                                                   2 of 3                                                                </div>                                                                    <div class="col">                                                                   3 of 3                                                                </div>                                                                  </div>                                                          </div>

Setting one column width

Auto-layout for flexbox grid columns also means you can set the width of one column and have the sibling columns automatically resize around it. You may use predefined grid classes (as shown below), grid mixins, or inline widths. Note that the other columns will resize no matter the width of the center column.

1 of 3
2 of 3 (wider)
3 of 3
1 of 3
2 of 3 (wider)
3 of 3
<div class="container">                                                                 <div class="row">                                                                   <div class="col">                                                                   1 of 3                                                                </div>                                                                    <div class="col-6">                                                                 2 of 3 (wider)                                                                </div>                                                                    <div class="col">                                                                   3 of 3                                                                </div>                                                                  </div>                                                            <div class="row">                                                                   <div class="col">                                                                   1 of 3                                                                </div>                                                                    <div class="col-5">                                                                 2 of 3 (wider)                                                                </div>                                                                    <div class="col">                                                                   3 of 3                                                                </div>                                                                  </div>                                                          </div>

Variable width content

Use col-{breakpoint}-autoclasses to size columns based on the natural width of their content.

1 of 3
Variable width content
3 of 3
1 of 3
Variable width content
3 of 3
<div class="container">                                                                <div class="row justify-content-md-center">                                                                 <div class="col col-lg-2">                                                                  1 of 3                                                                </div>                                                                    <div class="col-md-auto">                                                                   Variable width content                                                                </div>                                                                    <div class="col col-lg-2">                                                                  3 of 3                                                                </div>                                                                  </div>                                                            <div class="row">                                                                   <div class="col">                                                                   1 of 3                                                                </div>                                                                    <div class="col-md-auto">                                                                   Variable width content                                                                </div>                                                                    <div class="col col-lg-2">                                                                  3 of 3                                                                </div>                                                                  </div>                                                          </div>

Responsive classes

Bootstrap’s grid includes five tiers of predefined classes for building complex responsive layouts. Customize the size of your columns on extra small, small, medium, large, or extra large devices however you see fit.

Stacked to horizontal

Don’t want your columns to simply stack in some grid tiers? Use a combination of different classes for each tier as needed. See the example below for a better idea of how it all works.

.col-12 .col-md-8
.col-6 .col-md-4
.col-6 .col-md-4
.col-6 .col-md-4
.col-6 .col-md-4
.col-6
.col-6
<!-- Stack the columns on mobile by making one full-width and the other half-width -->                                                  <div class="row">                                                   <div class="col-12 col-md-8">.col-12 .col-md-8</div>                                                        <div class="col-6 col-md-4">.col-6 .col-md-4</div>                                                        </div>                                                    <!-- Columns start at 50% wide on mobile and bump up to 33.3% wide on desktop -->                                                 <div class="row">                                                   <div class="col-6 col-md-4">.col-6 .col-md-4</div>                                                          <div class="col-6 col-md-4">.col-6 .col-md-4</div>                                                          <div class="col-6 col-md-4">.col-6 .col-md-4</div>                                                        </div>                                                    <!-- Columns are always 50% wide, on mobile and desktop -->                                                       <div class="row">                                                   <div class="col-6">.col-6</div>                                                     <div class="col-6">.col-6</div>                                                   </div>

Alignment

Use flexbox alignment utilities to vertically and horizontally align columns.

Vertical alignment

One of three columns
One of three columns
One of three columns
One of three columns
One of three columns
One of three columns
One of three columns
One of three columns
One of three columns
<div class="container">                                                         <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 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 class="row align-items-end">                                                           <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>

Horizontal alignment

One of two columns
One of two columns
One of two columns
One of two columns
One of two columns
One of two columns
One of two columns
One of two columns
One of two columns
One of two columns
<div class="container">                                                                <div class="row justify-content-start">                                                             <div class="col-4">                                                                 One of two columns                                                                    </div>                                                                    <div class="col-4">                                                                 One of two columns                                                                    </div>                                                                  </div>                                                            <div class="row justify-content-center">                                                                    <div class="col-4">                                                                 One of two columns                                                                    </div>                                                                    <div class="col-4">                                                                 One of two columns                                                                    </div>                                                                  </div>                                                            <div class="row justify-content-end">                                                               <div class="col-4">                                                                 One of two columns                                                                    </div>                                                                    <div class="col-4">                                                                 One of two columns                                                                    </div>                                                                  </div>                                                            <div class="row justify-content-around">                                                                    <div class="col-4">                                                                 One of two columns                                                                    </div>                                                                    <div class="col-4">                                                                 One of two columns                                                                    </div>                                                                  </div>                                                            <div class="row justify-content-between">                                                                   <div class="col-4">                                                                 One of two columns                                                                    </div>                                                                    <div class="col-4">                                                                 One of two columns                                                                    </div>                                                                  </div>                                                          </div>

No gutters

The gutters between columns in our predefined grid classes can be removed with .no-gutters. This removes the negative margins from .rowand the horizontal paddingfrom all immediate children columns.

Here’s the source code for creating these styles. Note that column overrides are scoped to only the first children columns and are targeted via attribute selector. While this generates a more specific selector, column padding can still be further customized with spacing utilities.

Need an edge-to-edge design?Drop the parent .containeror .container-fluid.

.no-gutters {                                                               margin-right: 0;                                                                margin-left: 0;                                                                 >.col,                                                                  >[class*="col-"] {                                                                padding-right: 0;                                                               padding-left: 0;                                                              }                                                             }

In practice, here’s how it looks. Note you can continue to use this with all other predefined grid classes (including column widths, responsive tiers, reorders, and more).

.col-12 .col-sm-6 .col-md-8
.col-6 .col-md-4
                                                             <div class="row no-gutters">                                                                <div class="col-12 col-sm-6 col-md-8">.col-12 .col-sm-6 .col-md-8</div>                                                             <div class="col-6 col-md-4">.col-6 .col-md-4</div>                                                                </div>

Column breaks

Breaking columns to a new line in flexbox requires a small hack: add an element with width: 100%wherever you want to wrap your columns to a new line. Normally this is accomplished with multiple .rows, but not ever implementation method can account for this.

.col-6 .col-sm-3
.col-6 .col-sm-3
.col-6 .col-sm-3
.col-6 .col-sm-3
<div class="row">                                                                <div class="col-6 col-sm-3">.col-6 .col-sm-3</div>                                                                  <div class="col-6 col-sm-3">.col-6 .col-sm-3</div>                                                                  <!-- Force next columns to break to new line -->                                                                  <div class="w-100"></div>                                                           <div class="col-6 col-sm-3">.col-6 .col-sm-3</div>                                                                  <div class="col-6 col-sm-3">.col-6 .col-sm-3</div>                                                                </div>

Reordering

Order classes

Use .order-classes for controlling the visual orderof your content. These classes are responsive, so you can set the orderby breakpoint (e.g., .order-1.order-md-2). Includes support for 1through 12across all five grid tiers.

First, but unordered
Second, but last
Third, but first
<div class="container">                                                           <div class="row">                                                                   <div class="col">                                                                   First, but unordered                                                                  </div>                                                                    <div class="col order-12">                                                                  Second, but last                                                              </div>                                                                    <div class="col order-1">                                                                   Third, but first                                                              </div>                                                                  </div>                                                          </div>

There’s also a responsive .order-firstclass that quickly changes the order of one element by applying order: -1. This class can also be intermixed with the numbered .order-*classes as needed.

First, but unordered
Second, but unordered
Third, but first
<div class="container">                                                            <div class="row">                                                                   <div class="col">                                                                   First, but unordered                                                                  </div>                                                                    <div class="col">                                                                   Second, but unordered                                                                 </div>                                                                    <div class="col order-first">                                                               Third, but first                                                              </div>                                                                  </div>                                                          </div>

Offsetting columns

You can offset grid columns in two ways: our responsive .offset- grid classes and our margin utilities. Grid classes are sized to match columns while margins are more useful for quick layouts where the width of the offset is variable.

Offset classes

Move columns to the right using .offset-md-*classes. These classes increase the left margin of a column by *columns. For example, .offset-md-4moves .col-md-4over four columns.

.col-md-4
.col-md-4 .offset-md-4
.col-md-3 .offset-md-3
.col-md-3 .offset-md-3
.col-md-6 .offset-md-3
<div class="row">                                                               <div class="col-md-4">.col-md-4</div>                                                               <div class="col-md-4 offset-md-4">.col-md-4 .offset-md-4</div>                                                            </div>                                                            <div class="row">                                                           <div class="col-md-3 offset-md-3">.col-md-3 .offset-md-3</div>                                                              <div class="col-md-3 offset-md-3">.col-md-3 .offset-md-3</div>                                                            </div>                                                            <div class="row">                                                           <div class="col-md-6 offset-md-3">.col-md-6 .offset-md-3</div>                                                            </div>

Margin utilities

With the move to flexbox in v4, you can use margin utilities like .mr-autoto force sibling columns away from one another.

.col-md-4
.col-md-4 .ml-auto
.col-md-3 .ml-md-auto
.col-md-3 .ml-md-auto
.col-auto .mr-auto
.col-auto
<div class="row">                                                                 <div class="col-md-4">.col-md-4</div>                                                               <div class="col-md-4 ml-auto">.col-md-4 .ml-auto</div>                                                            </div>                                                            <div class="row">                                                           <div class="col-md-3 ml-md-auto">.col-md-3 .ml-md-auto</div>                                                                <div class="col-md-3 ml-md-auto">.col-md-3 .ml-md-auto</div>                                                              </div>                                                            <div class="row">                                                           <div class="col-auto mr-auto">.col-auto .mr-auto</div>                                                              <div class="col-auto">.col-auto</div>                                                             </div>