Gutters and spacing help keep content neat and easy to read by adding space between elements.
Gutters and spacing control in Bootsrap
class="g-{size}" for gutters (e.g., g-3) class="p-{size}" for padding (e.g., p-2) class="m-{size}" for margin (e.g., m-4) Sizes range from 0 to 5, where 0 means no space and 5 means larger space.
Gutters control space between columns inside a .row.
Padding and margin classes add space inside or outside elements.
<div class="row g-3"> <div class="col">Column 1</div> <div class="col">Column 2</div> </div>
<button class="btn btn-primary p-4">Big Padding</button>
<p class="m-2">Paragraph with margin</p>
<div class="row g-0"> <div class="col">No gutter space</div> <div class="col">No gutter space</div> </div>
This page shows three columns with space between them using gutters. Each column has padding inside for spacing. The button below also has padding to make it bigger. The paragraph has margin top and bottom removed for tight spacing.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Bootstrap Gutters and Spacing</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <main class="container mt-4"> <h1 class="mb-4">Gutters and Spacing Example</h1> <div class="row g-4"> <div class="col bg-primary text-white p-3">Column 1 with padding</div> <div class="col bg-secondary text-white p-3">Column 2 with padding</div> <div class="col bg-success text-white p-3">Column 3 with padding</div> </div> <button class="btn btn-danger mt-4 p-3">Button with padding</button> <p class="mt-0 mb-0">Paragraph with margin top and bottom removed.</p> </main> </body> </html>
Use gutter classes only on .row elements to control space between columns.
Padding and margin classes can be combined for fine control of spacing.
Sizes 0 to 5 scale spacing from none to large.
Gutters add space between columns in Bootstrap grids.
Padding and margin classes add space inside or outside elements.
Use size numbers 0-5 to control how much space you want.
Practice
g-3 do in a grid layout?Solution
Step 1: Understand gutter classes in Bootstrap
The classg-3sets the gutter size between columns to a medium spacing level.Step 2: Differentiate gutters from padding and margin
Gutters control space between columns, not inside columns (padding) or outside elements (margin).Final Answer:
Adds a medium gutter spacing between columns -> Option BQuick Check:
Gutter size 3 means medium space between columns [OK]
- Confusing gutters with padding or margin
- Thinking g-3 removes gutters
- Assuming gutters center content
Solution
Step 1: Understand gutter axis classes
gx-0removes horizontal gutters (x-axis),gy-0removes vertical gutters (y-axis), andg-0removes both.Step 2: Identify the class that removes only horizontal gutters
Since the question asks for horizontal gutters only,gx-0is correct.Final Answer:
gx-0 -> Option AQuick Check:
gx-0 removes horizontal gutters only [OK]
- Using g-0 removes all gutters, not just horizontal
- Confusing gx and gy classes
- Choosing g-5 which adds large gutters
<div class='row gx-4'> <div class='col'>A</div> <div class='col'>B</div> </div>
What is the effect of
gx-4 on the columns?Solution
Step 1: Identify gutter axis and size
The classgx-4sets horizontal gutters (x-axis) to size 4, which is large spacing.Step 2: Understand gutter effect on columns
This adds horizontal space between the columns but does not affect vertical spacing or padding inside columns.Final Answer:
Adds large horizontal space between columns -> Option AQuick Check:
gx-4 means large horizontal gutters [OK]
- Confusing vertical and horizontal gutters
- Thinking gutters add padding inside columns
- Assuming gx-4 removes gutters
Solution
Step 1: Understand axis gutter classes
gy-0removes vertical gutters,gx-3sets horizontal gutters to size 3.Step 2: Check each option
gy-0 gx-3 correctly removes vertical gutters and sets horizontal gutters to 3. Others either reverse axes or conflict.Final Answer:
gy-0 gx-3 -> Option CQuick Check:
gy-0 removes vertical, gx-3 sets horizontal gutters [OK]
- Swapping gx and gy classes
- Using g-0 removes all gutters
- Combining conflicting gutter sizes
Solution
Step 1: Add spacing between columns with gutters
Usingg-2on the row adds equal gutters (spacing) between all columns.Step 2: Add spacing inside each column with padding
Addingp-3on each column adds equal padding inside each column for internal spacing.Final Answer:
Useg-2on the row andp-3on each column -> Option DQuick Check:
Gutters add space between columns; padding adds space inside columns [OK]
- Using margin instead of padding inside columns
- Removing gutters accidentally with g-0
- Adding padding on row instead of columns
Ready to prove it?
Pass the test and this pattern moves unknown
