How can I make grid columns share space but keep a minimum width?
Quick answer
Set the columns to repeat(auto-fill, minmax(200px, 1fr)), replacing 200px with the smallest width that suits your content. minmax() sets a track-size range, and 1fr shares the remaining space. With auto-fill, Grid fits as many minimum-width tracks as the container allows, so the column count can change as the container resizes. [S1][S2]
The question, the details, the next step.
A practical checklist
Choose the smallest track width that suits the real card content.
Use
repeat(auto-fill, minmax([minimum], 1fr))for the columns.Set a gap that fits the design and include it when evaluating available space.
Check the grid at narrow, intermediate, and wide container sizes.
Inspect overflow and content fit; do not assume the minimum prevents every layout issue.
A few more useful answers
Does `1fr` mean every column always has exactly the same width?
In this pattern, the repeated tracks share the remaining space using the same 1fr maximum. Their final sizing still depends on the available container space and layout constraints. [S2]
Can I use a different minimum than `200px`?
Yes. The 200px value is an example; choose a minimum that suits your content and design, then check the result in the actual container. [S1]
Will this pattern guarantee there is no overflow?
No. minmax() defines a track-size range, but other layout constraints or content can still cause overflow. [S2]
Sources
References used for this guide.
- [S1] Realizing common layouts using grids developer.mozilla.org · Checked
- [S2] grid-template-columns CSS property reference developer.mozilla.org · Checked
