Bootstrap Grid System
Bootstrap Grid System
Bootstrap's grid system allows up to 12 columns across the page.
If you do not want to use all 12 column individually, you can group the columns together to create wider columns:
|span 1||span 1||span 1||span 1||span 1||span 1||span 1||span 1||span 1||span 1||span 1||span 1|
|span 4||span 4||span 4|
|span 4||span 8|
|span 6||span 6|
Bootstrap's grid system is responsive, and the columns will re-arrange depending on the screen size: On a big screen it might look better with the content organized in three columns, but on a small screen it would be better if the content items were stacked on top of each other.
Tip: Remember that grid columns should add up to twelve for a row. More than that, columns will stack no matter the viewport.
The Bootstrap grid system has four classes:
xs(for phones - screens less than 768px wide)
sm(for tablets - screens equal to or greater than 768px wide)
md(for small laptops - screens equal to or greater than 992px wide)
lg(for laptops and desktops - screens equal to or greater than 1200px wide)
The classes above can be combined to create more dynamic and flexible layouts.
Tip: Each class scales up, so if you wish to set the same widths for xs and sm, you only need to specify xs.
Grid System Rules
Some Bootstrap grid system rules:
- Rows must be placed within a
.container-fluid(full-width) for proper alignment and padding
- Use rows to create horizontal groups of columns
- Content should be placed within columns, and only columns may be immediate children of rows
- Predefined classes like
.col-sm-4are available for quickly making grid layouts
- Columns create gutters (gaps between column content) via padding. That padding is offset in rows for the first and last column via negative margin on
- Grid columns are created by specifying the number of 12 available columns you wish to span. For example, three equal columns would use three
- Column widths are in percentage, so they are always fluid and sized relative to their parent element
Basic Structure of a Bootstrap Grid
The following is a basic structure of a Bootstrap grid:
So, to create the layout you want, create a container (
class="container">). Next, create a row (
class="row">). Then, add the desired number of columns (tags with appropriate
.col-*-* classes). Note that numbers in
.col-*-* should always add up to 12 for each row.
So for the first row in
our example above, the markup defines a <div> with class
.col-sm-12, which is going to take up twelve
columns of space (100% of the width).
The next row specifies three columns; Bootstrap lines these up next to each other, where
about 33.3% of the width (33.3% + 33.3% + 33.3%).
In our third row, we have added one extra class to each column (
.col-lg-3). This means that when the page is viewed on a larger screen it should
split the column width to 75% (
.col-lg-9) and 25% (
As we also have specified the small classes, the columns will split to 66% (
and 33% (
.col-sm-4) for small AND medium screens (scales up). This is useful for re-arranging
the layout for
different screen sizes.
The following table summarizes how the Bootstrap grid system works across multiple devices:
|Suitable for||Phones||Tablets||Small Laptops||Laptops & Desktops|
|Grid behaviour||Horizontal at all times||Collapsed to start, horizontal above breakpoints||Collapsed to start, horizontal above breakpoints||Collapsed to start, horizontal above breakpoints|
|Container width||None (auto)||750px||970px||1170px|
|# of columns||12||12||12||12|
|Gutter width||30px (15px on each side of a column)||30px (15px on each side of a column)||30px (15px on each side of a column)||30px (15px on each side of a column)|
The next chapters shows examples of grid systems for different devices: