How to Create a Four-Column Layout with Bootstrap ?
Last Updated :
12 Apr, 2024
In Bootstrap, creating a column layout is important for organizing content into a structured grid system. A four-column layout allows for efficient arrangement of content, such as displaying courses, products, or services, with flexibility in responsiveness for various screen sizes.
Below are the approaches to create a four-column layout with bootstrap:
Using Grid Classes
In this approach, we are using Bootstrap's Grid Classes to create a four-column layout. Each column is defined using the col-sm class, and the gx-0 class is used to remove the gutter (space) between columns. The content of each column is styled using Bootstrap's utility classes for background color (bg-primary, bg-secondary, bg-success, bg-danger) and text color (text-white).
Example: The below example uses Grid Classes to Create a Four-Column Layout with Bootstrap.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Using Grid Classes</title>
<link href=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet">
</head>
<body>
<div class="container text-center mt-4">
<h1 class="text-success">GeeksforGeeks</h1>
<h3>Using Grid Classes</h3>
</div>
<div class="container mt-4">
<div class="row gx-0">
<div class="col-sm">
<div class="bg-primary text-white p-3">
<h4>Java</h4>
<p>Java</p>
</div>
</div>
<div class="col-sm">
<div class="bg-secondary text-white p-3">
<h4>Python</h4>
<p>Python</p>
</div>
</div>
<div class="col-sm">
<div class="bg-success text-white p-3">
<h4>HTML</h4>
<p>HTML</p>
</div>
</div>
<div class="col-sm">
<div class="bg-danger text-white p-3">
<h4>CSS</h4>
<p>CSS</p>
</div>
</div>
</div>
</div>
</body>
</html>
Output:

Using FlexBox Classes
In this approach, we are using Bootstrap's Flexbox utility classes like d-flex, flex-wrap, and justify-content-center to create a four-column layout. Each column is defined as a flex item with the flex-fill class, allowing them to expand to fill the available space evenly. The m-2 class adds a margin around each column for spacing.
Example: The below example uses FlexBox to Create a Four-Column Layout with Bootstrap.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Using Flexbox</title>
<link href=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet">
</head>
<body>
<div class="container text-center mt-4">
<h1 class="text-success">GeeksforGeeks</h1>
<h3>Using Flexbox</h3>
</div>
<div class="container mt-4">
<div class="d-flex flex-wrap
justify-content-center">
<div class="bg-primary text-white
p-3 flex-fill m-2">
<h4>CSS</h4>
<p>CSS</p>
</div>
<div class="bg-secondary text-white
p-3 flex-fill m-2">
<h4>HTML</h4>
<p>HTML</p>
</div>
<div class="bg-success text-white
p-3 flex-fill m-2">
<h4>ReactJS</h4>
<p>ReactJS</p>
</div>
<div class="bg-danger text-white
p-3 flex-fill m-2">
<h4>Java</h4>
<p>Java</p>
</div>
</div>
</div>
</body>
</html>
Output:

Similar Reads
How to Create Form Layouts with Bootstrap ? Form Layouts in Bootstrap refer to the arrangement and presentation of form elements within a web page. To create Form Layouts with Bootstrap, utilize grid system classes to structure forms horizontally or vertically, and enhance them with input groups, inline forms, and responsive designs for impro
5 min read
How to Create a Multi-Column Footer in Bootstrap ? Bootstrap offers a range of classes that can be employed to design web pages and apply diverse styles. Footers are a crucial element of web design, as they provide users with valuable information and navigation options. With Bootstrap, creating a multi-column footer that is visually appealing and re
3 min read
How to Create a Basic Two-Column Layout using Bootstrap 5 ? To create a basic two-column layout using Bootstrap, first, we have to enclose your content within a container, then create two divs with classes like col or col-xx, where xx represents the breakpoint for responsive behavior. Place your content inside these columns, and Bootstrap will handle the lay
3 min read
How to Create a 4-Column Layout Grid with CSS? We can create a layout with multiple columns using CSS. It is easier to design complex layouts. In this article, we are going to discuss how to create a 4-column layout grid using CSS. We will discuss different approaches, their syntax, and code examples of each method. A 4-column layout grid is a c
3 min read
How to Create a 2-Column Layout Grid with CSS? Creating a two-column layout is a common design pattern used in web development. This layout helps to organize content efficiently and is used across various types of websites. A 2-column layout divides the webpage into two sections, which can be useful for creating sidebars, main content areas, or
4 min read