Gutter in Bootstrap refer to the space between columns within the grid system. Bootstrap 5 offers flexible way to easily control the gutter sizes or remove them entirely.
The grid system uses gutters for columns padding to separate content and create a clean design and layout.
How Gutters Work in Bootstrap 5
By default, gutters are set 1.5rem
(24px) horizontally and vertically. However, Bootstrap 5 allows you to:
Customize the gutter size using utility classes.
Add or remove gutters based on screen sizes.
Use horizontal or vertical gutters separately .
Default Gutters Example
By default, the following code will have a gutter between the columns.
<div class = "container" >
<div class = "row" >
<div class = "col" >
<div class = "p-3 bg-primary text-white" > Column 1 </div>
</div>
<div class = "col" >
<div class = "p-3 bg-success text-white" > Column 2 </div>
</div>
</div>
</div>
In the above example, each columns will have 1.5rem space between them.
Gutters Control Utility Classes
Bootstrap 5.3 introduces the given below classes to control gutters:-
.g-{size}
: Controls both horizontal and vertical gutters.
.gx-{size}
: Controls horizontal gutters only (left and right).
.gy-{size}
: Controls vertical gutters only (top and bottom).
.g-0
: Removes all gutters.
Available gutter sizes:
0
: No gutters
1
: 0.25rem gutters (4px)
2
: 0.5rem gutters (8px)
3
: 1rem gutters (16px)
4
: 1.5rem gutters (24px)
5
: 3rem gutters (48px)
Controlling Both Horizontal and Vertical Gutters
<div class = "container" >
<div class = "row g-3" >
<div class = "col" >
<div class = "p-3 bg-info text-white" > Column 1 </div>
</div>
<div class = "col" >
<div class = "p-3 bg-success text-white" > Column 2 </div>
</div>
</div>
</div>
Explanation
The .g-3
applies 1rem (16px) padding between the columns both horizontally and vertically.
Controlling Only Horizontal Gutters
<div class = "container" >
<div class = "row gx-5" >
<div class = "col" >
<div class = "p-3 bg-secondary text-white" > Column 1 </div>
</div>
<div class = "col" >
<div class = "p-3 bg-dark text-white" > Column 2 </div>
</div>
</div>
</div>
Explanation
The .gx-5
applies 3rem (48px) padding between the columns only horizontally and keeps the vertical gutter default.
Controlling Only Vertical Gutters
<div class = "container" >
<div class = "row gy-2" >
<div class = "col" >
<div class = "p-3 bg-danger text-white" > Column 1 </div>
</div>
<div class = "col" >
<div class = "p-3 bg-success text-white" > Column 2 </div>
</div>
</div>
</div>
Explanation
The .gy-2
applies 0.5 rem (8px) padding between the columns only vertically and keeps the horizontal gutter default.
Removing Gutters Completely
<div class = "container" >
<div class = "row g-0" >
<div class = "col" >
<div class = "p-3 bg-primary text-white" > Column 1 </div>
</div>
<div class = "col" >
<div class = "p-3 bg-secondary text-white" > Column 2 </div>
</div>
</div>
</div>
Explanation
The .g-0
removes both vertically and horizontal gutter completely.
Responsive Gutter Control
You can apply different gutter sizes for different screen sizes using response breakpoints (sm, md, lg, xl, xxl, )
<div class = "container" >
<div class = "row g-3 g-md-5" >
<div class = "col" >
<div class = "p-3 bg-info text-white" > Column 1 </div>
</div>
<div class = "col" >
<div class = "p-3 bg-warning text-white" > Column 2 </div>
</div>
</div>
</div>
Explanation
On small screens, the gutter .g-3
applies 1rem (16px).
On medium screens and larger, the gutter increases to 3rem (48px) with .g-md-5
.
Summary of Gutter Control Options
.g-{size}
: Controls both vertical and horizontal gutters.
.gx-{size}
: Controls horizontal gutters only.
.gy-{size}
: Controls vertical gutters only.
Responsive control : Use .g-breakpoint-{size}
for different screen sizes.
Removing gutters : Use .g-0
to remove all gutters.
You can easily create flexible and responsive layouts using these gutter options.
Complete Layout Example with Gutter Control
Here’s a complete webpage layout example using Bootstrap 5.3 that showcases how to control gutters across multiple sections. This layout includes a header, main content, sidebar, and footer, and demonstrates different gutter controls for horizontal and vertical spacing.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE html>
<html lang = "en" >
<head>
<meta charset = "UTF-8" >
<meta name = "viewport" content = "width=device-width, initial-scale=1.0" >
<title> Bootstrap 5.3 Layout with Gutter Control </title>
<link href = "https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel = "stylesheet" >
</head>
<body>
<!-- Header Section -->
<header class = "bg-dark text-white p-3" >
<h1 class = "text-center" > Website Header </h1>
</header>
<!-- Main Layout Container -->
<div class = "container mt-4" >
<!-- Row with Gutters -->
<div class = "row g-4" >
<!-- Main Content Section (2/3 width on large screens) -->
<div class = "col-lg-8" >
<div class = "p-3 bg-light border" >
<h2> Main Content </h2>
<p> This is the main content area. The gutter size is controlled by the Bootstrap grid system with the `.g-4` class. </p>
</div>
</div>
<!-- Sidebar Section (1/3 width on large screens) -->
<div class = "col-lg-4" >
<div class = "p-3 bg-secondary text-white border" >
<h3> Sidebar </h3>
<p> This is the sidebar section. It is displayed next to the main content with controlled spacing. </p>
</div>
</div>
</div>
<!-- Second Row with Custom Gutters -->
<div class = "row gx-3 gy-5 mt-5" >
<div class = "col-md-4" >
<div class = "p-3 bg-info text-white" >
<h4> Card 1 </h4>
<p> This card has a smaller horizontal gutter (gx-3) and larger vertical gutter (gy-5). </p>
</div>
</div>
<div class = "col-md-4" >
<div class = "p-3 bg-warning text-dark" >
<h4> Card 2 </h4>
<p> This card follows the same gutter control rules as Card 1. </p>
</div>
</div>
<div class = "col-md-4" >
<div class = "p-3 bg-success text-white" >
<h4> Card 3 </h4>
<p> The gutter spacing creates a clear visual separation between each card. </p>
</div>
</div>
</div>
</div>
<!-- Footer Section -->
<footer class = "bg-dark text-white text-center p-3 mt-5" >
<p> © 2025 Bootstrap Layout Example. All rights reserved. </p>
</footer>
<!-- Bootstrap 5.3 JavaScript Bundle -->
<script src = "https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js" > </script>
</body>
</html>