Home/Tools/Layout/CSS Grid Generator
Layout · Generator

CSS Grid Generator

Visually build responsive CSS Grid layouts — set columns, rows, gaps and alignment with live preview. Copy production-ready CSS instantly. Free, no sign-up.

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;
100%
Free, no
sign-up needed
0
Code written
by hand
85+
CSS tools
in one place
<1s
Copy-ready
CSS instantly
What is this

What is the CSS Grid Generator?

CSS Grid is the most powerful layout system in CSS — a two-dimensional grid that places elements into rows and columns at the same time. Build one visually and copy the exact CSS it produces.

Everything runs locally in your browser. Adjust the controls above, preview instantly, and copy clean, production-ready CSS — no account, no upload.

How to use

Using the CSS Grid Generator

Everything lives in the panel at the top of this page. There is nothing to install — it all runs right here in your browser.

1

Set columns & rows

Use the Columns and Rows sliders to define your grid shape. The preview rebuilds instantly so you always see the structure.

2

Adjust the gap

Slide the Gap control to add breathing room between cells. It maps directly to the CSS gap property — consistent spacing everywhere.

3

Pick column sizing

Choose fr units for equal flexible columns, or Auto-fit for a grid that wraps responsively without media queries.

4

Copy your CSS

Hit Copy and paste the output onto your container element. That is the whole workflow.

The output

What the generated code looks like

Clean, production-ready CSS — no vendor bloat, no unnecessary declarations.

layout.css
.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 14px;
}

Switch to Auto-fit and the output uses repeat(auto-fit, minmax(…, 1fr)) — a grid that fits as many columns as will comfortably fit, then wraps. Responsive with zero media queries.

Copy & paste

Ready-to-use CSS patterns

Drop any of these straight into your project — no modifications needed.

Responsive auto-fit grid

Fills the row with as many columns as fit, then wraps. No breakpoints required.

styles.css
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
}

Holy grail page layout

Header, sidebar, content and footer with named areas.

styles.css
.page {
  display: grid;
  grid-template-columns: 220px 1fr;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "header header"
    "sidebar main"
    "footer footer";
  min-height: 100vh;
}
Common mistakes & fixes

Common mistakes & how to fix them

A few habits trip people up. Here is what to watch for — and the exact fix.

Fixed px columns

Using 200px 200px 200px makes columns that cannot adapt and overflow on small screens.

Fix: Use 1fr units so columns share space and stay fluid.

Margins for spacing

Adding margins to grid items creates uneven, hard-to-balance gutters.

Fix: Use the gap property — one value, consistent everywhere.

Media queries for wrapping

Writing breakpoints to change column counts is verbose and brittle.

Fix: Use Auto-fit with minmax() for responsive wrapping for free.

Grid for everything

Reaching for Grid on a simple one-row button group adds needless complexity.

Fix: Use Flexbox for single-axis layouts; save Grid for true 2D layouts.

Pro tips

Pro tips for better results

fr beats percentages

Fractional units account for the gap automatically. Three 1fr columns with a gap always add up correctly, where 33.33% columns plus gaps overflow.

minmax() prevents squashing

repeat(auto-fit, minmax(220px, 1fr)) guarantees columns never shrink below 220px before wrapping to a new row.

FAQ

Frequently asked questions

Flexbox is one-dimensional — it lays items out in a single row or column. CSS Grid is two-dimensional, controlling rows and columns at the same time. Use Flexbox for nav bars and button groups; reach for Grid when you need a true layout with aligned rows and columns.
Often not. Switch the generator to Auto-fit and the output uses repeat(auto-fit, minmax(…, 1fr)), which automatically fits and wraps columns as the screen changes — responsive behaviour without a single breakpoint.
Yes. CSS Grid is supported in every modern browser — Chrome, Firefox, Safari and Edge — and has been for years. You can use the generated code in production with confidence.
Absolutely. Grid excels at page-level structure — headers, sidebars, content areas and footers. Generate your base grid here, then assign items to areas with grid-column and grid-row in your own CSS.
No. Everything runs locally in your browser. Nothing is uploaded, stored or sent to a server — the generated CSS never leaves your machine.

From the blog

Read more