Most grid bugs are not caused by CSS Grid being hard. They come from one hasty declaration of grid-template-columns that never got reviewed again: a fixed pixel width that breaks on mobile, an 1fr track that refuses to shrink, or an auto-fill where auto-fit was needed. This checklist walks through every decision, one snippet at a time, and ends with a copy-ready responsive 3-column pattern you can paste into any project.
Quick answer: what does grid-template-columns do?
The grid-template-columns property defines the number of columns in a grid container and the width of each one. You write one value per column track, separated by spaces, on the element that has display: grid. Three values means three columns.
.grid {
display: grid;
grid-template-columns: 200px 1fr 1fr; /* 3 columns: fixed, flexible, flexible */
gap: 1rem;
}
That is the whole concept. Everything below is about choosing the right value for each track so the layout survives long words, small screens and unpredictable content.

The checklist
1. Turn the parent into a grid container first
.wrapper {
display: grid; /* or display: inline-grid */
}
When to use it: always, before anything else. grid-template-columns does nothing on an element that is not a grid (or subgrid) container. Anyone digging further should read CSS Grid: grid-template-areas without grid-template-rows.
2. Decide: fixed width or flexible (fr)?
/* fixed */
grid-template-columns: 240px 240px 240px;
/* flexible */
grid-template-columns: 1fr 1fr 1fr;
When to use it: use fixed widths only for elements whose size is dictated by content you control (a sidebar, an icon column, an avatar rail); use fr for anything that should share the leftover space.
The fr unit means “fraction of the free space remaining after gaps and fixed tracks are subtracted”. 2fr 1fr gives the first column twice the free space of the second, not twice the total width.
3. Mix fixed and flexible when one side must stay put
.app {
display: grid;
grid-template-columns: 260px 1fr; /* sidebar + fluid content */
gap: 2rem;
}
When to use it: dashboards, documentation layouts, any UI where a navigation column must keep a predictable width while the main area absorbs the rest.
4. Use repeat() instead of typing the same value
/* identical results */
grid-template-columns: 1fr 1fr 1fr 1fr;
grid-template-columns: repeat(4, 1fr);
/* repeat a pattern */
grid-template-columns: repeat(3, 200px 1fr);
When to use it: as soon as the same track value appears twice. It is shorter, easier to change, and it is the only way to use auto-fit / auto-fill.
The syntax is repeat(count, track-list). The count can be a number, auto-fit or auto-fill. You can also combine repeat() with normal tracks: grid-template-columns: 200px repeat(3, 1fr) 200px;
5. Add minmax() to give each column a floor and a ceiling
grid-template-columns: repeat(3, minmax(180px, 1fr));
When to use it: whenever a column must never get narrower (or wider) than a certain size, for example to keep card text readable.
Careful: a minmax() minimum is a hard minimum. Three columns with a 180px floor plus gaps will overflow a 400px viewport. Pair it with auto-fit or a media query, or use the min() trick in item 9. Full details on https://devdoc.net.
6. Choose between auto-fit and auto-fill
/* columns stretch to fill the row */
grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
/* empty tracks are kept, items stay their minimum size */
grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
When to use it: auto-fit for card grids where the last row should stretch to the full width; auto-fill when you want a stable column rhythm even if there are not enough items to fill the row.
| Behaviour | auto-fit | auto-fill |
|---|---|---|
| Empty tracks | Collapsed to 0 | Kept at their minimum size |
| 2 items in a wide container | Each item stretches, filling the row | Items keep the min width, empty space on the right |
| Best for | Card and product grids | Calendars, catalogues, fixed rhythms |
| With a fixed value (no 1fr) | Visually identical to auto-fill | Visually identical to auto-fit |
The difference only becomes visible when the flexible part of minmax() is 1fr and there are fewer items than available tracks. The team at bisign.es reached a similar conclusion.
7. Set the gap before tuning the widths
.grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 1.5rem; /* row and column */
/* column-gap: 1.5rem; row-gap: 2.5rem; */
}
When to use it: always use gap rather than margins on grid children. Gaps are subtracted from the free space before fr units are calculated, so widths stay correct automatically.
8. Kill overflow with minmax(0, 1fr)
/* can overflow with long words, blocks or wide tables */
grid-template-columns: repeat(3, 1fr);
/* safe */
grid-template-columns: repeat(3, minmax(0, 1fr));
When to use it: any time a column may contain a long URL, a code block, a table or an image without a max-width. A bare 1fr is shorthand for minmax(auto, 1fr), and auto refuses to shrink below the content's minimum size, which pushes the grid out of its container.
If the overflowing element is nested deeper, add min-width: 0; (or overflow: hidden;) on the grid item itself.
9. Protect small screens with min()
grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr));
When to use it: every responsive card grid. It says "the minimum track is 18rem, unless 18rem is wider than the container, in which case use 100%", which removes horizontal scrollbars on narrow phones without a single media query.
10. Know when auto, max-content and min-content are the right answer
grid-template-columns: max-content 1fr; /* label sized by its longest text */
grid-template-columns: min-content 1fr; /* label as narrow as possible */
grid-template-columns: auto 1fr auto; /* content-sized edges, fluid middle */
When to use it: form rows, toolbars, table-like layouts where one column must match its content exactly instead of a number you guessed.
11. Name your lines when the layout gets complex
.page {
display: grid;
grid-template-columns: [full-start] 1fr [content-start] minmax(0, 70ch) [content-end] 1fr [full-end];
}
.page > * { grid-column: content; }
.page > .hero { grid-column: full; }
When to use it: article layouts with full-bleed sections. Named lines are self-documenting and survive refactors better than numeric line indexes.
12. Change the column count only where the layout actually breaks
.grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 900px) {
.grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
.grid { grid-template-columns: 1fr; }
}
When to use it: when the grid must follow a precise editorial rhythm. Otherwise prefer item 9, which adapts with no breakpoints at all. Container queries (@container, supported in current versions of Chrome, Edge, Firefox and Safari) are the modern option when the grid should react to its parent rather than to the viewport. This is the sort of thing a solid web design team ships without fuss.
13. Test before you ship
- Resize from about 320px wide up to your largest breakpoint and watch for a horizontal scrollbar.
- Paste a 60-character word with no spaces into one cell.
- Remove items until only one is left (that is where
auto-fitandauto-filldiverge). - Check zoom at 200%, which WCAG 2.1 success criterion 1.4.4 expects to work without loss of content.
- Open DevTools and toggle the grid overlay to see the real track sizes.

