CSS Grid Cheatsheet
cssComplete CSS Grid reference with examples.
Container Properties - Display & Template
display: grid | inline-grid;Defines the element as a grid container
.container { display: grid; }grid-template-columns: <track-size> ... | <line-name> <track-size> ...;Defines the columns of the grid with a space-separated list of values
grid-template-columns: 200px 1fr 2fr;grid-template-rows: <track-size> ... | <line-name> <track-size> ...;Defines the rows of the grid with a space-separated list of values
grid-template-rows: 100px auto 200px;grid-template-areas: "<area-name> ..." ...;Defines named grid areas using a visual ASCII-art style syntax
grid-template-areas:
"header header"
"sidebar main"
"footer footer";grid-template: <rows> / <columns>;Shorthand for grid-template-rows, grid-template-columns, and grid-template-areas
grid-template: 100px 1fr / 200px 1fr;Container Properties - Gap & Spacing
gap: <row-gap> <column-gap>;Sets the gap between rows and columns
gap: 20px 10px;row-gap: <length> | <percentage>;Sets the gap between grid rows
row-gap: 15px;column-gap: <length> | <percentage>;Sets the gap between grid columns
column-gap: 20px;Container Properties - Alignment
justify-items: start | end | center | stretch;Aligns grid items along the inline (row) axis within their cell
justify-items: center;align-items: start | end | center | stretch | baseline;Aligns grid items along the block (column) axis within their cell
align-items: start;place-items: <align-items> <justify-items>;Shorthand for align-items and justify-items
place-items: center start;justify-content: start | end | center | stretch | space-around | space-between | space-evenly;Aligns the entire grid along the inline (row) axis within the container
justify-content: space-between;align-content: start | end | center | stretch | space-around | space-between | space-evenly;Aligns the entire grid along the block (column) axis within the container
align-content: center;place-content: <align-content> <justify-content>;Shorthand for align-content and justify-content
place-content: center space-evenly;Container Properties - Auto Placement
grid-auto-columns: <track-size> ...;Specifies the size of implicitly created column tracks
grid-auto-columns: 100px;grid-auto-rows: <track-size> ...;Specifies the size of implicitly created row tracks
grid-auto-rows: minmax(100px, auto);grid-auto-flow: row | column | row dense | column dense;Controls how auto-placed items are inserted in the grid
grid-auto-flow: row dense;grid: <grid-template> | <grid-auto-flow> [<grid-auto-rows> / <grid-auto-columns>];Shorthand for all grid container properties
grid: auto-flow dense / 1fr 1fr;Item Properties
grid-column-start: <line> | span <number> | auto;Determines where a grid item starts on the column axis
grid-column-start: 2;grid-column-end: <line> | span <number> | auto;Determines where a grid item ends on the column axis
grid-column-end: span 2;grid-column: <start> / <end>;Shorthand for grid-column-start and grid-column-end
grid-column: 1 / 3;grid-row-start: <line> | span <number> | auto;Determines where a grid item starts on the row axis
grid-row-start: 1;grid-row-end: <line> | span <number> | auto;Determines where a grid item ends on the row axis
grid-row-end: span 3;grid-row: <start> / <end>;Shorthand for grid-row-start and grid-row-end
grid-row: 2 / 4;grid-area: <name> | <row-start> / <col-start> / <row-end> / <col-end>;Assigns an item to a named area or specifies its position
grid-area: header;justify-self: start | end | center | stretch;Aligns a single grid item along the inline (row) axis
justify-self: end;align-self: start | end | center | stretch | baseline;Aligns a single grid item along the block (column) axis
align-self: center;place-self: <align-self> <justify-self>;Shorthand for align-self and justify-self
place-self: center end;Sizing Functions & Units
<number>frRepresents a fraction of the available space in the grid container
grid-template-columns: 1fr 2fr 1fr;repeat(<count>, <track-list>)Repeats a track pattern a specified number of times
grid-template-columns: repeat(3, 1fr);minmax(<min>, <max>)Defines a size range between min and max values
grid-template-columns: minmax(200px, 1fr);repeat(auto-fill, <track-size>)Creates as many tracks as fit in the container, including empty tracks
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));repeat(auto-fit, <track-size>)Creates as many tracks as fit, collapsing empty tracks to zero
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));fit-content(<length-percentage>)Clamps size to content up to a maximum value
grid-template-columns: fit-content(300px) 1fr;min-contentSize based on the minimum content size of the track items
grid-template-columns: min-content 1fr;max-contentSize based on the maximum content size of the track items
grid-template-columns: max-content 1fr;Common Patterns
display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px;Creates an equal three-column grid with consistent gaps
.grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 20px;
}grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));Creates a responsive grid that adjusts column count based on container width
.responsive {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}grid-template: auto 1fr auto / auto 1fr auto;Classic header-sidebar-main-sidebar-footer layout using named areas
.layout {
display: grid;
grid-template-areas:
"header header header"
"nav main aside"
"footer footer footer";
}grid-template-columns: 250px 1fr;Fixed sidebar with flexible main content area
.sidebar-layout {
display: grid;
grid-template-columns: 250px 1fr;
}display: grid; place-items: center;Centers a single item both horizontally and vertically
.centered {
display: grid;
place-items: center;
height: 100vh;
}grid-column: 1 / -1;Makes an item span from first to last column line
.full-width {
grid-column: 1 / -1;
}