CSS Grid Essentials

CSS Grid cheat sheet: every property, explained

All CSS Grid container properties, item properties and alignment shortcuts in one reference. Includes the fr unit explained, common layout patterns and a 4-language syntax comparison.

CSS Grid container properties

Apply display:grid to any element to activate it as a grid container and unlock all grid properties.

PropertyValuesDescription
displaygrid or inline-gridActivates the grid formatting context. All direct children become grid items.
grid-template-columns1fr 2fr, repeat(3, 1fr), repeat(auto-fill, minmax(200px, 1fr)), 200px 1frDefines column track sizes. fr divides remaining space after gaps.
grid-template-rowsauto, 100px 1fr, repeat(3, 200px)Defines row track sizes. auto lets content determine the height.
grid-template-areasNamed area strings in quotes, one per row. Use . for empty cells.Defines named template regions assigned to items via grid-area.
grid-template-Shorthand combining grid-template-rows / grid-template-columns. Rarely used alone – prefer the longhand properties for clarity.
column-gap / row-gapAny length value (px, rem, %)Sets the gutter between columns and rows. Replaces the deprecated grid-column-gap and grid-row-gap.
gaprow-gap column-gap, or a single value for bothShorthand. gap: 1rem sets equal gaps. gap: 1rem 2rem sets rows then columns.
justify-itemsstart | end | center | stretch (default)Aligns grid items along the inline (horizontal) axis inside their cell.
align-itemsstart | end | center | stretch (default) | baselineAligns grid items along the block (vertical) axis inside their cell.
place-itemsalign-items justify-itemsShorthand. place-items: center centers items in both axes. Very useful for centering.
justify-contentstart | end | center | space-between | space-around | space-evenlyDistributes grid tracks horizontally when total track width is less than the container.
align-contentstart | end | center | space-between | space-around | space-evenlyDistributes grid tracks vertically when total track height is less than the container.
grid-auto-columnsAny track size valueSets the size of columns created outside the explicit grid – when items are placed beyond defined columns.
grid-auto-rowsAny track size valueSets the size of automatically created rows. Common use: grid-auto-rows: minmax(100px, auto) for equal-minimum card rows.
grid-auto-flowrow (default) | column | denseControls how auto-placed items fill the grid. dense fills gaps with smaller items – useful for photo galleries.

CSS Grid item properties

Apply these to direct children of a grid container to control their placement, spanning and alignment.

PropertyValuesDescription
grid-column-startLine number or named lineDefines which vertical grid line the item starts on. 1 = the first line.
grid-column-endLine number, named line, or span NDefines where the item ends. span 2 means span across two columns.
grid-columnstart / endEg: grid-column: 1 / 3 spans from line 1 to line 3. grid-column: 1 / span 2 does the same thing.
grid-row-startLine number or named lineDefines which horizontal grid line the item starts on.
grid-row-endLine number, named line, or span NDefines where the item ends on the row axis.
grid-rowstart / endEg: grid-row: 1 / 3 or grid-row: 1 / span 2. Same shorthand pattern as grid-column.
grid-areaNamed area from grid-template-areas, or row-start / col-start / row-end / col-endThe most powerful placement shorthand.
justify-selfstart | end | center | stretchOverrides justify-items for a single grid item along the inline axis.
align-selfstart | end | center | stretchOverrides align-items for a single grid item along the block axis.
place-selfalign-self justify-selfShorthand for both axes on a single item.

The fr unit explained

fr stands for fraction. 1fr means one equal share of the available space after fixed widths and gaps are subtracted. Think of it as slicing the remaining space like a pizza – 3 equal slices is 1fr 1fr 1fr.

1fr
1fr
1fr

grid-template-columns: 1fr 1fr 1fr

Example 1: grid-template-columns: 1fr 1fr 1fr – three equal columns. Example 2: grid-template-columns: 2fr 1fr – left column is twice as wide. Example 3: grid-template-columns: 200px 1fr – fixed sidebar, flexible content.

Percentage widths include the gap in their calculation, so 3 x 33.33% will overflow if there is a gap. fr excludes gaps – it divides only what is left after them. This makes fr simpler and more predictable.

Common CSS Grid patterns

Equal responsive columns

CSS
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}

Auto-wraps cards at any width without media queries.

Holy Grail layout

CSS
.grid {
  display: grid;
  grid-template-columns: 200px 1fr 200px;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    'header header header'
    'left main right'
    'footer footer footer';
}

Header, footer, main and two sidebars.

Named areas

CSS
.container {
  display: grid;
  grid-template-columns: 1fr 2fr;
  grid-template-areas:
    'sidebar content'
    'sidebar content';
}
.sidebar { grid-area: sidebar; }
.content { grid-area: content; }

Names make layout intent clear.

Dense packing

CSS
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  grid-auto-flow: dense;
  gap: 0.5rem;
}

dense fills gaps left by items of different sizes, useful for masonry-style galleries.

CSS Grid in 4 languages

The same 3-column responsive grid expressed in CSS, Tailwind, JavaScript and SCSS.

CSS
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}
Tailwind
<div class="grid grid-cols-3 gap-4">
JavaScript
const el = document.querySelector('.grid');
el.style.display = 'grid';
el.style.gridTemplateColumns = 'repeat(3, 1fr)';
el.style.gap = '1rem';
SCSS
$cols: 3;
.grid {
  display: grid;
  grid-template-columns: repeat($cols, 1fr);
  gap: 1rem;
}

Frequently asked questions

What is the most important CSS Grid property to learn first?
grid-template-columns. It defines how many columns your grid has and how wide they are. Once you understand track sizing and the fr unit, the rest of CSS Grid becomes much easier.
What does fr mean in CSS Grid?
fr stands for fraction. 1fr means one equal share of the remaining space after fixed widths and gaps are subtracted. 2fr gets twice as much space as 1fr.
When should I use CSS Grid instead of Flexbox?
Use CSS Grid for two-dimensional layouts – when you need to control both rows and columns. Use Flexbox for one-dimensional layouts – a row of buttons or a vertical stack of items.
How do I make a responsive CSS Grid without media queries?
Use repeat(auto-fill, minmax(minWidth, 1fr)). This creates as many columns as will fit at the minimum width, and they grow to fill the rest. No media queries needed.
How do grid-template-areas work?
Define named regions in the container as quoted strings – one string per row. Then assign each grid item to a region using grid-area: name. The visual layout in the CSS matches the actual layout on screen.
How do I make a grid item span multiple columns?
Use grid-column: span N (eg: grid-column: span 2 to span two columns) or use grid-column: start / end (eg: grid-column: 1 / 3 to run from line 1 to line 3).
What are the Tailwind CSS Grid utility classes?
grid (sets display:grid), grid-cols-N (sets column count), col-span-N (item spanning), gap-N (gap size), and place-items-* for alignment. Generate the exact classes in Gridlock Holmes.

Build a CSS Grid layout now

Visual, free, no signup. CSS, Tailwind, JavaScript and SCSS output.

Open the CSS Grid Generator Start the Learning Path Use Grid Detective