CSS Grid Cheat Sheet
A reference for CSS Grid, defining tracks with grid-template-columns and repeat, sizing with fr and minmax, gaps, grid-template-areas, and placing items across the grid.
A reference to CSS Grid, the two-dimensional layout model. Define rows and columns on the grid container, and place items on the grid with the item properties. Click any value to copy it.
Container properties
| Property | What it does |
|---|---|
display: grid | Turn an element into a grid container |
grid-template-columns: 1fr 2fr | Define columns (here, two tracks) |
grid-template-rows: auto 1fr | Define rows |
repeat(3, 1fr) | Repeat a track (repeat(auto-fit, minmax(200px, 1fr)) is responsive) |
gap: 1rem | Space between tracks (row-gap / column-gap) |
grid-template-areas | Name grid cells for readable layouts |
justify-items: center | Align items in their cell along the row (align-items for the column) |
Item properties
| Property | What it does |
|---|---|
grid-column: 1 / 3 | Span an item from line 1 to line 3 |
grid-row: span 2 | Span two rows |
grid-area: header | Place an item in a named area |
justify-self: end | Align one item in its cell along the row (align-self for the column) |
order: 2 | Change placement order (default 0) |
Tip: for a responsive card grid with no media queries, use
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)). The fr
unit shares leftover space, so columns stretch and wrap as the viewport changes.
What this does
A CSS Grid cheat sheet covers defining tracks with grid-template-columns and repeat, sizing with fr and minmax, gaps, grid-template-areas, and placing items.
How to use it
- Browse by property.
- Find the value you need.
- Copy it with one tap.
- Paste it into your stylesheet.
Example
grid-template-columns: repeat(3, 1fr) makes three equal columns.
Sources & methodology
Last updated .
Frequently asked questions
Grid or Flexbox — when do I use which?
Use grid for two-dimensional layouts with aligned rows and columns, and Flexbox for one-dimensional rows or columns where items size themselves.
How do I make a responsive grid without media queries?
Use repeat(auto-fit, minmax(200px, 1fr)). Items flow onto as many columns as fit, then wrap and stretch as the viewport changes.
What is the fr unit?
fr is a fraction of the free space in the track. With grid-template-columns: 1fr 2fr, the second column gets twice the remaining width of the first after fixed sizes are taken out.
Related tools
Git Cheat Sheet
The Git commands you use every day, setup, the add/commit/push workflow, branching and merging, working with remotes, and undoing mistakes safely.
Docker Cheat Sheet
A reference for everyday Docker, building and tagging images, running and managing containers, ports and volumes, system cleanup, and Docker Compose.
Vim Cheat Sheet
A reference for the Vim editor, modes, moving around, editing, search and replace, and saving or quitting, including the escape hatch for when you are stuck.
Regex Cheat Sheet
A regular-expression reference, character classes, anchors, quantifiers, groups and alternation, lookarounds, common ready-made patterns, and flags.