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.
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
Breaking it down, here’s how it works:
.containerfor a responsive pixel width or
width: 100%across all viewport and device sizes.
padding(called a gutter) for controlling the space between them. This
paddingis then counteracted on the rows with negative margins. This way, all the content in your columns is visually aligned down the left side.
widthwill automatically layout as equal width columns. For example, four instances of
.col-smwill each automatically be 25% wide from the small breakpoint and up. See the auto-layout columns section for more examples.
widths are set in percentages, so they’re always fluid and sized relative to their parent element.
paddingto create the gutters between individual columns, however, you can remove the
marginfrom rows and
paddingfrom columns with
.col-sm-4applies to small, medium, large, and extra large devices, but not the first
.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.
While Bootstrap uses
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.
|Max container width||None (auto)||540px||720px||960px||1140px|
|# of columns||12|
|Gutter width||30px (15px on each side of a column)|