Web Design
Updated for 2026

CSS Grid Layout Cheatsheet & Visual Cheat Sheet

Complete CSS Grid cheatsheet and grid alignment cheat sheet. Learn grid-container attributes, alignment properties, visual template areas, and responsive units.

Target Version Compatibility

Interactive Skill Mastery

Mark commands as learned to build your customized reference tracker. Retained locally in this browser.

Level:Novice
Command Mastery Progress0 of 19 Mastered (0%)

Container Setup

display: grid;
BeginnerBasics
Convert any HTML block element into a CSS Grid parent container.

When to Use

When styling and positioning multidimensional responsive grids, columns, or structural visual elements.

Common Mistakes

Confusing CSS Grid (suited for double-axis layouts) with CSS Flexbox (suited for single-axis rows or list items).

Shortcut / Pro-Tip

Combine repeat() with minmax() parameters to quickly construct gorgeous responsive bento grids without media queries.

Example

display: grid;

Output Example

Console / Terminal
Grid layout painted successfully inside the browser visual tree.
gap: 20px 10px;
BeginnerBasics
Configure gaps between child elements (sets row-gap and column-gap spacing).

When to Use

When styling and positioning multidimensional responsive grids, columns, or structural visual elements.

Common Mistakes

Confusing CSS Grid (suited for double-axis layouts) with CSS Flexbox (suited for single-axis rows or list items).

Shortcut / Pro-Tip

Combine repeat() with minmax() parameters to quickly construct gorgeous responsive bento grids without media queries.

Example

gap: 20px 10px;

Output Example

Console / Terminal
Grid layout painted successfully inside the browser visual tree.
grid-auto-flow: dense;
BeginnerBasics
Instruct the grid layout auto-placement engine to fill empty visual holes with smaller elements.

When to Use

When styling and positioning multidimensional responsive grids, columns, or structural visual elements.

Common Mistakes

Confusing CSS Grid (suited for double-axis layouts) with CSS Flexbox (suited for single-axis rows or list items).

Shortcut / Pro-Tip

Combine repeat() with minmax() parameters to quickly construct gorgeous responsive bento grids without media queries.

Example

grid-auto-flow: dense;

Output Example

Console / Terminal
Grid layout painted successfully inside the browser visual tree.
grid-template-columns: subgrid;
BeginnerBasics
Modern CSS: Instruct a child grid-item to inherit and align perfectly to its parent grid column track definition definitions.

When to Use

When styling and positioning multidimensional responsive grids, columns, or structural visual elements.

Common Mistakes

Confusing CSS Grid (suited for double-axis layouts) with CSS Flexbox (suited for single-axis rows or list items).

Shortcut / Pro-Tip

Combine repeat() with minmax() parameters to quickly construct gorgeous responsive bento grids without media queries.

Example

grid-template-columns: subgrid;

Output Example

Console / Terminal
Grid layout painted successfully inside the browser visual tree.
grid-template-rows: masonry;
BeginnerBasics
CSS Masonry (Experimental): Establish high-fidelity multi-column masonry grids where items pack tight vertically across rows.

When to Use

When styling and positioning multidimensional responsive grids, columns, or structural visual elements.

Common Mistakes

Confusing CSS Grid (suited for double-axis layouts) with CSS Flexbox (suited for single-axis rows or list items).

Shortcut / Pro-Tip

Combine repeat() with minmax() parameters to quickly construct gorgeous responsive bento grids without media queries.

Example

grid-template-rows: masonry;

Output Example

Console / Terminal
Grid layout painted successfully inside the browser visual tree.

Template Sizing

grid-template-columns: repeat(3, 1fr);
BeginnerBasics
Divide columns into three equal responsive fractional size units.

When to Use

When styling and positioning multidimensional responsive grids, columns, or structural visual elements.

Common Mistakes

Confusing CSS Grid (suited for double-axis layouts) with CSS Flexbox (suited for single-axis rows or list items).

Shortcut / Pro-Tip

Combine repeat() with minmax() parameters to quickly construct gorgeous responsive bento grids without media queries.

Example

grid-template-columns: repeat(3, 1fr);

Output Example

Console / Terminal
Grid layout painted successfully inside the browser visual tree.
grid-template-rows: auto 1fr auto;
BeginnerBasics
Define explicit row heights (ideal for header, dynamic main, and sticky footer).

When to Use

When styling and positioning multidimensional responsive grids, columns, or structural visual elements.

Common Mistakes

Confusing CSS Grid (suited for double-axis layouts) with CSS Flexbox (suited for single-axis rows or list items).

Shortcut / Pro-Tip

Combine repeat() with minmax() parameters to quickly construct gorgeous responsive bento grids without media queries.

Example

grid-template-rows: auto 1fr auto;

Output Example

Console / Terminal
Grid layout painted successfully inside the browser visual tree.
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
BeginnerBasics
Achieve auto-wrapping responsive bento layouts without utilizing a single CSS media query.

When to Use

When styling and positioning multidimensional responsive grids, columns, or structural visual elements.

Common Mistakes

