Bootstrap 4 Grid System

Bootstrap 4 Grid Systems

Bootstrap offers a responsive and mobile-first grid system with the help of which we can divide the screen of the web browser into 12 horizontal parts. It has predefined classes that provide easy options for creating layouts, and it also consists of mixins that helps in creating semantic layouts.

Working of Grid System

Grid System uses several numbers of rows, columns, and containers for the alignment of content. The working of the grid system is given below:-

  • With the help of containers, we can center align the content of our website and provides horizontal padding. .container class is used for responsive pixel width, and .container-fluid class is used to cover the full width of the screen.
  • There is a predefined class .row that should be placed within the .container class as it is used to provide alignment and padding.
  • In the grid system, all contents of the site are placed within the column. Columns are the child of the rows.
  • With the help of column class .col, you can create multiple horizontal groups but not more than 12.

Grid Classes

There are five grid classes in Bootstrap 4. These are as follows:-

S.No Grid classes Definition
1. .col This class is used for small devices that have a screen size of less than 576 px.
2. .col-sm- This class can be used for both types of devices that either have a screen size of 576 px or greater than 576px.
3. .col-md- It is used for the medium size devices that either has a screen width of 768px or greater.
4. .col-lg- This class is used for the devices that contain the large size of screens, for example, 992px or greater.
5. .col-xl- This class is used for the devices that contain extra-large sized screen, for example, 1200px or greater.

Equal Width Columns

Here is the example of creating equal-width columns that supports all screen size is given below:

Example

<!DOCTYPE html> <html lang="en">
 <head>
   <title>Grid Example</title>
   <meta charset="utf-8">
   <meta name="viewport" content="width=device-width, initial-scale=1">
   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"> 
 </head>
 <body>
 <div class="container">
   <h1>Two equal width columns</h1>
   <p>This example shows two columns of equal length.</p>
   <div class="row">
     <div class="col" style="background-color: #a4a6a5; border: 2px solid black;">col 1</div>
     <div class="col" style="background-color: #a4a6a5; border: 2px solid black;">col 2</div> 
   </div>
   <h1>Three equal width columns</h1>
   <p>This example shows three columns of same width.</p>
   <div class="row">
     <div class="col" style="background-color: #a4a6a5; border: 2px solid black;">col 1</div>
     <div class="col" style="background-color: #a4a6a5; border: 2px solid black;">col 2</div>
     <div class="col" style="background-color: #a4a6a5; border: 2px solid black;">col 3</div>
   </div> 
 </div>
   <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
   <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
   <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
 </body>
 </html> 

Output

Bootstrap 4 Grid System

Unequal Width Columns

Here is the example of creating unequal-width columns that support all screen size is given below:

Example

<!DOCTYPE html>
 <html lang="en">
 <head>
   <title>Unequal Grid Example</title>
   <meta charset="utf-8">
   <meta name="viewport" content="width=device-width, initial-scale=1">
   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
 </head> 
 <body>
 <div class="container">
   <h2>Two Unequal-width Responsive Columns</h2>
   <p>When you resize the browser window you will see the effect.</p>
   <p>This grid will be automatically adjusted itself and the first column will come on top of the second column When we move the browser screen to the mobile screen size.</p>
   <div class="row">
     <div class="col-sm-4" style="background-color: #a4a6a5; border: 2px solid black;">column 1</div>
     <div class="col-sm-8" style="background-color: #a4a6a5; border: 2px solid black;">column 2</div>
   </div>
 <h2>Three Unequal-width Responsive Columns</h2>
 <p>This grid will also be automatically adjusted itself and all three columns will stack on top of each other When we move the browser screen to the mobile screen size.</p>
 <div class="row">
     <div class="col-sm-2" style="background-color: #a4a6a5; border: 2px solid black;">column 1</div>
     <div class="col-sm-4" style="background-color: #a4a6a5; border: 2px solid black;">column 2</div>
     <div class="col-sm-6" style="background-color: #a4a6a5; border: 2px solid black;">column 3</div>
 </div>
 </div> 
   <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
   <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
   <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>   
 </body>
 </html> 

Output

Bootstrap 4 Grid System

Related Topics

Bootstrap Validation Example

