How do grid auto-fit and auto-fill change a responsive card layout?
Quick answer
Both auto-fit and auto-fill create as many repeated columns as fit the container. If there’s space for more columns than you have cards, auto-fill keeps the unused tracks, while auto-fit collapses them after placing items. With flexible 1fr tracks, that means existing cards can grow wider with auto-fit; with auto-fill, empty tracks remain part of the layout. Choose based on whether you want that space preserved.
The question, the details, the next step.
A practical checklist
Keep the card minimum size and gap identical while comparing both modes.
Test a wide container with one card, two cards, and a full row.
Check whether sparse rows look better with wider cards or preserved empty tracks.
Repeat the comparison at a narrow width and with your real card content.
Choose
auto-fitto collapse empty tracks, orauto-fillto preserve them.
A few more useful answers
Do `auto-fit` and `auto-fill` always produce different layouts?
No. If there are no empty repeated tracks to collapse, their behavior can look the same. The distinction matters when the grid can fit more tracks than the items occupy. [S1]
Will `auto-fit` always make cards wider?
Not necessarily. It collapses empty tracks, but the result depends on track sizing and the items. The expansion described here is the typical effect when the tracks have a flexible 1fr maximum. [S1]
Is `200px` the right minimum for every card grid?
No. It is just an example. Choose a minimum that works for your content and container, then test the resulting layout at the widths your page needs.
Sources
References used for this guide.
- [S1] repeat() CSS function reference developer.mozilla.org · Checked
- [S2] Realizing common layouts using grids developer.mozilla.org · Checked
