Skip to content

CSS Tutorial CSS Grid

CSS grid-template-columns and grid-template-rows

Lesson 100 of 182 2 min read By Deepak Paswan Updated Oct 4, 2026

Two properties on the container describe the tracks.

  • grid-template-columns sets the columns: one size per column.
  • grid-template-rows sets the rows.
index.html
HTML
<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

SizeMeaning
200px, 10rem, 30%Fixed or relative length
1fr, 2frA share of the free space. See fr
autoFits the content (and stretches when there is room)
min-content / max-contentAs 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:

style.css
CSS
.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).

lightbulb
Columns do most of the work
A lot of grids define only grid-template-columns and let the rows happen. Leave the row sizes alone unless you have a reason.