Grid System

Use our powerful mobile-first flexbox grid to build layouts of all shapes and sizes thanks to a twelve column system, five default responsive tiers, Sass variables and mixins, and dozens of predefined classes.

How it works

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.

New to or unfamiliar with flexbox?Read this CSS Tricks flexbox guide for background, terminology, guidelines, and code snippets.

One of three columns
One of three columns
One of three columns
          
              <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.

Breaking it down, here’s how it works:

  • 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.
  • In a grid layout, content must be placed within columns and only columns may be immediate children of rows.
  • Thanks to flexbox, grid columns without a specified width will automatically layout as equal width columns. For example, four instances of .col-sm will each automatically be 25% wide from the small breakpoint and up. See the auto-layout columns section for more examples.
  • Column classes indicate the number of columns you’d like to use out of the possible 12 per row. So, if you want three equal-width columns across, you can use .col-4.
  • Column widths are set in percentages, so they’re always fluid and sized relative to their parent element.
  • Columns have horizontal padding to create the gutters between individual columns, however, you can remove the margin from rows and padding from columns with .no-gutters on the .row.
  • To make the grid responsive, there are five grid breakpoints, one for each responsive breakpoint: all breakpoints (extra small), small, medium, large, and extra large.
  • Grid breakpoints are based on minimum width media queries, meaning they apply to that one breakpoint and all those above it (e.g., .col-sm-4 applies to small, medium, large, and extra large devices, but not the first xs breakpoint).
  • You can use predefined grid classes (like .col-4) or Sass mixins for more semantic markup.

Be aware of the limitations and bugs around flexbox, like the inability to use some HTML elements as flex containers.

Grid Options

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 widthNone (auto)540px720px960px1140px
Class prefix.col-.col-sm-.col-md-.col-lg-.col-xl-
# of columns12
Gutter width30px (15px on each side of a column)
NestableYes
Column orderingYes
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 xs to 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>
          
        

Equal-width columns can be broken into multiple lines, but there was a Safari flexbox bug that prevented this from working without an explicit flex-basis or border. There are workarounds for older browser versions, but they shouldn’t be necessary if you’re up-to-date.

Column
Column
Column
Column
          
              <div class="container">
                  <div class="row">
                      <div class="col">Column</div>
                      <div class="col">Column</div>
                      <div class="w-100"></div>
                      <div class="col">Column</div>
                      <div class="col">Column</div>
                  </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*-auto classes 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>
          
        
Equal-width multi-row

Create equal-width columns that span multiple rows by inserting a .w-100 where you want the columns to break to a new line. Make the breaks responsive by mixing the .w-100 with some responsive display utilities.

col
col
col
col
          
              <div class="row">
                  <div class="col">col</div>
                  <div class="col">col</div>
                  <div class="w-100"></div>
                  <div class="col">col</div>
                  <div class="col">col</div>
              </div>