loading

BS4 Grid System

Bootstrap 4 Grid System

The grid system of Bootstrap supports a maximum of 12 columns on a page.

To make broader columns, you can group the columns together if you don’t want to use each of the 12 columns individually:

Bs4 Grid System -

Because of Bootstrap’s responsive grid technology, the columns will adjust to fit the size of the screen: Three columns of content might seem better on a large screen, but stacking the content pieces on top of one another would work better on a small one.

Grid Classes

The five classes of the Bootstrap 4 grid system are:
 
  • .col- (extra small devices – screen width less than 576px)
  • .col-sm- (small devices – screen width equal to or greater than 576px)
  • .col-md- (medium devices – screen width equal to or greater than 768px)
  • .col-lg- (large devices – screen width equal to or greater than 992px)
  • .col-xl- (xlarge devices – screen width equal to or greater than 1200px)
 
More dynamic and adaptable layouts can be made by combining the aforementioned classes.
 
Tip: Since all classes scale up, you only need to provide sm if you want to define the same widths for sm and md.

Grid System Rules

Rules for the Bootstrap 4 grid system include:

  • For correct alignment and padding, rows must be inserted into a .container (fixed-width) or .container-fluid (full-width) container.
  • To make horizontal groups of columns, use rows.
  • Columns should include content, and only columns that are directly children of rows may do so.
  • Grid layouts can be readily created using predefined classes, such as .row and .col-sm-4.
  • By using padding, columns produce gutters, or spaces between column content. Negative margin on .rows is used to counteract that padding in rows for the first and last column.
  • You can create grid columns by indicating how many of the twelve available columns you want to span. Three equal columns, for instance, would require three .col-sm-4.
  • Column widths are always flexible and sized in relation to their parent element since they are expressed as percentages.
  • The primary difference between Bootstrap 3 and Bootstrap 4 is that the latter now makes use of flexbox rather of floats. Flexbox has the significant benefit of automatically arranging grid columns without a defined width as “equal width columns” (and equal height). For instance, three components with the .col-sm suffix will all be automatically 33.33% wide when viewed from the small breakpoint upwards. Advice: Have a look at our CSS Flexbox Tutorial to understand more about Flexbox.

Note that IE9 and older versions do not support Flexbox.

Use Bootstrap 3 if you need to support IE8–9. It is the most stable version of Bootstrap, and the team continues to maintain it with important updates to the documentation and bug fixes. It won’t, however, get any new features.

Basic Structure of a Bootstrap 4 Grid

The fundamental layout of a Bootstrap 4 grid is as follows:

				
					<!-- Control the column width, and how they should appear on different devices -->
<div class="row">
  <div class="col-*-*"></div>
  <div class="col-*-*"></div>
  <div class="col-*-*"></div>
</div>

<!-- Or let Bootstrap automatically handle the layout -->
<div class="row">
  <div class="col"></div>
  <div class="col"></div>
  <div class="col"></div>
  <div class="col"></div>
</div>
				
			

Make a row (<div class=”row”>) as an example first. The desired number of columns (tags with relevant data) should then be added .col-*-* 8classes. The responsiveness—sm, md, lg, or xl—is represented by the first star (*), and a number—which should always add up to 12 for each row—is represented by the second star.

Second example: to create equal width columns, let bootstrap handle the layout rather than appending a number to each col. Each of the two “col” components has a 50% width. Three columns equals 33.33% of a col’s width. 4 cols = 25% of the width, etc. For responsive columns, you may also use .col-sm|md|lg|xl.

Grid Options

The functionality of the Bootstrap 4 grid system over a range of screen sizes is outlined in the following table:

 Extra small (<576px)Small (>=576px)Medium (>=768px)Large (>=992px)Extra Large (>=1200px)
Class prefix.col-.col-sm-.col-md-.col-lg-.col-xl-
Grid behaviourHorizontal at all timesCollapsed to start, horizontal above breakpointsCollapsed to start, horizontal above breakpointsCollapsed to start, horizontal above breakpointsCollapsed to start, horizontal above breakpoints
Container widthNone (auto)540px720px960px1140px
Suitable forPortrait phonesLandscape phonesTabletsLaptopsLaptops and Desktops
# of columns1212121212
Gutter width30px (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)30px (15px on each side of a column)
NestableYesYesYesYesYes
OffsetsYesYesYesYesYes
Column orderingYesYesYesYesYes
Share this Doc

BS4 Grid System

Or copy link

Explore Topic