Web development

Build a responsive card grid

Use CSS Grid with auto-fit and minmax to arrange cards according to the available width. Let the grid collapse naturally instead of requiring a separate breakpoint for every possible column count.

Worked example

HTML example · save as example.html and open in a browser

<style>
.cards{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,16rem),1fr));gap:1rem}
.cards article{padding:1rem;border:1px solid #b5c2d1}
</style>
<div class="cards"><article><h2>Files</h2><p>Read a guide.</p></article><article><h2>Browser</h2><p>Find a diagnosis.</p></article></div>

How it works

The minimum card width is capped by the container’s width so a very narrow viewport does not force overflow. Auto-fit collapses unused tracks, and fractional units distribute remaining space. Gap provides consistent separation without per-card margin calculations.

Limits and mistakes

Grid does not guarantee readable content inside each card. Long strings, fixed-width children, and unusual source order still need testing. Keep DOM order meaningful rather than using visual placement to rearrange a confusing reading sequence.

Check the result

Resize from one column to several. Confirm cards fill the available space, headings wrap, and the keyboard order matches the visible reading order.

Sources

Reference documentation for the behavior used in this guide: