Here’s a beginner-friendly guide to the Bootstrap Grid System, one of the most powerful features in the Bootstrap framework for building responsive layouts.
📦 What Is the Bootstrap Grid System?
The Bootstrap grid system is a 12-column responsive layout system that helps you organize and align content using rows and columns.
It’s built on top of Flexbox, and makes it easy to design layouts that work on all screen sizes.
🧱 Basic Structure
html
<div class="container">
<div class="row">
<div class="col">Column 1</div>
<div class="col">Column 2</div>
</div>
</div>
.container
: Centers content with padding.row
: Wraps columns and clears float.col
: Auto-sizes to share space equally
🔟 The 12-Column Rule
You can divide a row into 12 units total.
html
<div class="row">
<div class="col-4">4</div>
<div class="col-8">8</div>
</div>
✅ 4 + 8 = 12 columns → Full width
You can use:
.col-1
to.col-12
Mix and match:
col-3
,col-6
,col-3
(adds to 12)
📱 Responsive Breakpoints
Class Prefix | Screen Size | Min Width |
---|---|---|
col- | Extra small (xs) | <576px |
col-sm- | Small | ≥576px |
col-md- | Medium | ≥768px |
col-lg- | Large | ≥992px |
col-xl- | Extra large | ≥1200px |
col-xxl- | XXL | ≥1400px |
Example:
html
<div class="row">
<div class="col-12 col-md-6">Left</div>
<div class="col-12 col-md-6">Right</div>
</div>
📱 On mobile: stacked
💻 On desktop: side-by-side
✨ Common Grid Tricks
✅ Equal Columns
html
<div class="row">
<div class="col">1</div>
<div class="col">2</div>
<div class="col">3</div>
</div>
✅ Nested Grids
html
<div class="row">
<div class="col-6">
<div class="row">
<div class="col-6">Nested 1</div>
<div class="col-6">Nested 2</div>
</div>
</div>
<div class="col-6">Main Right</div>
</div>
✅ Offset Columns
html
<div class="row">
<div class="col-md-4 offset-md-2">Pushed Right</div>
</div>
✅ Column Order
html
<div class="row">
<div class="col-md-6 order-md-2">Second on Desktop</div>
<div class="col-md-6 order-md-1">First on Desktop</div>
</div>
🧪 Grid Playground
Try it online here:
🔗 Bootstrap Grid Builder
✅ Summary
Concept | Class |
---|---|
Define grid | .container , .row , .col |
Set width | .col-4 , .col-6 , etc. |
Responsive design | .col-sm-* , .col-lg-* |
Alignment | justify-content-* , align-items-* |
Spacing | g-3 (gutters), m-* , p-* |