Confusing CSS Grid (suited for double-axis layouts) with CSS Flexbox (suited for single-axis rows or list items).

Shortcut / Pro-Tip

Combine repeat() with minmax() parameters to quickly construct gorgeous responsive bento grids without media queries.

Example

grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));

Output Example

Console / Terminal
Grid layout painted successfully inside the browser visual tree.
grid-auto-rows: minmax(100px, auto);
BeginnerBasics
Establish height ranges for implicitly generated grid rows to dynamically adapt to text content volumes.

When to Use

When styling and positioning multidimensional responsive grids, columns, or structural visual elements.

Common Mistakes

Confusing CSS Grid (suited for double-axis layouts) with CSS Flexbox (suited for single-axis rows or list items).

Shortcut / Pro-Tip

Combine repeat() with minmax() parameters to quickly construct gorgeous responsive bento grids without media queries.

Example

grid-auto-rows: minmax(100px, auto);

Output Example

Console / Terminal
Grid layout painted successfully inside the browser visual tree.
grid-template-columns: fit-content(350px) 1fr;
BeginnerBasics
Sizing tracks: Clamp track widths dynamically up to a specified maximum value while allowing them to shrink freely if needed.

When to Use

When styling and positioning multidimensional responsive grids, columns, or structural visual elements.

Common Mistakes

Confusing CSS Grid (suited for double-axis layouts) with CSS Flexbox (suited for single-axis rows or list items).

Shortcut / Pro-Tip

Combine repeat() with minmax() parameters to quickly construct gorgeous responsive bento grids without media queries.

Example

grid-template-columns: fit-content(350px) 1fr;

Output Example

Console / Terminal
Grid layout painted successfully inside the browser visual tree.

Grid Item Placement

grid-column: span 2;
BeginnerBasics
Set a child grid item to span across two horizontal columns.

When to Use

When styling and positioning multidimensional responsive grids, columns, or structural visual elements.

Common Mistakes

Confusing CSS Grid (suited for double-axis layouts) with CSS Flexbox (suited for single-axis rows or list items).

Shortcut / Pro-Tip

Combine repeat() with minmax() parameters to quickly construct gorgeous responsive bento grids without media queries.

Example

grid-column: span 2;

Output Example

Console / Terminal
Grid layout painted successfully inside the browser visual tree.
grid-row: 1 / 3;
BeginnerBasics
Position a grid item explicitly from vertical row line 1 down to row line 3.

When to Use

When styling and positioning multidimensional responsive grids, columns, or structural visual elements.

Common Mistakes

Confusing CSS Grid (suited for double-axis layouts) with CSS Flexbox (suited for single-axis rows or list items).

Shortcut / Pro-Tip

Combine repeat() with minmax() parameters to quickly construct gorgeous responsive bento grids without media queries.

Example

grid-row: 1 / 3;

Output Example

Console / Terminal
Grid layout painted successfully inside the browser visual tree.
align-self: end;\njustify-self: start;
BeginnerBasics
Align or position a single grid item locally, overriding the parent container alignment rules.

When to Use

When styling and positioning multidimensional responsive grids, columns, or structural visual elements.

Common Mistakes

Confusing CSS Grid (suited for double-axis layouts) with CSS Flexbox (suited for single-axis rows or list items).

Shortcut / Pro-Tip

Combine repeat() with minmax() parameters to quickly construct gorgeous responsive bento grids without media queries.

Example

align-self: end;\njustify-self: start;

Output Example

Console / Terminal
Grid layout painted successfully inside the browser visual tree.
grid-column: 1 / -1;
BeginnerBasics
Set a grid item to span the entire horizontal width, from the first line to the very last.

When to Use

When styling and positioning multidimensional responsive grids, columns, or structural visual elements.

Common Mistakes

Confusing CSS Grid (suited for double-axis layouts) with CSS Flexbox (suited for single-axis rows or list items).

Shortcut / Pro-Tip

Combine repeat() with minmax() parameters to quickly construct gorgeous responsive bento grids without media queries.

Example

grid-column: 1 / -1;

Output Example

Console / Terminal
Grid layout painted successfully inside the browser visual tree.

Grid Alignment

justify-items: center;\nalign-items: center;
BeginnerBasics
Center child items both horizontally and vertically inside their grid cells.

When to Use

When styling and positioning multidimensional responsive grids, columns, or structural visual elements.

Common Mistakes

Confusing CSS Grid (suited for double-axis layouts) with CSS Flexbox (suited for single-axis rows or list items).

Shortcut / Pro-Tip

Combine repeat() with minmax() parameters to quickly construct gorgeous responsive bento grids without media queries.

Example

justify-items: center;\nalign-items: center;

Output Example

Console / Terminal
Grid layout painted successfully inside the browser visual tree.
place-items: center;
BeginnerBasics
A clean shorthand utility setting both align-items and justify-items centering simultaneously.

When to Use

When styling and positioning multidimensional responsive grids, columns, or structural visual elements.

Common Mistakes

Confusing CSS Grid (suited for double-axis layouts) with CSS Flexbox (suited for single-axis rows or list items).

Shortcut / Pro-Tip

