Two properties on the container describe the tracks.
grid-template-columnssets the columns: one size per column.grid-template-rowssets the rows.
<style>
.grid > div { background: #d0e8f2; border: 1px solid #1a5276; padding: 10px; }
.grid {
display: grid;
grid-template-columns: 100px 1fr 2fr;
grid-template-rows: 60px auto;
gap: 8px;
}
</style>
<div class="grid"><div>1</div><div>2</div><div>3</div><div>4</div><div>5</div><div>6</div></div>
The first column is a fixed 100px. The other two share what is left, in a 1:2 ratio. The first row is 60px tall. The second row is auto, so it fits its content.
Sizes you can use
| Size | Meaning |
|---|---|
200px, 10rem, 30% | Fixed or relative length |
1fr, 2fr | A share of the free space. See fr |
auto | Fits the content (and stretches when there is room) |
min-content / max-content | As narrow / as wide as the content allows |
Explicit and implicit tracks
Tracks you define are explicit. Items that do not fit go into implicit rows that the browser adds. Size those with grid-auto-rows:
.grid { grid-auto-rows: minmax(80px, auto); }
Where does each item go?
Items fill the grid left to right, then top to bottom, one cell per item. The next lessons show how to control spacing (gap) and how to place items yourself (lines).
Columns do most of the work
grid-template-columns and let the rows happen. Leave the row sizes alone unless you have a reason.