CSS Grid Cheatsheet

Interactive reference for every grid property with live demos — click any value to see the layout change instantly

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.

How to Use This CSS Grid Cheatsheet

This interactive CSS Grid cheatsheet covers every container and item property with live previews you can click. Use the tabs to jump between Container Properties, Item Properties, and Common Patterns — or type in the search box to filter by property name or keyword.

Step 1: Understand the two key concepts

CSS Grid has two layers: the grid container (the parent element you apply display: grid to) and grid items (the direct children). Container properties set up the structure — tracks, gaps, alignment. Item properties control where individual children are placed within that structure.

Step 2: Define your column and row tracks

Start with grid-template-columns to define how many columns exist and how wide each is. The fr unit divides remaining space proportionally — repeat(3, 1fr) creates three equal columns. For responsive grids, combine repeat(auto-fill, minmax(240px, 1fr)) to let columns wrap automatically without media queries.

Step 3: Use named areas for complex layouts

grid-template-areas lets you define layouts with ASCII-art syntax. Write each row as a quoted string with space-separated names. Repeat a name across columns to make that region span multiple tracks. Then assign items using grid-area: name on each child. This approach makes complex layouts like holy grail extremely readable.

Step 4: Place items with grid-column and grid-row

For precise placement, use grid-column: start / end on individual items. Line numbers start at 1 from the left edge. Negative numbers count from the right — 1 / -1 spans the full width. The span keyword is simpler: grid-column: span 2 spans two columns from wherever the item naturally falls.

Step 5: Control alignment

justify-items and align-items align all items within their cells (horizontal and vertical respectively). justify-content and align-content distribute the entire grid when it's smaller than its container. For one-off overrides on a single item, use justify-self, align-self, or the place-self shorthand.

Browser support

CSS Grid is supported in all modern browsers (Chrome, Firefox, Safari, Edge) — over 97% of global users. The subgrid value for grid-template-columns/rows has broader support as of 2023. For most production use cases, all properties covered in this CSS Grid cheatsheet are safe to use without any fallback.

Frequently Asked Questions

Is this CSS Grid cheatsheet free?

Yes, completely free with no signup, no account, and no hidden fees. Everything runs in your browser with no data sent to any server.

Is my data safe when using this tool?

Absolutely. This cheatsheet runs entirely in your browser — no data is collected or stored anywhere.

What is the difference between CSS Grid and Flexbox?

CSS Grid is a two-dimensional layout system that controls both rows and columns simultaneously. Flexbox is one-dimensional — it handles either a row or a column at a time. Grid is ideal for full-page layouts and complex two-axis positioning; Flexbox is better for distributing items along a single axis.

What does the fr unit mean in CSS Grid?

The fr (fractional) unit represents a fraction of the available space in the grid container. For example, grid-template-columns: 1fr 2fr creates two columns where the second is twice as wide as the first. After fixed-size columns are placed, fr units divide the remaining space proportionally.

What is the difference between auto-fill and auto-fit in CSS Grid?

Both auto-fill and auto-fit create as many columns as will fit in the container. The difference appears when there are fewer items than columns: auto-fill keeps empty column tracks, preserving their space; auto-fit collapses empty tracks so existing items can grow to fill the space.

How do grid-column and grid-row work?

grid-column and grid-row are shorthand properties that let a grid item span across tracks. They use line numbers or span keywords. For example, grid-column: 1 / 3 makes an item start at column line 1 and end at line 3, spanning 2 columns. grid-column: span 2 does the same without specifying start/end lines.

What is grid-template-areas and when should I use it?

grid-template-areas lets you define a grid layout using named regions with a visual ASCII-art syntax. It makes complex layouts like holy grail (header, sidebar, main, footer) easy to read and maintain. Each named area must form a rectangle. Items are then placed using grid-area: name on child elements.

Can I print or save this CSS Grid cheatsheet?

Yes. Use your browser's print function (Ctrl+P / Cmd+P) to print or save as PDF. The cheatsheet is designed to be scannable and readable in printed form.