A CSS Grid cheatsheet is a quick reference for every grid container and item property. CSS Grid is the most powerful two-dimensional layout system in CSS, letting you control rows and columns simultaneously with precise placement and responsive patterns. Click any value below to see a live preview instantly.

display
Activates grid on the container element
1
2
3

grid makes the element a block-level grid container. inline-grid makes it inline-level — it sits inline with surrounding text.

grid-template-columns
Defines the column tracks of the grid
1
2
3
4
5
6

fr = fractional unit — divides remaining space. repeat(n, size) repeats a track n times. minmax(min, max) sets a flexible size range.

grid-template-rows
Defines the row tracks of the grid
1
2
3
4

auto sizes rows to fit content. Explicit row heights give precise control over the grid's vertical rhythm.

grid-template-areas
Define named grid regions with ASCII-art syntax
header
sidebar
main
footer

Each string is a row. Repeat a name across columns to span. Use . for empty cells. Assign items with grid-area: name.

gap / row-gap / column-gap
Sets space between grid tracks
1
2
3
4
5
6

gap: row col sets row and column gaps separately. row-gap and column-gap set them individually.

justify-items
Aligns grid items along the inline (horizontal) axis
1
2
3

stretch (default) makes items fill their cell width. Other values shrink items to content size and align them within the cell.

align-items
Aligns grid items along the block (vertical) axis
1
2
3

Controls vertical placement within each row track. Use with varying-height items to see the difference clearly.

justify-content
Distributes the entire grid along the inline axis
1
2
3

Only has effect when total column widths are less than the container. Uses fixed-width 60px columns in this demo so you can see the distribution.

align-content
Distributes the entire grid along the block axis
1
2
3
4
5
6

Only has effect when total row heights are less than the container height. The demo uses fixed 40px rows with extra container height.

grid-auto-rows / grid-auto-columns
Size of implicitly created tracks
1
2
3
4
5

When items overflow defined rows, implicit tracks are created. grid-auto-rows sizes these new rows. Use minmax(min, auto) to enforce a minimum height.

grid-auto-flow
Controls how auto-placed items flow into the grid
span 2
2
3
4
5

row (default) fills row by row. column fills column by column. dense back-fills gaps when earlier items span multiple tracks.