CSS Grid Generator

Home/Tools/Grid Generator

Build complex CSS Grid layouts visually with drag and drop.

No sign-up neededRuns in your browserProduction-ready CSS

Grid Structure

3
3

Gap

16px
16px

Alignment

Justify Items
Align Items

Preview

1
2
3
4
5
6
7
8
9
Generated CSS
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, 1fr);
column-gap: 16px;
row-gap: 16px;
justify-items: stretch;
align-items: stretch;

CSS Grid Generator

Build responsive grid layouts visually. Set your columns, rows, and gaps — then copy the CSS.

What the generated code looks like

Here's exactly what you'll walk away with. Clean, production-ready CSS — no wrappers, no vendor prefixes, no unnecessary declarations.

styles.css
.grid-container {display: grid;grid-template-columns: repeat(3, 1fr);grid-template-rows: auto auto;gap: 16px;justify-items: stretch;align-items: stretch;}.grid-item {/* your item styles here */}
No extra wrappers. No vendor prefixes. No unnecessary declarations. Just the CSS you need.
🎯

How to use the CSS Grid Generator

Six steps. Each control maps directly to a CSS property — plain and fast.

1
Set your column count
Each column becomes a 1fr track in grid-template-columns
2
Set your row count
Rows map directly to grid-template-rows
3
Adjust the gap
Controls gap — space between cells, never around them
4
Override templates
Enter custom values like 200px 1fr or repeat(auto-fit, minmax(250px, 1fr))
5
Set alignment
Justify and align items within their cells visually before committing to code
6
Copy the CSS
Hit the copy button. Paste into your project. Done.
🏗️

5 real layouts you can build right now

Ready-to-use patterns for the most common CSS Grid use cases. Copy any of these directly into your project.

Pattern 01
Responsive Card Grid (auto-fit)
For blogs, product listings, and team pages. Adjusts columns automatically — no media queries needed.
styles.css
.card-grid {display: grid;grid-template-columns:repeat(auto-fit, minmax(280px, 1fr));gap: 24px;}
Cards never collapse below 280px wide
Pattern 02
Classic Sidebar Layout
Docs sites, dashboards, admin panels. Sidebar holds width while content fills remaining space.
styles.css
.sidebar-layout {display: grid;grid-template-columns: 260px 1fr;gap: 32px;min-height: 100vh;}
Use 1fr 260px to move sidebar to the right
Pattern 03
Full-Page Dashboard Layout
Complex multi-zone layout using named grid areas — would have taken nested floats before Grid.
styles.css
.dashboard {display: grid;grid-template-areas:"header header header""sidebar main widgets""footer footer footer";grid-template-columns: 240px 1fr 300px;grid-template-rows: 64px 1fr 56px;height: 100vh;gap: 16px;}
Named areas make the layout self-documenting
Pattern 04
Responsive Image Gallery (auto-fill)
Keeps empty columns visible for consistent structure — ideal for portfolios and galleries.
styles.css
.gallery {display: grid;grid-template-columns:repeat(auto-fill, minmax(200px, 1fr));gap: 12px;}
auto-fill vs auto-fit — see the explanation below
Pattern 05
Equal-Height Feature Cards (3-col)
Every card stretches to equal height automatically — a classic case that trips up Flexbox users.
styles.css
.features {display: grid;grid-template-columns: repeat(3, 1fr);gap: 20px;align-items: stretch;}
Grid handles equal heights natively — no JS needed
📐

The fr unit & auto-fit vs auto-fill explained

Two topics developers search constantly. Explained plainly — no padding, no filler.

Understanding the fr unit

The fr (fractional unit) makes CSS Grid layouts feel effortless. Instead of calculating percentages, you describe how space is shared.

