The Grid in Depth
Bootstrap's grid has 12 columns and 6 breakpoints. A breakpoint is a screen width where the layout may change.
col-(all screens),col-sm-(576px+),col-md-(768px+),col-lg-(992px+),col-xl-(1200px+),col-xxl-(1400px+)- A class works from its breakpoint upwards.
col-md-6is half width on tablets and computers, and full width on phones.
Breakpoints are the widths where your layout is allowed to change. Bootstrap is mobile-first, so classes without a size apply to all screens, and each size prefix adds a rule from that width upward. Combining a few classes on one element lets you describe how it behaves on every device - full width on phones, half on tablets, a quarter on laptops - without writing any media queries.
Example
<!DOCTYPE html>
<html lang="en">
<head>
<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="p-3">
<div class="container">
<div class="row g-3">
<div class="col-12 col-md-8"><div class="p-3 bg-primary-subtle">Main: full on phone, 8/12 on tablet+</div></div>
<div class="col-12 col-md-4"><div class="p-3 bg-success-subtle">Side: full on phone, 4/12 on tablet+</div></div>
<div class="col-6 col-lg-3"><div class="p-3 bg-warning-subtle">A</div></div>
<div class="col-6 col-lg-3"><div class="p-3 bg-warning-subtle">B</div></div>
<div class="col-6 col-lg-3"><div class="p-3 bg-warning-subtle">C</div></div>
<div class="col-6 col-lg-3"><div class="p-3 bg-warning-subtle">D</div></div>
</div>
</div>
</body>
</html>▶ Try it yourselfOffsets, order and auto width
offset-md-2- push a column 2 columns to the rightorder-first,order-md-2- change the order on some screens (show the picture first on phones)col- share the space equally;col-auto- only as wide as its contentg-0tog-5- the gap between columns (gutter)
Example
<!DOCTYPE html>
<html lang="en">
<head>
<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="p-3">
<div class="container">
<div class="row g-2 mb-3">
<div class="col-md-6 offset-md-3"><div class="p-3 border text-center">Centred with an offset</div></div>
</div>
<div class="row g-2 align-items-center">
<div class="col-auto"><div class="p-2 border">Logo</div></div>
<div class="col"><div class="p-2 border">Search box takes the rest</div></div>
<div class="col-auto"><div class="p-2 border">Cart</div></div>
</div>
<div class="row g-2 mt-3">
<div class="col-md-6 order-md-2"><div class="p-3 bg-info-subtle">Picture (right on tablet+, first on phone)</div></div>
<div class="col-md-6 order-md-1"><div class="p-3 bg-light border">Text</div></div>
</div>
</div>
</body>
</html>▶ Try it yourselfNesting
Put a new .row inside a column to split that column again into 12.
Resize the preview window (or turn your phone sideways) to watch the layout change at each breakpoint.
Key points
- 6 breakpoints: (none), sm, md, lg, xl, xxl.
- offset-*, order-* and col-auto fine-tune layouts.
- Nest rows inside columns for sub-layouts.
📝 Test yourself
1. On a phone, how wide is a column with only col-md-6?
2. How many columns does one Bootstrap row have?
3. Fill in the class that makes a column only as wide as its content:
<div class="col-">Cart</div>
