Equal-height cards with CSS Grid and grid-auto-rows
In CSS Grid, ordinary cards that each occupy one cell can stretch to the height of their own row. To make multiple implicit rows equally tall in a grid without a fixed height, use grid-auto-rows: 1fr. The example compares that with the default auto rows.
Match cards within a row or across all rows
A track is a row or column between adjacent grid lines. The snippet explicitly defines two columns. It leaves rows to be created as cards are placed, so grid-auto-rows supplies their sizing rule. With no fixed grid height and one cell per card, equal 1fr rows take the height needed to fit the largest content contribution. See CSS Grid · grid-auto-rows and CSS Grid · Flexible lengths.
.grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 12px;
grid-auto-rows: 1fr;
}
Compare auto and 1fr rows in a complete example
Save and open the full example as grid-equal-cards.html. It needs no external files or JavaScript. Both grids contain the same four cards. Only the second sets grid-auto-rows: 1fr. align-items: stretch explicitly tells card boxes to fill their rows.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Compare row heights in a card grid</title>
<style>
body { margin: 20px; font: 16px/1.6 system-ui, sans-serif; color: #203348; }
* { box-sizing: border-box; }
h1 { font-size: 24px; } h2 { margin: 20px 0 8px; font-size: 18px; }
.grid { display: grid; align-items: stretch; grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 12px; max-width: 600px; }
.card { min-width: 0; padding: 16px; border: 1px solid #7795a3;
border-radius: 6px; background: #edf5f7; overflow-wrap: anywhere; }
.card h3 { margin: 0 0 8px; font-size: 16px; }
.card p { margin: 0; }
.same { grid-auto-rows: 1fr; }
</style>
</head>
<body>
<h1>Compare Grid card heights</h1>
<h2>Default auto rows</h2>
<div class="grid normal">
<article class="card"><h3>Card A</h3><p>A short description.</p></article>
<article class="card"><h3>Card B</h3><p>This card has a longer description to show how content affects row height. The other card in this row takes the same height, but a different row can stay much shorter.</p></article>
<article class="card"><h3>Card C</h3><p>An ordinary description.</p></article>
<article class="card"><h3>Card D</h3><p>A brief description.</p></article>
</div>
<h2>All rows set to 1fr</h2>
<div class="grid same">
<article class="card"><h3>Card A</h3><p>A short description.</p></article>
<article class="card"><h3>Card B</h3><p>This card has a longer description to show how content affects row height. The other card in this row takes the same height, but a different row can stay much shorter.</p></article>
<article class="card"><h3>Card C</h3><p>An ordinary description.</p></article>
<article class="card"><h3>Card D</h3><p>A brief description.</p></article>
</div>
</body>
</html>
In the first grid, A and B share one row height, and C and D share another. The card with longer text makes the first row taller. In the second grid, both rows fit that long card and all four boxes have equal heights. The actual height depends on text length, font, and column width.
At a content width of 600px, subtracting the 12px column gap leaves 588px, or 294px for each column. minmax(0, 1fr) gives each track a zero minimum and an equal share of the space. overflow-wrap: anywhere allows a long address to break inside a card. See CSS Grid · grid-template-columns.
Add a row and change the amount of content
Insert the card below after the last card in the second grid. Five cards in two columns generate a third row, which also uses 1fr. The new card occupies its first cell and the other cell stays empty.
<article class="card">
<h3>Card E</h3>
<p>Adding another item creates a new row.</p>
</article>
Duplicate the paragraph in card B in both grids. With auto, only the row containing the card grows. With 1fr, the other rows grow as well. Delete the duplicate text and the extra card to restore the original example.
If a grid also sets grid-template-rows: 80px 140px, its first two rows keep those sizes. Only a newly created third row gets its rule from grid-auto-rows. For consistent sizing across all rows, remove unneeded explicit rows or make the explicit and implicit rules consistent.
Switch to one column and diagnose unequal heights
The example keeps two columns even in a narrow window for comparison. If that makes actual card text hard to read, add the rules below at the end of style to switch to one column at 480px or less. Returning the rows to auto shrinks the extra space on shorter cards when they are stacked.
@media (max-width: 480px) {
.grid { grid-template-columns: minmax(0, 1fr); }
.same { grid-auto-rows: auto; }
}
To diagnose a mismatch, inspect whether the row tracks differ or the card boxes differ within equal tracks. A fixed height, a max-height, or align-self: start can stop the card from filling its row. A constrained grid height or a card spanning several rows also brings content minimums and flexible space into the calculation. See CSS Grid · Grid item sizing.




