Bootstrap 5 Stacked to Horizontal
The most common responsive pattern on the web is: stacked on phones, side by side on bigger screens. On a narrow phone there's no room for columns, so content flows top to bottom; on a laptop the same content spreads into columns. Bootstrap makes this a one-class job.
How it works
A column class with a breakpoint (e.g. .col-sm-6) only takes effect from that breakpoint up. Below it, columns fall back to full width (width: 100%), so they stack. You choose where the switch happens by choosing the tier.
| Class on each column | Stacked below | Horizontal from |
|---|---|---|
.col-sm-* |
576px | 576px |
.col-md-* |
768px | 768px |
.col-lg-* |
992px | 992px |
.col-xl-* |
1200px | 1200px |
.col-xxl-* |
1400px | 1400px |
.col-* (no tier) |
never | always horizontal |
A stacked-to-horizontal layout
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="py-2">
<div class="container">
<div class="row g-2">
<div class="col-sm-4"><div class="p-3 text-bg-primary rounded">📰 News</div></div>
<div class="col-sm-4"><div class="p-3 text-bg-success rounded">🌦 Weather</div></div>
<div class="col-sm-4"><div class="p-3 text-bg-danger rounded">⚽ Sport</div></div>
</div>
</div>
</body>
</html>The frame is almost certainly wider than 576px, so you'll see three columns. Make your browser window very narrow (or open the page on a phone) and they stack.
Note: The preview frame can only be resized vertically (drag its bottom-right corner). Its width follows the lesson column, so resizing your browser window is the way to test breakpoints.
Comparing tiers side by side
The same three columns with different tiers switch at different widths. Compare what the frame shows for each:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<style>.row > div > div { background: #e9dffb; border: 1px solid #7952b3; padding: .25rem .5rem; font-size: .8rem; }</style>
</head>
<body class="py-2">
<div class="container">
<p class="small mb-1">.col-sm-4 (horizontal from 576px)</p>
<div class="row g-1 mb-2"><div class="col-sm-4"><div>A</div></div><div class="col-sm-4"><div>B</div></div><div class="col-sm-4"><div>C</div></div></div>
<p class="small mb-1">.col-lg-4 (horizontal from 992px)</p>
<div class="row g-1 mb-2"><div class="col-lg-4"><div>A</div></div><div class="col-lg-4"><div>B</div></div><div class="col-lg-4"><div>C</div></div></div>
<p class="small mb-1">.col-4 (always horizontal)</p>
<div class="row g-1"><div class="col-4"><div>A</div></div><div class="col-4"><div>B</div></div><div class="col-4"><div>C</div></div></div>
</div>
<script>console.log('frame width:', window.innerWidth + 'px');</script>
</body>
</html>Check the console: if the frame is between 576 and 992px, the first row is horizontal and the second is stacked.
A typical page layout
Main content plus a sidebar is the classic example. Stacked on phones (the sidebar comes after the article), side by side from md.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<header class="text-bg-dark p-2 mb-2"><div class="container">My Blog</div></header>
<div class="container">
<div class="row g-3">
<main class="col-md-8">
<article class="border rounded p-3">
<h5>Learning Bootstrap</h5>
<p class="mb-0 small">The article takes two thirds of the width on medium screens and up, and the full width on phones.</p>
</article>
</main>
<aside class="col-md-4">
<div class="bg-body-tertiary rounded p-3 small">
<strong>About me</strong><br>Sidebar: one third from md, below the article on phones.
</div>
</aside>
</div>
</div>
</body>
</html>Mixing stacked and always-horizontal
You can use a non-tiered class for one tier and a tiered class for bigger screens. .col-6 .col-md-3 gives two per row on phones and four per row from md — never a single stacked column.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="py-2">
<div class="container">
<div class="row g-2 text-center">
<div class="col-6 col-md-3"><div class="border rounded p-2">📷<br><small>Photos</small></div></div>
<div class="col-6 col-md-3"><div class="border rounded p-2">🎵<br><small>Music</small></div></div>
<div class="col-6 col-md-3"><div class="border rounded p-2">🎬<br><small>Videos</small></div></div>
<div class="col-6 col-md-3"><div class="border rounded p-2">📄<br><small>Docs</small></div></div>
</div>
</div>
</body>
</html>Tip: Design for the smallest screen first, then decide at which width there's enough room to go horizontal. That breakpoint is the tier you put in the class.
Test yourself
On a 500px wide phone, how do columns with .col-sm-6 behave?
- Two per row
- They stack, each full width
- They are hidden
- They overflow
Which column class never stacks?
- .col-sm-4
- .col-md-4
- .col-4
- .col-lg-4
You want a sidebar beside the content only on screens 992px and wider. Which tier?
- sm
- md
- lg
- xl