CSS Grid Cheatsheet - Grid Layout Reference
For developers building full-page layouts with both rows and columns. Unlike Flexbox, Grid controls both axes at once, so it is the right tool for an app shell or a dashboard with a fixed header and footer. By the end you can define a repeatable template, place items into named areas, size columns with fr units so the layout fills the viewport, and build a responsive grid without hammering media queries.
Container Definition 8
display: gridEnable grid layout (block-level)
display: inline-gridEnable grid layout (inline-level)
grid-template-columns: 1fr 2fr 1frDefine column tracks & ratio
grid-template-rows: 100px auto 100pxDefine row tracks & sizes
grid-template-columns: repeat(3, 1fr)Repeat 3 equal columns
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr))Auto-fill responsive columns
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr))Auto-fit responsive columns
grid-template-areas: "header header" "sidebar main" "footer footer"Visual named-area layout
Gap & Alignment 10
gap: 16pxRow & column gap
row-gap: 16pxRow gap only
column-gap: 16pxColumn gap only
justify-items: stretchStretch horizontally in cell (default)
justify-items: centerCenter horizontally in cell
align-items: centerCenter vertically in cell
place-items: centerSet both horizontal & vertical
justify-content: centerAlign grid horizontally
align-content: centerAlign grid vertically
place-content: centerSet both grid alignments
Cells & Spans 7
grid-area: headerPlace item into named area
grid-area: 1 / 1 / 3 / 3Line-based: row-start/col-start/row-end/col-end
grid-column: 1 / 3Span columns: line 1 to 3
grid-row: 1 / span 2Span 2 rows from line 1
grid-column: 1 / -1Span full row (line 1 to end)
grid-column: span 2Span 2 columns
grid-row: span 3Span 3 rows
Explicit & Implicit Tracks 6
grid-auto-columns: 100pxImplicit column track size
grid-auto-rows: 100pxImplicit row track size
grid-auto-flow: rowAuto-placement: by row (default)
grid-auto-flow: columnAuto-placement: by column
grid-auto-flow: denseDense packing, fill gaps
grid-auto-flow: row denseRow-wise dense packing
Common Patterns 6
grid-template-columns: 1fr 1fr 1frThree equal columns
grid-template-columns: 200px 1frSidebar + main content
grid-template-columns: repeat(12, 1fr)12-column grid system
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr)Prevent overflow break
grid-template-areas: "header" "main" "footer"Single-column stacked layout
grid-column: 1 / -1Item spans full row
Responsive Tips 5
repeat(auto-fit, minmax(200px, 1fr))Auto-fit, empty tracks collapse
repeat(auto-fill, minmax(150px, 1fr))Auto-fill, keeps empty tracks
repeat(auto-fit, minmax(min(100%, 250px), 1fr))min() prevents small-screen overflow
@media (max-width: 768px) { grid-template-columns: 1fr }Single column on mobile
grid-auto-rows: minmax(150px, auto)Responsive row height
Tips
- fr is a flexible unit — 1fr 2fr means the second column is twice as wide as the first.
- minmax(200px, 1fr) means min 200px, max flexible fill; pair with auto-fill for responsiveness.
- grid-template-areas defines layout visually, improving code readability.
- gap replaces the old grid-gap and is the current standard syntax.
- auto-fit collapses empty tracks to stretch and fill; auto-fill keeps them — responsive layouts usually use auto-fit.
Official References
Each command links to its official documentation below, so you can verify the latest usage and read deeper.
Maintained by LaoHand
Publicly updated on Jul 21, 2026, continuously proofread against official docs.
Contact Us
Wrong command or description? Send us corrections, business inquiries or product feedback by email.
Contact Us