CSS grid-template-columns and grid-template-rows: Size Grid tracks
grid-template-columns defines the explicit columns in CSS Grid. grid-template-rows defines its explicit rows. With 80px minmax(0, 1fr) minmax(0, 2fr), the first column is 80px and the other two divide the width left after the fixed column and gaps in a 1:2 ratio.
Define explicit columns and rows
.grid {
display: grid;
grid-template-columns: 80px minmax(0, 1fr) minmax(0, 2fr);
grid-template-rows: 72px minmax(96px, auto);
}
A track is a grid row or column. The snippet defines three columns and two rows. Three columns are bounded by four grid lines. A track list can also contain repeat() and line names, so counting space-separated words does not tell you the number of columns. The initial value none creates no explicit tracks through that property. Placement can still generate implicit tracks. See CSS Grid · Explicit track sizing.
| Value | How it sizes a track |
|---|---|
80px |
Uses a fixed length. Larger content can overflow. |
50% |
Uses the container’s content size along that axis. |
auto |
Depends on content, sizing, and alignment. |
1fr |
Sets a share of the flexible space. |
minmax(0, 1fr) |
Allows a zero minimum and shares the available space. |
Try fixed and flexible tracks in a complete example
Save and open the code as grid-tracks.html. It needs no external files or JavaScript. The yellow first row is fixed at 72px. The second uses minmax(96px, auto) and can grow to fit the long text in F. A third, implicit row holds the seventh item, G. Its sizing rule is grid-auto-rows: minmax(56px, auto).
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Define Grid column widths and row heights</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; max-width: 600px; padding: 12px;
grid-template-columns: 80px minmax(0, 1fr) minmax(0, 2fr);
grid-template-rows: 72px minmax(96px, auto);
grid-auto-rows: minmax(56px, auto); gap: 12px;
border: 1px solid #7795a3; background: #edf5f7; }
.item { min-width: 0; padding: 8px; border: 1px solid #176f80;
background: white; overflow-wrap: anywhere; }
.item:nth-child(-n+3) { background: #fff2cf; }
</style>
</head>
<body>
<h1>Compare column and row sizes</h1>
<div class="grid">
<div class="item">A</div>
<div class="item">B</div>
<div class="item">C</div>
<div class="item">D</div>
<div class="item">E</div>
<div class="item">F: when this description gets longer, the row can grow beyond its minimum. Compare the result with the fixed first row.</div>
<div class="item">G</div>
</div>
</body>
</html>
At a grid border-box width of 600px, the border and padding occupy 26px, leaving 574px of content width. Two gaps use 24px and the first column uses 80px. The two flexible columns share the remaining 470px. The 1fr column is about 156.67px and the 2fr column about 313.33px.
At a grid border-box width of 350px, the same calculation leaves 220px, so the flexible columns measure about 73.33px and 146.67px. Changing the gaps or fixed track changes how much space they share. For fr rows, the calculation also depends on whether the grid has a definite height. See CSS Grid · Flexible lengths.
Repeat equal tracks or a size pattern
Replace just grid-template-columns in the complete example with the first declaration below. It creates three equal columns. With a content width of 574px, the three columns share 550px once you subtract the two 12px gaps.
grid-template-columns: repeat(3, minmax(0, 1fr));
The second declaration repeats a two-track 1:2 pattern, creating four columns. The first four items occupy the first row and the remaining three fit in the second, so no implicit row is needed. The yellow rule highlights the first three items, which need not fill a full row after a column change. Restoring the original declaration brings back the three columns and implicit third row. See CSS Grid · repeat() notation.
/* Four columns made by repeating a 1:2 pattern twice */
grid-template-columns: repeat(2, minmax(0, 1fr) minmax(0, 2fr));
Check overflow and switch to one column
Bare 1fr 2fr tracks can be affected by automatic minimum sizes when a column contains long content. In the example, minmax(0, …) allows the track to shrink, while min-width: 0 and overflow-wrap: anywhere let the card handle long text. In minmax(), a flexible fr value can be the maximum. See CSS Grid · Track sizes.
Percentage columns that total 100% can overflow once you add gaps. If a narrow track makes the content hard to read, append the following rule to style. At 480px or less, the grid uses one column and drops the explicit row heights.
@media (max-width: 480px) {
.grid {
grid-template-columns: minmax(0, 1fr);
grid-template-rows: none;
grid-auto-rows: minmax(56px, auto);
}
}
In one column, the seven items occupy seven implicit rows with a 56px minimum. A row can grow if it needs more room. Remove the media query to restore the original layout. If a different rule appears to apply, inspect the parent’s display, the explicit and implicit tracks, and any later grid shorthand in developer tools.




