Skip to main content

Grid system

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

Idea React provides the Container, Row, and Col wrappers for these examples. Pass fluid or breakpoint to Container, use the cols and breakpoint props on Row, and use the span, sm, md, lg, xl, and 2xl props on Col.

Example

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 explanation for how the grid system comes together.

Column
Column
Column

The above example creates three equal-width columns across all devices and viewports using our predefined grid classes. Those columns are centered in the page with the parent .container.

How it works

Breaking it down, here's how the grid system comes together:

  • Our grid supports six responsive breakpoints. Breakpoints are based on min-width media queries, meaning they affect that breakpoint and all those above it (e.g., .sm:col-4 applies to sm, md, lg, xl, and 2xl). This means you can control container and column sizing and behavior by each breakpoint.

  • Containers center and horizontally pad your content. Use .container for a responsive pixel width, .container-fluid for width: 100% across all viewports and devices, or a responsive container (e.g., .md:container) for a combination of fluid and pixel widths.

  • 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 to ensure the content in your columns is visually aligned down the left side. Rows also support modifier classes to uniformly apply column sizing and gutter classes to change the spacing of your content.

  • Columns are incredibly flexible. There are 12 template columns available per row, allowing you to create different combinations of elements that span any number of columns. Column classes indicate the number of template columns to span (e.g., col-4 spans four). widths are set in percentages so you always have the same relative sizing.

  • Gutters are also responsive and customizable. Gutter classes are available across all breakpoints, with all the same sizes as our margin and padding utilities. Change horizontal gutters with .gx-* classes, vertical gutters with .gy-*, or all gutters with .g-* classes. .g-0 is also available to remove gutters.

  • Sass variables, maps, and mixins power the grid. If you don't want to use the predefined grid classes in Bootstrap, you can use our grid's source Sass to create your own with more semantic markup. We also include some CSS custom properties to consume these Sass variables for even greater flexibility for you.

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

Grid options

Bootstrap's grid system can adapt across all six default breakpoints, and any breakpoints you customize. The six default grid tiers are as follows:

  • Extra small (xs)
  • Small (sm)
  • Medium (md)
  • Large (lg)
  • Extra large (xl)
  • Extra extra large (2xl)

As noted above, each of these breakpoints have their own container, unique class prefix, and modifiers. Here's how the grid changes across these breakpoints:

xs
<576px
sm
≥576px
md
≥768px
lg
≥1024px
xl
≥1280px
2xl
≥1536px
Container max-widthNone (auto)540px720px960px1200px1440px
Class prefix.col-.sm:col-.md:col-.lg:col-.xl:col-.2xl:col-
# of columns12
Gutter width1.5rem (.75rem on left and right)
Custom guttersYes
NestableYes
Column orderingYes

Auto-layout columns

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

Equal-width

For example, here are two grid layouts that apply to every device and viewport, from xs to 2xl. 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

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, 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

Variable width content

Use the auto value on a breakpoint prop 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

Responsive classes

Bootstrap's grid includes six 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.

All breakpoints

For grids that are the same from the smallest of devices to the largest, use the span prop or leave it out for an equal-width column.

col
col
col
col
col-8
col-4

Stacked to horizontal

Using a single set of sm props, you can create a basic grid system that starts out stacked and becomes horizontal at the small breakpoint (sm).

sm:col-8
sm:col-4
sm:col
sm:col
sm:col

Mix and match

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

.md:col-8

.col-6 .md:col-4

.col-6 .md:col-4

.col-6 .md:col-4

.col-6 .md:col-4

.col-6
.col-6

Row columns

Use the responsive .row-cols-* classes to quickly set the number of columns that best render your content and layout. Whereas normal .col-* classes apply to the individual columns (e.g., .md:col-4), the row columns classes are set on the parent Row as a shortcut; pass cols, sm, md, lg, xl, or 2xl to it. With cols="auto" you can give the columns their natural width.

Column
Column
Column
Column
Column
Column
Column
Column
Column
Column
Column
Column
Column
Column
Column
Column

Nesting

To nest your content with the default grid, add a new Row and set of columns within an existing column. Nested rows should include a set of columns that add up to 12 or fewer (it is not required that you use all 12 available columns).

Level 1: .sm:col-3

Level 2: .col-8 .sm:col-6

Level 2: .col-4 .sm:col-6

CSS

When using Bootstrap's source Sass files, you have the option of using Sass variables and mixins to create custom, semantic, and responsive page layouts. Our predefined grid classes use these same variables and mixins to provide a whole suite of ready-to-use classes for fast responsive layouts.

The grid uses $grid-columns, $grid-gutter-x, $grid-gutter-y, and $grid-row-columns together with the breakpoint and container width maps. See the upstream grid CSS for the complete Sass variable and mixin reference.