Value cheat sheet
| Value | What it does | Typical use |
|---|---|---|
240px / 15rem |
Fixed track | Sidebars, icon rails |
1fr |
One share of the free space | Main content areas |
minmax(0, 1fr) |
Flexible but allowed to shrink to 0 | Default safe column |
auto |
Sized by content, can stretch | Form labels, buttons |
min-content / max-content |
Smallest / largest content size | Table-like rows |
repeat(n, ...) |
Repeats a track list n times | Equal column sets |
repeat(auto-fit, ...) |
As many tracks as fit, empties collapse | Responsive card grids |
repeat(auto-fill, ...) |
As many tracks as fit, empties kept | Fixed rhythms, calendars |
percentages |
Relative to the container width | Rarely needed; gaps are added on top, so they often overflow |

Copy-ready pattern: responsive 3-column grid
This is the version we would ship. Three columns on desktop, automatic reflow on smaller screens, no overflow, no magic numbers scattered through the stylesheet.
.grid-3 {
display: grid;
gap: clamp(1rem, 2vw, 2rem);
grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr));
}
/* Cap it at 3 columns on very wide screens */
@media (min-width: 75rem) {
.grid-3 {
grid-template-columns: repeat(3, minmax(0, 1fr));
}
}
Markup:
<div class="grid-3">
<article class="card">...</article>
<article class="card">...</article>
<article class="card">...</article>
</div>
If you want exactly three columns at all times above a breakpoint and a single column below it, swap the first rule for the media query stack in checklist item 12.

Why the Bootstrap grid has 12 columns (and how to copy it)
Twelve is used because it divides cleanly by 2, 3, 4 and 6, so halves, thirds, quarters and sixths all land on whole columns. A 10-column system cannot express thirds; a 12-column one can. You can reproduce the same base with a single line of CSS Grid:
.row-12 {
display: grid;
grid-template-columns: repeat(12, minmax(0, 1fr));
gap: 1.5rem;
}
.col-4 { grid-column: span 4; } /* one third */
.col-6 { grid-column: span 6; } /* one half */
.col-12 { grid-column: span 12; } /* full width */
No framework, no wrapper divs, and the minmax(0, 1fr) keeps long content from blowing the row apart.

Five mistakes worth re-checking
- Using percentages with gaps.
33.33% 33.33% 33.33%plus a 2rem gap overflows. Use1fr. - Forgetting
minmax(0, 1fr). The single most common cause of a mysterious horizontal scrollbar. - Picking
auto-fillby habit. It leaves a gap on the right when there are few items. - Setting widths on the grid items. Track sizing belongs to the container; width on children fights it.
- Breakpoints that do not match the content. Change columns where the design breaks, not at a round device width.
FAQ
How to use repeat in grid-template-columns?
Write repeat(count, track-list). repeat(4, 1fr) creates four equal columns, repeat(2, 200px 1fr) repeats a two-track pattern twice (four columns total), and repeat(auto-fit, minmax(240px, 1fr)) creates as many columns as fit the container. You can combine it with ordinary tracks: grid-template-columns: 200px repeat(3, 1fr);
How to make a 3 column grid in CSS?
Set display: grid on the parent and give it three track values:
.three {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 1.5rem;
}
Add a media query (or the auto-fit pattern above) so it collapses to two columns and then one on smaller screens.
Which CSS property defines the number of columns in a grid?
grid-template-columns. Each value you list creates one column track, so the number of values equals the number of explicit columns. grid-auto-columns only sizes implicit columns created outside your template, and column-count belongs to CSS multi-column layout, not to Grid.
What is a CSS Grid?
CSS Grid Layout is a two-dimensional layout system: it positions elements in rows and columns at the same time, unlike Flexbox which works along a single axis. You activate it with display: grid on a container, then describe the tracks with grid-template-columns and grid-template-rows. It is supported in every current major browser.
What is an example of a grid?
Everyday examples: a spreadsheet, a chessboard, a calendar month view, a photo gallery on an e-commerce category page, or a newspaper front page. In code, a blog card listing is the classic one:
.posts {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr));
gap: 2rem;
}
Should I use Grid or Flexbox for columns?
Use Grid when you know the column structure in advance and want rows to line up across items. Use Flexbox when items should size themselves and wrap freely, such as a row of tags or buttons. They work well together: a grid for the page, flex inside each cell.
Does grid-template-columns work with named areas?
Yes. grid-template-areas names the regions while grid-template-columns sizes them. Define both on the container, and keep the number of column values equal to the number of columns in each area string.
In short
Work through the checklist in order: container, fixed vs fr, repeat(), minmax(), auto-fit or auto-fill, gap, then the overflow guards. If you only remember two things, make them minmax(0, 1fr) for safety and repeat(auto-fit, minmax(min(100%, 18rem), 1fr)) for responsive card grids. Those two patterns cover the large majority of real layouts you will build.
