Skip to content

Grid Template Columns & Rows

On the last page, display: grid; was pure intent.

This is where Grid finally shows up.

When you define tracks (columns and/or rows), you create the explicit grid — and the browser has a structure to apply.


You can specify as many columns as you want, using any valid length units:

.layout {
display: grid;
grid-template-columns: 240px 240px 240px 240px;
}

Once columns exist, grid items begin flowing into the cells automatically — left to right, top to bottom.


Rows work the same way:

.layout {
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
grid-template-rows: 10rem 10rem;
}

If you define fewer rows than you have items for, Grid will create more rows as needed (that’s the implicit grid, coming soon).


  • Tracks: the columns and rows you define
  • Lines: the boundaries between tracks (they start at 1, not 0)
  • Cells: the rectangles formed by intersecting tracks

Grid is basically: lines first, placement second.


Same HTML. New rules.
Define tracks — and the grid snaps into existence.


If you want Grid to do something:

  1. Set the container: display: grid;
  2. Define tracks: grid-template-columns and/or grid-template-rows

No tracks, no grid.

📘 Grid Template Columns and Rows Study Guide (PDF)

📘 Grid Template Columns and Rows Infographic (PNG)

Infographic explaining CSS Flexbox direction and axes, showing how flex-direction defines the main axis and cross axis, with visual examples for row, row-reverse, column, and column-reverse, and how justify-content and align-items map to each axis.

Clean, smart, proportional division of available space.