CSS grid-auto-rows: Set the height of automatically created rows
grid-auto-rows sets the sizing rule for Grid rows that have no size assigned by the explicit row template. If grid-template-rows: 72px sizes the first row and grid-auto-rows: minmax(72px, auto) applies to later rows, those rows are at least 72px tall and can grow with content.
Which rows does grid-auto-rows size?
With two columns and default row-wise auto-placement, filling two cells causes another row to be created for the next item. Explicitly placing an item outside the explicit grid can also create additional tracks. Item placement determines the number of rows. grid-auto-rows determines their sizing rule, and its initial value is auto. See CSS Grid · The implicit grid.
.grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
grid-template-rows: 72px;
grid-auto-rows: minmax(72px, auto);
}
Try a fixed first row and content-sized later rows
Save the code as grid-auto-rows.html and open it. No external files or JavaScript are required. grid-template-rows sets the 72px first row, shown in yellow. The next three rows are created automatically and use minmax(72px, auto).
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Explicit and implicit row sizes</title>
<style>
body { margin: 20px; font: 16px/1.6 system-ui, sans-serif; color: #203348; }
* { box-sizing: border-box; }
h1 { font-size: 24px; }
.grid { display: grid; grid-auto-flow: row; align-items: stretch; grid-template-columns: repeat(2, minmax(0, 1fr));
grid-template-rows: 72px; grid-auto-rows: minmax(72px, auto);
gap: 10px; max-width: 600px; }
.item { min-width: 0; padding: 12px; border: 1px solid #7795a3;
background: #edf5f7; overflow-wrap: anywhere; }
.item:nth-child(-n+2) { background: #fff2cf; }
</style>
</head>
<body>
<h1>Compare grid-auto-rows values</h1>
<div class="grid">
<div class="item">A: first row</div>
<div class="item">B: first row</div>
<div class="item">C: new row</div>
<div class="item">D: new row</div>
<div class="item long">E: this item has more text. Its row grows beyond the minimum when the content needs more space. The shorter rows can keep their original height.</div>
<div class="item">F: same row</div>
<div class="item">G: new row</div>
<div class="item">H: new row</div>
</div>
</body>
</html>
The first row is 72px, and the short second and fourth rows are 72px too. The third row can grow to fit its longer description. The adjacent item stretches within that row. The other short rows can keep their size. Narrow the window to make the text wrap and see the difference. The document can grow because the grid has no fixed height.
Compare fixed sizes, minmax(), 1fr, and repeated patterns
| Example value | When to use it |
|---|---|
auto |
Lets content and layout determine the height. |
72px |
Fixes the row height. Longer content may overflow. |
minmax(72px, auto) |
Keeps a minimum and grows to fit content as needed. |
1fr |
Equalizes implicit rows in this unconstrained example. |
72px 112px |
Alternates between two fixed sizes. |
Try the grid-auto-rows values in the table one at a time. Start with 72px, which fixes even the long implicit row at that size. Text and padding may overflow if they need more room. Restore minmax(72px, auto) to let the row fit its content. See CSS Grid · grid-auto-rows.
Next try 1fr. In this example, where the grid has no fixed height and each item occupies a single row, the implicit rows grow to the same height to fit the largest content contribution. The first row stays at 72px. fr is a flexible length, and its result depends on how the track sizes and available space are calculated. See CSS Grid · Flexible lengths.
With 72px 112px, rows two through four have heights of 72px, 112px, and 72px. The fixed first row is outside the pattern. If implicit rows are created before the explicit grid, the closest one gets the last value, 112px, and the preceding one gets 72px. Shorten the long description temporarily to see the fixed pattern clearly, then restore the text and sizing rule.
Add a new row and diagnose sizing issues
Insert the element below after the last item. With nine items and two columns, a fifth row is created. The original minmax(72px, auto) gives it a 72px minimum. If the repeating pattern is still active, the fifth row is 112px. Remove the new element to return to four rows.
<div class="item">I: newly created row</div>
Remove grid-template-rows: 72px to apply the automatic sizing rule to the first row as well. If you use named areas with grid-template-areas, a row without a size from grid-template-rows can still take its size from grid-auto-rows. Also check whether a later grid shorthand resets the rule. See CSS Grid · The explicit grid.
If you get new columns instead of rows, check grid-auto-flow and any explicit placement. grid-auto-columns sizes those columns. To diagnose heights, inspect the tracks with the Grid overlay in developer tools, then check the items for a fixed height or overflowing content.