Combine repeat() with minmax() parameters to quickly construct gorgeous responsive bento grids without media queries.

Example

place-items: center;

Output Example

Console / Terminal
Grid layout painted successfully inside the browser visual tree.

Grid Area Mapping

grid-template-areas: \n "header header"\n "sidebar main"\n "footer footer";
BeginnerBasics
Define layout rows using visual named areas on the parent container.

When to Use

When styling and positioning multidimensional responsive grids, columns, or structural visual elements.

Common Mistakes

Confusing CSS Grid (suited for double-axis layouts) with CSS Flexbox (suited for single-axis rows or list items).

Shortcut / Pro-Tip

Combine repeat() with minmax() parameters to quickly construct gorgeous responsive bento grids without media queries.

Example

grid-template-areas: \n  "header header"\n  "sidebar main"\n  "footer footer";

Output Example

Console / Terminal
Grid layout painted successfully inside the browser visual tree.
grid-area: main;
BeginnerBasics
Assign a child item to place itself inside a predefined grid-template-area section.

When to Use

When styling and positioning multidimensional responsive grids, columns, or structural visual elements.

Common Mistakes

Confusing CSS Grid (suited for double-axis layouts) with CSS Flexbox (suited for single-axis rows or list items).

Shortcut / Pro-Tip

Combine repeat() with minmax() parameters to quickly construct gorgeous responsive bento grids without media queries.

Example

grid-area: main;

Output Example

Console / Terminal
Grid layout painted successfully inside the browser visual tree.
grid-template-columns: [main-start] 1fr [content-start] 3fr [content-end] 1fr [main-end];
BeginnerBasics
Define explicit named grid lines to place items using recognizable keyword aliases instead of numeric indices index lines.

When to Use

When styling and positioning multidimensional responsive grids, columns, or structural visual elements.

Common Mistakes

Confusing CSS Grid (suited for double-axis layouts) with CSS Flexbox (suited for single-axis rows or list items).

Shortcut / Pro-Tip

Combine repeat() with minmax() parameters to quickly construct gorgeous responsive bento grids without media queries.

Example

grid-template-columns: [main-start] 1fr [content-start] 3fr [content-end] 1fr [main-end];

Output Example

Console / Terminal
Grid layout painted successfully inside the browser visual tree.

CSS Grid Best Practices

1Use Grid for Double-Axis Layouts

Prefer CSS Grid layouts for complex, two-dimensional structures, and keep Flexbox for simple one-dimensional headers or menus.

2Leverage repeat() and minmax()

Combine repeat(auto-fit, minmax(250px, 1fr)) to make bento grids fully responsive across phone and ultra-wide screens natively.

3Build Templates with Grid Areas

Use grid-template-areas for visual layouts to make page restructuring simple and highly readable inside stylesheets.

4Style Grid Gaps with gap shorthand

Define consistent row and column spacing using the unified 'gap' property instead of adding margins to child cards.

5Verify Layout boundaries with DevTools

Always open browser DevTools grid overlays to visually inspect track heights, lines, and alignment boundaries.

Common CSS Grid Errors & Solutions

Error

Grid items overflowing layout containers

Solution

Ensure you use the fractional unit '1fr' or 'minmax()' instead of rigid pixel widths (like 300px) that don't scale down.

Error

Grid Area names mismatch in template properties

Solution

Verify that visual names assigned to 'grid-area' on child elements match the layout map strings exactly.

Error

Confusing repeat(auto-fill) vs repeat(auto-fit)

Solution

auto-fill leaves track spaces empty if there are few items. auto-fit stretches existing items to fill the remaining track width.

Error

Gaps adding to container heights causing scrollbars

Solution

Use 'box-sizing: border-box' to incorporate margins, padding, and borders inside height calculations.

Error

Items packing awkwardly in columns

Solution

Activate implicit packing behaviors using 'grid-auto-flow: dense' to let small items fill empty spaces.

Common CSS Grid Interview Questions

Q1What is the difference between CSS Grid and CSS Flexbox?

CSS Grid is a 2D layout engine that manages both rows and columns simultaneously, ideal for whole-page structures. CSS Flexbox is a 1D layout engine designed for alignment along a single axis, ideal for cards or navigation headers.

Q2Explain the fractional (fr) unit and how it works in CSS layouts.

The 'fr' unit represents a fraction of the leftover free space in the grid container. If columns are configured as '1fr 2fr', the second column receives twice the remaining layout space compared to the first.

Q3What do repeat(auto-fit, minmax(150px, 1fr)) do?

It tells the grid to fill the container row with columns of at least 150px. If there is leftover space, columns stretch equally to fill it. If space shrinks, columns wrap dynamically without requiring media queries.

Q4What is Grid Area Mapping and why is it useful?

Grid Area Mapping links visual child names directly into visual layout template grid strings on the parent container. This decouples HTML order from visual order, letting you relocate header, sidebars, and footer instantly.

Q5How do justify-items and align-items differ in CSS Grid containers?

justify-items aligns grid child elements horizontally along the row axis within their cells. align-items aligns grid child elements vertically along the column axis within their cells.