bootstrap 4 grid examples
Bootstrap grid system provides a quick and convenient way to create responsive website layouts. The latest Bootstrap 4 version introduces the new mobile-first flexbox grid system that appropriately scales up to 12 columns as the device or viewport size increases.
Bootstrap 4 includes predefined grid classes for quickly making grid layouts for different types of devices like cell phones, tablets, laptops and desktops, etc. For example, you can use the .col-*
classes to create grid columns for extra small devices mobile phones in portrait mode, similarly you can use the .col-sm-*
classes to create grid columns for small screen devices like mobile phone in landscape mode, the .col-md-*
classes for medium screen devices like tablets, the .col-lg-*
classes for large devices like desktops, and the .col-xl-*
classes for extra large desktop screens.
The following table summarizes some of the key features of the new grid system.
Features
Bootstrap 4 Grid System
|
Extra small
<576px
|
Small
≥576px
|
Medium
≥768px
|
Large
≥992px
|
Extra large
≥1200px
|
---|---|---|---|---|---|
Max container width |
None (auto) | 540px | 720px | 960px | 1140px |
Ideal for |
Mobile (Portrait) | Mobile (Landscape) | Tablets | Laptops | Laptops & Desktops |
Class prefix | .col- |
.col-sm- |
.col-md- |
.col-lg- |
.col-xl- |
Number of columns | 12 | ||||
Gutter width | 30px (15px on each side of a column) | ||||
Nestable | Yes | ||||
Column ordering | Yes |
Above table demonstrates one important thing, applying any .col-sm-*
class to an element will not only affect its styling on small devices, but also on medium, large and extra large devices having screen width greater than or equal to 540px, if a .col-md-*
, .col-lg-*
or .col-xl-*
class is not present. Similarly, the .col-md-*
class will not only affect the styling of elements on medium devices, but also on large and extra large devices if a .col-lg-*
or .col-xl-
class is not present.
Now the question arises how to create rows and columns using this 12 column responsive grid system. The answer is pretty simple, at first create a container that acts as a wrapper for your rows and columns using the .container
class, after that create rows inside the container using the .row
class, and to create columns inside any row you can use the .col-*
, .col-sm-*
, .col-md-*
, .col-lg-*
and .col-xl-*
classes. The columns are actual content area where we will place our contents.
Let’s put all these things into real action. Let’s see how it actually works: