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 4 Spinners

Bootstrap 4 offers spinner is a loading indicator that is used to display the loading state of any component or web page. The spinner is also known as a loader...

7 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 First Example

1) Add HTML5 doctype Before starting the example of Bootstrap, we should know about the some basic rules of Bootstrap. We have to add HTML5 doctype with lang element and CSS properties. <!DOCTYPE html>   <html lang="en">     <head>       <meta charset="utf-8">      </head>   </html> 2) Bootstrap...

2 minutes read.

Bootstrap Toast Example

What are toasts? Toasts are similar to notifications, and they are lightweight and act as push notifications from mobile and desktop operating systems. They’re built using flexbox in Bootstrap. They can...

4 minutes 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 Card

In Bootstrap 4, a card is a bordered box with padding around its content. It has options for headers, footers, colors, content, etc. The card provides the link, title, image,...

8 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 Modal

Bootstrap 4 Modal The Modal is a component of Bootstrap 4, which is a dialog box or pop-up window. The modals are used to provide information or warning to the user, such as...

18 minutes read.

Bootstrap Typography

Bootstrap provides simple and easily customized typography for headings, body text, lists, and many more. Headline <h1> to <h6> By default, Bootstrap has HTML headings (<h1> to <h6>) that are given below: Example <h1>h1. Bootstrap heading</h1>   <h2>h2. Bootstrap heading</h2>   <h3>h3. Bootstrap heading</h3>   <h4>h4. Bootstrap heading</h4>   <h5>h5. Bootstrap heading</h5>   <h6>h6. Bootstrap heading</h6> Try Now ←...

1 minute read.

Bootstrap Grid System Example

Bootstrap Grid System Example Stacked to horizontal – In stacked to the horizontal grid system, the grid columns are stacked on top of each other on extra small devices and becomes...

7 minutes read.

Bootstrap Multiselect Dropdown

What is a multi-select Dropdown? Multi-select dropdown lists are used when we want to select multiple options for a particular record. Usually, dropdown lists provide the feature of choosing just one value...

4 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 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 Datepicker

What is a Bootstrap Datepicker? It is used to display a calendar with the date, month, and time from a dropdown menu. We will use an example to see how the date...

5 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.

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.

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 4 Grid System

Bootstrap 4 Grid System The bootstrap 4 grid system is used to create a responsive website layout. The bootstrap 4 offers a mobile-first flexbox grid system that allows you to divide...

4 minutes read.

Bootstrap Time Picker Example

What is a Bootstrap Time picker? It is used to display the time in hours, minutes and seconds from a dropdown menu. In this section, we will create an example to...

4 minutes read.

Bootstrap Pager

← Prev Next → ...

1 minute read.