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, CSS custom properties, and dozens of predefined classes.
Idea React provides the Container, Row, and Col wrappers for these examples. Set fluid
to true for a full-width container or pass a breakpoint to make it responsive. Use the xs, sm,
md, lg, xl, and 2xl props on Row and 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.
The above example creates three equal-width columns across all devices and viewports using the
default Col sizing. The Container centers them in the page.
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-widthmedia queries, meaning a breakpoint prop affects that breakpoint and all those above it (e.g.,sm={4}onColapplies fromsmupward). Use responsive props to control container and column sizing and behavior. -
Containers center and horizontally pad your content. Use
Containerwith its default sizing, setfluidfor full width, or pass a breakpoint such asfluid="md"for responsive container sizing. -
Rows are wrappers for columns. Each column has horizontal
padding(called a gutter) for controlling the space between them. Thispaddingis then counteracted on the rows with negative margins to ensure the content in your columns is visually aligned down the left side. Set responsive column counts withRowprops; use gutter utilities throughclassNameto 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. Set a
Colbreakpoint prop (for examplexs={4}) to span a number of columns. Widths are set in percentages so you always have the same relative sizing. -
Gutters are also responsive and customizable. Pass gutter utilities through
Row'sclassNameto adjust horizontal, vertical, or all gutters at each breakpoint, including removing gutters entirely. -
Customize the grid with Props, utilities, and CSS custom properties. Use the layout components for semantic markup, responsive Props for column sizes, and gutter utilities for spacing. No preprocessor configuration is required.
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 | sm | md | lg | xl | 2xl | |
|---|---|---|---|---|---|---|
Container max-width | None (auto) | 540px | 720px | 960px | 1200px | 1440px |
| Class prefix | .col- | .sm:col- | .md:col- | .lg:col- | .xl:col- | .2xl:col- |
of columns | 12 | |||||
| Gutter width | 1.5rem (.75rem on left and right) | |||||
| Custom gutters | Yes | |||||
| Nestable | Yes | |||||
| Column ordering | Yes | |||||
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.
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.
Variable width content
Use the auto value on a breakpoint prop to size columns based on the natural width of their
content.
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 xs prop or leave
it out for an equal-width column.
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).
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.
Offsets and ordering
Pass a responsive object to a Col breakpoint prop to combine a column span with an offset or
visual order. Each option is independent, so you can also set only an offset or order at a
breakpoint. Order accepts a number, "first", or "last".
Row columns
Set xs, sm, md, lg, xl, or 2xl on Row to control the number of columns at each
breakpoint. This is a shortcut for setting each column's width; use xs="auto" to give columns
their natural width.
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).
CSS
Use Container, Row, and Col Props to select responsive layouts from the compiled stylesheet.
Adjust spacing with gutter utilities and scope any additional CSS custom property overrides to
your layout. See the upstream grid CSS for the underlying layout reference.