The 12 column grid can be used for aligning components and assisting in responsive behavior. It is not intended to be the only solution for aligning components. See the Layouts section for the most common example of layouts using the grid.
Grid systems are used for creating page layouts through a series of rows and columns that house your content. Here’s how the Bootstrap grid system works:
Rows must be placed within a .container (fixed-width) or .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 grid classes like .row and .col-xs-4 are available for quickly making grid layouts. Less mixins can also be used for more semantic 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 .rows.
The negative margin is why the examples below are outdented. It's so that content within grid columns is lined up with non-grid content.
Grid columns are created by specifying the number of twelve available columns you wish to span. For example, three equal columns would use three .col-xs-4.
If more than 12 columns are placed within a single row, each group of extra columns will, as one unit, wrap onto a new line.
Grid classes apply to devices with screen widths greater than or equal to the breakpoint sizes, and override grid classes targeted at smaller devices. Therefore, e.g. applying any .col-md-* class to an element will not only affect its styling on medium devices but also on large devices if a .col-lg-* class is not present.
Mobile First
Use bootstrap’s mobile-first flexbox grid to build layouts of all shapes and sizes thanks to a twelve column system, with five default responsive tiers.
col-sm-1
col-sm-1
col-sm-1
col-sm-1
col-sm-1
col-sm-1
col-sm-1
col-sm-1
col-sm-1
col-sm-1
col-sm-1
col-sm-1
col-sm-2
col-sm-2
col-sm-2
col-sm-2
col-sm-2
col-sm-2
col-sm-3
col-sm-3
col-sm-3
col-sm-3
col-sm-4
col-sm-4
col-sm-4
col-sm-6
col-sm-6
Stacked-to-Horizontal
Using a single set of .col-md-* grid classes, you can create a basic grid system that starts out stacked on mobile devices and tablet devices (the extra small to small range) before becoming horizontal on desktop (medium) devices. Place grid columns in any .row.
col-md-1
col-md-1
col-md-1
col-md-1
col-md-1
col-md-1
col-md-1
col-md-1
col-md-1
col-md-1
col-md-1
col-md-1
col-md-8
col-md-4
col-md-4
col-md-4
col-md-4
col-md-6
col-md-6
Mobile and Desktop
Don’t want your columns to simply stack in smaller devices? Use the extra small and medium device grid classes by adding .col-xs-* .col-md-* to your columns. See the example below for a better idea of how it all works.