Bootstrap Basic Grid System

Bootstrap grid system, the way to create responsive website layouts. Bootstrap has bunch of classes that support grid layouts in the form of row and columns to organize page contents. Bootstrap grid system enables to create layout for different types of devices like mobile, tablets, laptops and desktops etc. Bootstrap's grid system supports up to 12 columns across the page.

The .col-xs-* class is used to create grid columns for extra small devices like mobile. The .col-sm-* class is used for small screen devices like tablets. The .col-md-* class is used for medium size devices like desktops. The .col-lg-* class is used for large devices like desktops.

You can apply multiple classes to create dynamic grid system which supports multiple devices for example - if you apply .col-xs-* and .col-md-* classes, it will support two different devices, medium devices(md) and small devices(xs).

The below table demonstrates some of the key features of the new grid system

Features Extra small devices
Phones
Small devices
Tablets
Medium devices
Desktops
Large devices
Desktops
Max container width < 768px >= 768px >= 992px >= 1200px
Grid behavior Horizontal at all times Collapsed to start, horizontal above breakpoints
Class Name .col-xs-* .col-sm-* .col-md-* .col-lg-*
Max column width Auto ~62px ~81px ~97px
Gutter width 15px on each side of a column (i.e. 30px)

Bootstrap Grid Basic Structure

The below code demonstrates the basic structure of a Bootstrap grid:

<div class="row">
  <div class="col-*-*"></div>
  <div class="col-*-*"></div>
  <div class="col-*-*"></div>
</div>

In the above code, create a row using <div class="row">. Next, add the required number of columns using <div class="col-*-*"></div>. Remember that, number of columns in each row could be up to 12.

Four Equal Columns

<div class="row">
	<div class="col-sm-3">Column 3 Span</div><div class="col-sm-3">Column 3 Span</div>
	<div class="col-sm-3">Column 3 Span</div><div class="col-sm-3">Column 3 Span</div>
</div>
See Live Example

The above code example will produce below output:

Column 4 Column 4 Column 4 Column 4

Three UnEqual Columns

<div class="row">
	<div class="col-sm-4">Column 4 Span</div><div class="col-sm-3">Column 3 Span</div><div class="col-sm-5">Column 5 Span</div>
</div>
See Live Example

The above code example will produce below output:

Column 4 Column 3 Column 5

Single Column

<div class="row">
	<div class="col-sm-12">Column 12 Span</div>
</div>
See Live Example

The above code example will produce below output:

Column 12