LESSON 10.4
Bootstrap Grid System
Build responsive multi-column layouts without writing media queries
Learn how the Bootstrap 12-column grid works, how to create equal and uneven column layouts, and how columns stack automatically on mobile.
💡 The Concept
Now that you have Bootstrap installed (see Getting Started with Bootstrap if you need help with that), you can use it for a wide range of features: hamburger menus for mobile, dropdown menus, popups, and accordions. The most everyday use, though, is the grid system for stacking columns on mobile devices.
Bootstrap’s grid system divides every row into twelve equal units. Columns sit side by side on larger screens and automatically stack vertically on mobile. No media queries required.
The Three Building Blocks
- Container: wraps everything and centers it. I recommend using .container-fluid for full-width layouts. (You can also use
.containerfor a fixed-width centered layout.) - Row: a horizontal group of columns. Always place columns inside a row.
- Column: defines how wide each piece of content is, out of 12 units. We’ll cover how to write the column classes below.
The code looks like this:
<div class="container-fluid"><!--This sets up the container-->
<div class="row"><!--This starts a new row-->
<div class="col-md-12"><!--This creates a column-->
<!--Content goes here-->
</div>
</div>
</div>
The graphic below shows you the code for one row with three columns and one row with two columns.

Column Class Syntax

Column classes follow this pattern: col-{breakpoint}-{number}. Each class has three segments separated by hyphens.
First Segment: col
Every column class starts with col. This tells Bootstrap that the div is a column in the grid.
Second Segment: Breakpoint
The breakpoint is the minimum screen width at which columns display side by side. Below that width they stack. I recommend col-md- for most layouts in this course.
col-sm-: side by side at 576px and widercol-md-: side by side at 768px and widercol-lg-: side by side at 992px and widercol-xl-: side by side at 1200px and wider
Third Segment: Parts of Twelve
The number tells Bootstrap how many of the 12 units this column takes up. The numbers in a row must always add up to 12:

Three Equal Columns
<div class="container">
<div class="row">
<div class="col-md-4">Column 1</div>
<div class="col-md-4">Column 2</div>
<div class="col-md-4">Column 3</div>
</div>
</div>

Uneven Layouts
Any combination that adds up to 12 works. A common layout is a wide main content area with a narrower sidebar:
<div class="container">
<div class="row">
<div class="col-md-8">Main Content</div>
<div class="col-md-4">Sidebar</div>
</div>
</div>

Stacking on Mobile
When the screen is narrower than your breakpoint, Bootstrap automatically stacks the columns vertically. No extra CSS needed.

Exercise: Try It Yourself
Step 1. Open JSFiddle. Unlike a real webpage where the stylesheet link goes in the <head> and the script goes at the end of the <body>, in JSFiddle you can paste both at the very top of the HTML panel. Add these two lines:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
Step 2. Copy the following CSS into the CSS panel:
.col-md-4 p, .col-md-3 p, .col-md-9 p, .col-md-8 p {
background-color: blue;
height: 50px;
width: 100%;
margin: 5px;
padding: 12px;
color: white;
text-align: center;
}
Step 3. Using the starter code below and the image as your guide, build the column layout in the HTML panel:
<div class="container-fluid">
<div class="row">
<div class="col-md-4">
<p>This is a col-md-4</p>
</div>
</div>
</div>

Feeling stuck? The answer key is below. Try to do it by thinking about it before looking at the answer.

★ Key Takeaways
Bootstrap’s column system makes it easy to create multi-column layouts that work on any screen size. This lesson covered how the 12-column grid works and how to build column classes using the three-part syntax: col, breakpoint, and parts of twelve. Next, you will explore more of what Bootstrap can do, including responsive images, forms, modals, hamburger navigation, and accordions.
❓ Frequently Asked Questions
Five does not divide evenly into 12, so there is no numbered col class that works. Bootstrap 5 solves this with its auto-layout col class. Instead of specifying a number, just use col on each column. Bootstrap divides the row equally among however many col columns are in the row, so five col divs each get 20% of the width.
Yes. Bootstrap grid classes include built-in padding and margin that keep your rows consistently spaced. Even a single-column row benefits from that spacing. For a full-width single column, use col-md-12.
Google Ads
The costs of this website are partially offset by revenue from Google Ads.Tools of the Trade
HTML/CSS Lessons
-
-
-
1.3. HTML Tag Preview
-
-
-
2.2. The HTML Framework
-
-
2.4. HTML Headings
-
-
-
-
-
-
3.01. Introduction to CSS
-
3.02. How CSS Cascades
-
-
-
-
3.05. CSS Colors
-
3.06. RGBA Colors
-
-
3.08. Font and Text Properties
-
3.09. Classes and IDs
-
-
-
-
-
4.3. HTML Embedded Images
-
-
-
-
-
-
5.1. CSS Borders
-
5.2. CSS Border Radius
-
5.3. CSS Gradients
-
5.4. CSS Box Shadows
-
5.5. CSS Text Shadows
-
7.1. The Display Property
-
-
-
7.4. The Box Model
-
-
-
-
-
-
9.1. Website Tables
-
9.2. HTML Forms
-
-
9.4. Special Form Fields
-
9.5. Embedding Multimedia
-
-
9.7. Keyboard Shortcuts
-
10.1. What Is a Framework?
-
10.2. Font Awesome Icons
-
-
10.4. Bootstrap Grid System
-
-
10.6. Bootstrap Navigation
-
-
11.2. Purchasing a Domain Name
-
11.3. Website Hosting
-
11.4. Nameservers and DNS
-
11.5. FTP
-
11.6. GitHub Pages
