Understanding Bootstrap 5's Responsive Grid: Column Classes, Breakpoints, and Nesting
Learn how Bootstrap's 12‑column grid uses container, row, and col-* classes to create layouts that adapt from phones to large desktops, with a concrete example and pitfalls to avoid.
10 Sept 2025, 23:22 UTC

Use column classes to control width at each breakpoint
Bootstrap’s grid is built on a 12‑column system. By adding col-* classes you tell the browser how many of those 12 columns an element should occupy at a given viewport size. The asterisk stands for a breakpoint prefix (xs, sm, md, lg, xl, xxl) or can be omitted for the extra‑small baseline. When the viewport reaches a breakpoint, the matching class takes effect; larger breakpoints override smaller ones unless you explicitly reset them.
Worked example
The following markup creates a full‑width block on phones, two equal columns on medium tablets, and a 4‑column / 8‑column split on large desktops:
<div class="container">
<div class="row">
<div class="col-12 col-md-6 col-lg-4">Main content</div>
<div class="col-12 col-md-6 col-lg-8">Sidebar</div>
</div>
</div>
Explanation:
col-12makes each element span all 12 columns on extra‑small screens (phones), so they stack vertically.- At the
mdbreakpoint (≥768 px) the classescol-md-6give each element six columns, i.e. 50 % of the row width, producing two side‑by‑side columns. - At the
lgbreakpoint (≥992 px) thecol-lg-4andcol-lg-8classes take over, giving the first element 4/12 ≈ 33.3 % and the second 8/12 ≈ 66.6 % of the row.
Limits of the grid
Even though the system is flexible, it has a few hard constraints you must respect:
- Each
.rowcan contain at most 12 column units. If the sum of thecol-*values exceeds 12, the excess columns wrap to a new line automatically. - Nested grids must again observe the 12‑column rule inside the parent column. A nested
.rowdoes not inherit the parent’s width; it starts its own 12‑column count. - The grid relies on flexbox; setting explicit widths (e.g.,
width: 300px) or margins on a column can interfere with the calculated flex basis and cause overflow or unexpected wrapping.
Common mistakes and how to avoid them
- Missing
.rowwrapper – columns placed directly inside a.containerwill not get the negative margin that offsets the container’s padding, leading to unwanted horizontal scroll. - Omitting a parent
.containeror.container-fluid– without it the grid lacks the horizontal padding that keeps content from touching the viewport edge. - Mixing breakpoint classes without understanding override rules – for example
col-md-6 col-lg-3means the element is six columns wide at medium and up, but at large it becomes three columns because thelgclass overrides themdone. If you want the medium width to persist, add an explicitcol-lg-6or reset withcol-lg-auto. - Using fixed pixel widths inside columns (e.g.,
style="width:250px;") – this breaks the fluid behavior and can cause overflow on small screens. Prefer utility classes likew-50or let the grid manage width.
Verification steps
- Copy the example markup into a blank HTML file that includes Bootstrap 5 CSS (via CDN or local copy).
- Open the file in a browser and open DevTools.
- Toggle the device toolbar or resize the window to the breakpoint ranges:
<576px(xs),≥576px(sm),≥768px(md),≥992px(lg),≥1200px(xl),≥1400px(xxl). - Inspect each column; the computed width should match the expected fraction of the row’s width (e.g., 50 % at md, 33.33 % and 66.66 % at lg).
- If columns wrap unexpectedly, check that the total of the
col-*values in that row does not exceed 12 and that no custom width or margin rules are overriding the grid.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.