You writeWhat it meansResult
1fr 1fr 1fr3 equal partsThree equal columns
1fr 2frTotal split into 3 partsSecond column is twice as wide
200px 1frFirst is fixed; second fills restSidebar + flexible content area
1fr 1fr 1fr 1fr4 equal partsFour equal columns
The key insight: fr units only distribute space left over after fixed values (px, %) are subtracted. This makes mixed layouts like 200px 1fr 1fr predictable and easy.

auto-fit vs auto-fill — the actual difference

This is one of the most searched CSS Grid questions. Here it is, plain and simple:

KeywordWhat it does
auto-fillCreates as many column tracks as will fit — even if some are empty. Grid structure stays visible.
auto-fitCreates only the tracks needed for your content. Empty tracks collapse to zero width. Remaining items expand.

Rule of thumb: use auto-fill for galleries where you want consistent column structure. Use auto-fit for cards where you want them to fill the row.

auto-fit-vs-fill.css
/* auto-fit: items expand to fill row */grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));/* auto-fill: empty columns preserved */grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
⚠️

Common CSS Grid mistakes — and how to fix them

Real developer pain points, explained and solved. The issues that break layouts silently — and the exact fixes.

01
Using margins instead of gap
✗ Problem

Adding margin to grid items causes uneven spacing at the edges and makes responsive layouts unpredictable. Edge items get double spacing.

✓ Fix

Always use gap on the grid container. It only applies between items — never on the outside edges. This is exactly what the Grid Generator uses.

02
Forgetting that fr distributes leftover space
✗ Problem

Writing 200px 1fr 1fr and expecting the 1fr columns to be equal halves of total width. They're not — they share what's left after 200px.

✓ Fix

Subtract fixed widths from total width first. What remains gets divided by fr units. The generator shows this live, making the behaviour immediately obvious.

03
Nesting grids unnecessarily
✗ Problem

Wrapping grid inside grid inside grid creates layouts that break on edge-case screen sizes and become impossible to maintain.

✓ Fix

Use grid-template-areas for complex layouts instead of nesting. Define the entire layout at the top level. See Pattern 03 (Dashboard) above.

04
Ignoring source order for accessibility
✗ Problem

Using order or grid placement to rearrange elements visually without updating the HTML order. Screen readers follow the DOM — not the visual grid.

✓ Fix

Keep your HTML in logical reading order. Use grid placement for visual adjustments only — not to restructure content hierarchy.

💬

Frequently asked questions

Questions from real Google search data — answered directly, with no padding.

Use repeat(auto-fit, minmax(MIN, 1fr)) in your grid-template-columns. Set MIN to the smallest width you want each column to be. The grid will automatically add or remove columns based on available space — no media queries needed. The CSS Grid Generator outputs this pattern when you enable auto-fit mode.
auto-fill creates as many column tracks as will fit the container, even if they remain empty. auto-fit collapses empty tracks so existing items expand to fill the row. For cards and content blocks, auto-fit is usually what you want. For galleries with fixed structure, use auto-fill.
On the grid item (child element), use grid-column: 1 / 3 to span from column line 1 to line 3 (covering 2 columns). Or use grid-column: span 2 to span 2 columns from wherever the item is placed. The same logic applies to rows with grid-row.
The default for justify-items is stretch, which should fill the column. If your item isn't stretching, check whether the element has an explicit width set, or if a parent element has justify-self overriding the container setting. The generator sets justify-items: stretch by default, which is the correct starting point.
Yes — and this is actually a recommended pattern. Use Grid for the macro layout (page structure, sections, main regions). Use Flexbox inside individual grid items for micro layout (aligning icons with text, button groups, card footers). They solve different problems and work better together than they do alone.
Yes. The CSS Grid Generator on CSS Pixels is completely free, runs in your browser, requires no sign-up, and generates unlimited layouts.
CSS Grid is fully supported in all modern browsers — Chrome 57+, Firefox 52+, Safari 10.1+, and Edge 16+. The code this generator produces uses standard CSS Grid syntax with no prefixes or workarounds required.