CSS Grid Cheat Sheet: Columns, Rows, Areas, and Responsive Layouts
A practical CSS Grid reference with repeat(), minmax(), auto-fit, alignment, named areas, and responsive layout examples.
TechSilo
Technology writer & developer
CSS Grid handles two-dimensional layout: you can position content by columns and rows without combining floats or complicated width calculations.
Start with a simple grid
.dashboard {
display: grid;
grid-template-columns: 16rem minmax(0, 1fr);
gap: 1.25rem;
}The sidebar occupies 16rem, while the main region takes the remaining space. minmax(0, 1fr) allows long content to shrink instead of forcing horizontal overflow.
The most useful properties
| Property | Purpose |
| --- | --- |
| display: grid | Turn an element into a grid container |
| grid-template-columns | Define explicit columns |
| grid-template-rows | Define explicit rows |
| gap, row-gap, column-gap | Space between tracks |
| grid-column | Place or span an item across columns |
| grid-row | Place or span an item across rows |
| place-items | Shorthand for align-items and justify-items |
| place-content | Align the entire grid when free space exists |
Repeat tracks without hard-coding every width
.gallery {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 1rem;
}For truly responsive cards, let the browser decide how many columns fit:
.card-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr));
gap: 1rem;
}Here auto-fit collapses unused tracks, while auto-fill preserves empty track slots. The min(100%, 16rem) guard prevents a minimum card width from overflowing narrow phones.
Span columns and rows
.featured {
grid-column: 1 / -1; /* Across the full explicit grid */
}
.metrics {
grid-row: span 2; /* Occupies two row tracks */
}Avoid forcing visual order to differ from the HTML source order. Keyboard focus and screen readers generally follow the DOM order, not the layout positions.
Named grid areas
.page {
display: grid;
grid-template:
"header header" auto
"aside main" 1fr
"footer footer" auto
/ 15rem minmax(0, 1fr);
gap: 1rem;
}
header { grid-area: header; }
aside { grid-area: aside; }
main { grid-area: main; }
footer { grid-area: footer; }
@media (max-width: 48rem) {
.page {
grid-template:
"header" auto
"main" 1fr
"aside" auto
"footer" auto / minmax(0, 1fr);
}
}Named areas are useful when the same layout needs different arrangements across breakpoints.
Center anything inside a grid
.centered {
display: grid;
place-items: center;
min-height: 20rem;
}Debug checklist
If a grid overflows, inspect the minimum sizes of its children, long unbroken words, and the difference between 1fr and minmax(0, 1fr). Use browser DevTools' grid overlay to see each track. For small components where only one direction matters, Flexbox may be simpler.
Pair this reference with the [CSS Color Tools](/tools/color-tools) when you are styling a responsive interface.
Want to put this into practice?
Explore TechSilo's free developer tools for practical utilities you can use directly in your browser.
Related blog posts
CSS Flexbox Cheat Sheet: Alignment, Wrapping, and Responsive Rows
A practical CSS Flexbox reference covering display:flex, flex-direction, gap, justify-content, align-items, flex-wrap, and flex shorthand.
Read postnpm Scripts Cheat Sheet: Commands, Arguments, and Automation
A developer reference for package.json scripts, npm run, pre/post hooks, environment variables, and safe task automation.
Read postTypeScript Utility Types Cheat Sheet: Pick, Omit, Partial and More
Practical examples of TypeScript Partial, Required, Pick, Omit, Record, ReturnType, Awaited, Extract, and Exclude.
Read postUnderstanding CSS Specificity: How the Cascade Picks Styles
Understand CSS specificity, source order, cascade layers, :is(), :where(), and practical ways to debug overriding styles.
Read postGit Commands Cheat Sheet
1. Quick Reference | Command | Description | | --- | --- | | git init | Initialize a new Git repository | | git clone [url] | Clone a Git repository from a URL | | git add [file] | Stage a file ...
Read post