Validation We can provide valuable and actionable feedback to the users through an HTML form validation. It happens via custom styles or behaviors of default browsers and JavaScript. How does validation work...

4 minutes read.

Bootstrap 4 Grid System

Bootstrap 4 Grid Systems Bootstrap offers a responsive and mobile-first grid system with the help of which we can divide the screen of the web browser into 12 horizontal parts. It has predefined classes...

4 minutes read.

Difference between bootstrap.css and bootstrap-theme.css

The "bootstrap.css" uses to create a website with pre-existing designs and context. It uses basic Bootstrap classes like rows and columns with a CSS styling tool. The website is styled...

5 minutes read.

Bootstrap Contact Us page

What is a “Contact Us” page? A “Contact Us” page is a web page available on the websites of various companies, organisations etc., for its users to contact the organisation or...

5 minutes read.

Bootstrap 4 Margin classes

Bootstrap 4 contains a variety of brief, responsive margin and padding utility classes to change the appearance of an element. The Bootstrap 4 margin classes use for the outer spacing of...

8 minutes read.

Bootstrap 4 Pagination

Bootstrap 4 Pagination Bootstrap pagination is used to show the existence of a series of web pages of the website. It allows navigation on multiple pages of a website. In pagination, there is a block...

9 minutes read.

Bootstrap 4 Tooltip

Bootstrap 4 Tooltip Tooltip Bootstrap 4 offers a tooltip component, a small popup box that appears when you move the cursor over an element such as buttons or any highlighted element. It...

3 minutes read.

Bootstrap 4 Collapse

Bootstrap 4 Collapse Collapse is a bootstrap component that is similar to the dropdown button. Collapse is used to hide or show the content such as paragraphs, sentences, etc.  When we click on a...

4 minutes read.

Bootstrap 4 Content

Typography Typography is used for styling and formatting the content. It also helps in creating customized headings, sub-headings, lists, paragraphs, etc. Headings Bootstrap 4 offers HTML heading <h1> to <h6> that has bolder...

8 minutes read.

Environment Setup

How to use Bootstrap? We can use bootstrap in our project either by downloading or by providing link of the library files. 1) Download Bootstrap files To download files, visit official site of bootstrap www.getbootstrap.com/download/ and...

1 minute read.

Difference between Bootstrap and WordPress

What is WordPress? WordPress is a free open-source CMS (Content Management System) that is written using Hypertext Pre-processor (PHP) and is paired with MySQL and is supported with HTTPS (Hypertext Transfer...

3 minutes read.

Bootstrap Notification Bubble

What is a notification bubble? Bubbles are built into the Notification system. They float on top of the website or the button to indicate pending notifications. Bubbles can be expanded to reveal...

5 minutes read.

Bootstrap 4 Progress Bar

Bootstrap Progress Bar Bootstrap 4 offers progress bars that are used to represent the progress of tasks such as downloading a file, software installation, etc. on the computer. It represents the percentage of the...

9 minutes read.

Bootstrap List group

Bootstrap list group provides a group of a list of items. The most basic list is an unordered list. We can use <ul> element with .list-group class and <li> element with .lsit-group-item. Let us see...

3 minutes read.

Bootstrap Protocol (BOOTP)

In the following article, we will learn about the Bootstrap Protocol and how it maintains contracts among linked devices on webwork. What is Bootstrap Protocol? The Bootstrap Protocol is a webwork contract...

3 minutes read.

Bootstrap With CSS

← Prev Next → ...

1 minute read.

Bootstrap Pager

← Prev Next → ...

1 minute read.

Bootstrap 4 Icons

Bootstrap 4 Icons Bootstrap 3 contains the default icon library. But in bootstrap 4, you have to include the external icon library by yourself. Many free icon libraries are available such...

2 minutes read.

Bootstrap 4 Layout

Containers Containers are the essential elements of the bootstrap layout. It is required when we are using a bootstrap grid system. Containers can also be nested, but most layouts do not need nested containers. Bootstrap has...

3 minutes read.

Bootstrap 4 Flex

Bootstrap 4 Flex Flex is a Bootstrap 4 component used to manage the layout, navigation bar, grid columns, sizing, alignment, and other components. The flexbox or flex utility is the replacement...

26 minutes read.