CSS Grid Layout

Beginner
8 min read
Updated: Nov 2026
3 examples
Rows and columns

Definition and Usage

CSS Grid Layout divides a box into rows and columns. Set display: grid on the parent. That parent is the grid container. Each direct child is a grid item.

grid-template-columns sizes the column tracks. 1fr is one share of the free space, so repeat(3, 1fr) makes three equal columns. gap is the gutter between tracks. grid-column: 1 / 3 places an item from column line 1 to column line 3, which covers two columns.

Lines are numbered from 1.

Three columns have four lines: 1, 2, 3, and 4. grid-column: 1 / 3 stops at line 3, so the item fills columns 1 and 2.

CSS Syntax

A three-column grid, with one item placed by line numbers:

CSS
.wrapper {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  grid-auto-rows: minmax(100px, auto);
}

.one {
  grid-column: 1 / 3; /* line 1 to line 3 */
  grid-row: 1;
}

Core Ideas

Ideas every CSS Grid tutorial builds on:

IdeaExampleRemember
Containerdisplay: gridDirect children become items
Columnsrepeat(3, 1fr)Three equal column tracks
Fraction1fr 2frThe second track gets twice the free space
Guttergap: 10pxSpace between tracks
Linesgrid-column: 1 / 3Two columns, lines 1 through 3
New rowsminmax(100px, auto)At least 100px, taller if the content needs it

CSS Examples

Three grids. View Output shows the tracks the browser paints.

Example 1 — Three equal columns

repeat(3, 1fr) gives each column the same share of the free space. gap separates them.

CSS
.wrapper {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

/* items: One, Two, Three */
Try It Yourself

How It Works

  1. display: grid makes .wrapper the container. One, Two, and Three are the items.
  2. repeat(3, 1fr) builds three column tracks. Each 1fr is an equal share.
  3. gap: 10px is the space between the tracks. It is not padding around the grid.

Example 2 — Place an item from line 1 to line 3

grid-column: 1 / 3 covers the first two columns. The next item sits in column 3.

CSS
.wrapper {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.wide {
  grid-column: 1 / 3;
}
Try It Yourself

How It Works

  1. Four column lines cross a three-column grid: 1, 2, 3, and 4.
  2. 1 / 3 starts at line 1 and ends at line 3. Wide fills two tracks.
  3. Side is the next item, so it occupies the remaining cell on that row.

Example 3 — Give the second column twice the space

1fr 2fr splits the free space into three shares. The second column receives two of them.

CSS
.wrapper {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 10px;
}
Try It Yourself

How It Works

  1. 1fr + 2fr is three shares of the space left after the gap.
  2. The first column gets one share.
  3. The second column gets two shares, so it is twice as wide.

Frequently Asked Questions

CSS Grid lays out a parent’s direct children in rows and columns. Set display: grid on the parent. That parent is the grid container. Each direct child is a grid item. You then size the tracks and, when you need to, place an item between grid lines.
grid-template-columns: repeat(3, 1fr) or 1fr 1fr 1fr. The fr unit is a share of the free space. Three 1fr tracks are equal. gap: 10px adds the space between tracks.
Column lines are numbered from 1. A three-column grid has lines 1, 2, 3, and 4. grid-column: 1 / 3 starts at line 1 and stops at line 3, so the item covers the first two columns.
grid-auto-rows: minmax(100px, auto) sizes rows that you did not name. Each of those rows is at least 100px tall and grows with the content.
No. Only the direct children of the grid container are grid items. A grandchild is laid out by its own parent.

Next: Flexbox

Lay items along one row or one column.

Flexbox tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful