CSS Grid Generator
CSS ToolsDesign CSS Grid layouts visually — define rows, columns, areas, copy code. Free, private — all processing in your browser.
display: grid; grid-template-columns: 1fr 1fr 1fr; grid-template-rows: auto 1fr auto; gap: 16px; justify-items: stretch; align-items: stretch;
The CSS Grid Generator builds responsive 2D grid layouts through a visual editor. Drag to resize columns and rows, specify sizing with fr units (fractional), minmax(), auto, or fixed pixels. Name grid areas (header, sidebar, main, footer) and assign items to them by name — the killer feature of CSS Grid that makes layouts readable. Add gaps between rows and columns, set alignment for items, and generate production-ready CSS with matching HTML structure. Supports the modern features developers actually use: minmax(), auto-fit, auto-fill, subgrid (Firefox only for now), and named lines.
CSS Grid is the most powerful layout system CSS has ever had. Unlike Flexbox (1-dimensional), Grid handles rows AND columns together, enabling magazine-style layouts, dashboards, card grids with matching heights, responsive designs without media queries (thanks to auto-fit minmax()), and complex asymmetric layouts that used to require JavaScript. This generator runs entirely in your browser, so you can iterate on layouts without refreshing a dev server or touching your codebase.
CSS Grid Generator — key features
Visual grid designer
Drag to resize rows and columns. See the grid visualization update live.
Named grid areas
Define areas by name (header, sidebar, main). Drag to span cells. Readable, maintainable layouts.
fr, minmax, auto-fit support
Use modern Grid features for responsive layouts. No media queries needed for common cases.
Gap controls
Row gap, column gap, or uniform gap. Visualize spacing between cells.
Item placement
Drag items into grid areas or set grid-column/grid-row. See how items span cells.
Responsive preview
Change viewport width to test how auto-fit and minmax layouts respond.
Copy production CSS and HTML
Get the complete CSS rules plus matching HTML structure ready to use.
Preset layouts
Starting points: holy grail (header/sidebar/main/aside/footer), magazine, card grid, dashboard.
How to use the CSS Grid Generator
- 1
Choose layout preset or start blank
Presets like holy grail (header/sidebar/main/footer) or card grid give quick starting points.
- 2
Define columns and rows
Set track sizes with fr, px, %, or auto. Drag dividers to resize visually.
- 3
Name areas (optional)
Switch to area naming mode. Drag to select cells and name them (header, main, etc.).
- 4
Add items
Place items in cells or named areas. Each item has individual placement controls.
- 5
Set alignment and gaps
Configure justify-items, align-items for all items, or override per item.
- 6
Test responsive
Drag viewport width to see how minmax and auto-fit respond.
- 7
Copy code
Grab the CSS and HTML output. Ready to paste into your stylesheet.
Common use cases for the CSS Grid Generator
Page layouts
- →Holy grail layout: Classic: header on top, sidebar left, content middle, aside right, footer bottom. Grid named areas make this trivial.
- →Magazine layouts: Asymmetric designs with images, pull quotes, and text in different sizes — Grid handles this gracefully.
- →Dashboard layouts: Dashboards with cards of different sizes (hero card, secondary cards) — use grid-column and grid-row to span.
- →Landing pages: Hero section, feature grid, testimonials — each section uses Grid for layout.
Responsive card grids
- →Product grids (responsive without media queries): repeat(auto-fit, minmax(250px, 1fr)) — cards fill available space, wrap naturally. No media queries needed.
- →Blog post grids: 3 columns on desktop, 2 on tablet, 1 on mobile — all from one Grid definition.
- →Image galleries: Perfect grid alignment. Gap controls provide visual breathing room.
- →Team/member pages: Grid of team photos at consistent size. Flexible for adding/removing members.
Forms and admin UIs
- →Complex form layouts: Label-input pairs in columns, multi-column sections, responsive. Grid handles this better than Flexbox.
- →Settings pages: Label + description + control pattern. Grid with 3 columns + gap.
- →Table-like data display: Real tables are better for data, but Grid works for semi-structured data with consistent column alignment.
Complex components
- →Cards with aligned inner elements: Card grids where internal elements (titles, prices, buttons) align across cards. Use subgrid.
- →Pricing tables: Features row, price row, CTA row — all aligned across pricing tiers. Grid with subgrid.
- →Feature comparison tables: Rows of features, columns of products, all aligned. Grid template-rows + columns.
- →Image with overlay: Image filling the grid area, text overlay on top. z-index + grid-area.
CSS Grid Generator — examples
Holy grail layout
Classic full-page layout with named areas.
250px sidebar, fluid main, 200px aside, header/footer full-width
.layout {
display: grid;
grid-template-columns: 250px 1fr 200px;
grid-template-rows: auto 1fr auto;
grid-template-areas:
"header header header"
"sidebar main aside"
"footer footer footer";
min-height: 100vh;
gap: 1rem;
}Responsive card grid
No media queries — auto-fit + minmax.
Minimum card width 280px, fluid.
.cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
gap: 1.5rem;
}Asymmetric 3-column
1fr 2fr 1fr with items spanning multiple cells.
Left 1fr, middle 2fr, right 1fr. Hero spans middle and right.
.grid {
display: grid;
grid-template-columns: 1fr 2fr 1fr;
gap: 1rem;
}
.hero {
grid-column: 2 / 4; /* spans col 2 and 3 */
}Dashboard with nested grids
Outer grid for page, inner grids for cards.
Hero card large, others smaller in a grid below
.dashboard {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 1rem;
}
.hero {
grid-column: span 2;
grid-row: span 2;
}Fixed + fluid columns
Sidebar fixed, content fluid.
Sidebar 250px + main taking rest
.layout {
display: grid;
grid-template-columns: 250px 1fr;
min-height: 100vh;
}12-column grid system
Foundation-style flexible grid.
12 equal columns with gap
.grid-12 {
display: grid;
grid-template-columns: repeat(12, 1fr);
gap: 1rem;
}
.col-span-6 { grid-column: span 6; }
.col-span-4 { grid-column: span 4; }Technical details
CSS Grid Layout (Level 1 stable since 2017, Level 2 with subgrid stable in Firefox 71+, Safari 16+, Chrome 117+) is a two-dimensional layout system.
Container properties:
``css``
.grid {
display: grid; /* or inline-grid */
grid-template-columns: 1fr 2fr 1fr; /* define columns */
grid-template-rows: auto 1fr auto; /* define rows */
grid-template-areas: /* named areas */
"header header header"
"sidebar main aside"
"footer footer footer";
gap: 1rem; /* spacing between items */
row-gap: 1rem;
column-gap: 1rem;
justify-items: stretch; /* horizontal alignment within cells */
align-items: stretch; /* vertical alignment within cells */
justify-content: start; /* horizontal alignment of grid */
align-content: start; /* vertical alignment of grid */
}
Item properties:
``css``
.grid-item {
grid-column: 1 / 3; /* span from line 1 to line 3 */
grid-row: 2; /* place in row 2 */
grid-area: main; /* assign to named area */
justify-self: stretch; /* override container justify-items */
align-self: stretch;
}
Sizing units:
- fr (fractional) — 1fr 2fr = columns share space in 1:2 ratio after fixed widths are subtracted.
- px / rem / em — fixed sizes.
- % — percentage of container width.
- auto — size to content.
- min-content / max-content — shrinks or expands to content.
- minmax(min, max) — sizes between bounds: minmax(200px, 1fr) = at least 200px, up to equal share.
auto-fit and auto-fill:
The most powerful Grid feature — responsive without media queries:
``css``
.cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 1rem;
}
This creates as many columns as fit, each at least 300px wide. On 1200px viewport: 4 columns. On 800px: 2 columns. On 350px: 1 column.
- auto-fit — empty tracks collapse (layout fills container).
- auto-fill — empty tracks remain (creates reserved space).
Use auto-fit when you want items to fill, auto-fill when you want consistent column count.
Named grid areas:
The most readable Grid feature. Instead of abstract line numbers, name each area:
```css
.layout {
display: grid;
grid-template-columns: 250px 1fr;
grid-template-rows: 60px 1fr 40px;
grid-template-areas:
"header header"
"sidebar main"
"footer footer";
}
.header { grid-area: header; }
.sidebar { grid-area: sidebar; }
.main { grid-area: main; }
.footer { grid-area: footer; }
```
The ASCII art of grid-template-areas is literally the layout — dots represent empty cells, names span multiple cells to merge.
Implicit vs explicit grid:
- Explicit — rows and columns defined by grid-template-*.
- Implicit — created automatically when items are placed outside the explicit grid. Sized by grid-auto-rows, grid-auto-columns.
Subgrid (CSS Grid Level 2):
``css``
.child {
display: grid;
grid-template-columns: subgrid; /* inherits parent grid */
}
Allows nested grids to align with parent grid lines. Essential for complex card grids where internal content should align across cards. Supported in Firefox 71+, Safari 16+, Chrome 117+ (widely available as of 2024).
Common problems and solutions
⚠Items in implicit rows shrink unexpectedly
Items placed outside explicit grid create implicit tracks. Unless you set grid-auto-rows, they default to auto (size to content). Set grid-auto-rows: minmax(100px, auto) for consistent row heights.
⚠minmax(0, 1fr) vs minmax(auto, 1fr)
In a narrow container, 1fr alone respects content min-width, causing overflow. minmax(0, 1fr) lets items shrink below content width. Use minmax(0, 1fr) when content might overflow.
⚠Subgrid not universally supported
subgrid works in Firefox 71+ (2019), Safari 16+ (2022), Chrome 117+ (late 2023). Widely available as of 2024. For critical layouts, test or provide fallback without subgrid.
⚠Grid template-areas with dots confusion
. (dot) or .. or ... all mean empty cell in grid-template-areas. Whitespace between names matters — use multiple spaces to align columns visually. Your ASCII art is your layout.
⚠gap in Safari
Grid gap was supported in Safari well before Flexbox gap. OK to use. Safari 11+ (2017).
⚠Responsive without media queries is cool but
auto-fit minmax patterns solve card grids but not everything. Complex breakpoint behavior (hide sidebar on mobile, rearrange at 800px) still needs media queries. Use both where appropriate.
⚠Grid vs Flexbox choice
Start with Grid for layouts that need rows AND columns together. Use Flexbox for 1D arrangements inside Grid cells. Using Grid where Flexbox is simpler is overkill.
⚠Named areas with incorrect row count
Rows in grid-template-areas must match grid-template-rows count. Mismatch breaks layout. Each quoted line is a row.
CSS Grid Generator — comparisons and alternatives
CSS Grid vs Flexbox: Grid is 2D (rows and columns together). Flexbox is 1D. Use Grid for overall page/section layouts. Use Flexbox for 1D component layouts (navigation, button groups). Most real projects use both together.
CSS Grid vs table-based layout (legacy): Tables for layout are inappropriate for modern CSS — inaccessible, hard to style, inflexible. Grid provides all table advantages with proper semantics.
CSS Grid vs Bootstrap grid: Bootstrap grid uses a 12-column float-based or flex-based system with predefined breakpoints. Modern CSS Grid gives the same power without the framework cost. Build responsive grids with auto-fit minmax() — no Bootstrap needed.
CSS Grid vs float-based layouts (legacy): Floats were the standard before Grid — brittle, required clearfix, hard for complex layouts. Grid replaces them entirely for layout. Floats still useful for text wrapping around images.
Grid auto-fit vs auto-fill: auto-fit collapses empty tracks (layout fills container). auto-fill preserves them (reserves space). Use auto-fit when you want items to spread out, auto-fill when you want fixed-size slots.
Named areas vs line-based placement: Named areas (grid-template-areas) are readable — the CSS IS the layout. Line-based (grid-column: 1 / 3) is more flexible for dynamic content. Use names for fixed layouts, lines for programmatic placement.
Frequently asked questions about the CSS Grid Generator
▶What is CSS Grid?
CSS Grid is a 2-dimensional CSS layout system that arranges items in rows AND columns simultaneously. Unlike Flexbox (1-dimensional), Grid handles full-page layouts with multiple rows and columns working together. Released in all major browsers in 2017, now universally supported.
▶Should I use Grid or Flexbox?
Grid for layouts that need rows AND columns — page layouts, card grids, dashboards, magazine-style designs. Flexbox for 1-dimensional arrangements — navigation bars, toolbars, button groups. Most real projects use both together: Grid outside (layout) + Flexbox inside (component arrangement).
▶What is the fr unit?
fr (fractional unit) represents a share of available space. 1fr 2fr 1fr creates three columns sharing remaining space in 1:2:1 ratio after fixed-width columns. The middle column is twice as wide as the sides.
▶How do named grid areas work?
You give visual names to grid cells in grid-template-areas (like a ASCII art map). Then assign items to areas by name via grid-area: header. The CSS IS the layout — readable and maintainable. Great for fixed-structure layouts.
▶What is minmax() and auto-fit?
minmax(min, max) sets a cell size range. auto-fit (with repeat()) creates as many columns as fit. Combined: repeat(auto-fit, minmax(280px, 1fr)) creates responsive cards that wrap naturally without media queries.
▶What is subgrid?
subgrid (Grid Level 2) lets a nested grid inherit the parent grid lines. Essential for card grids where internal elements (titles, prices, buttons) should align across cards. Supported in Firefox 71+, Safari 16+, Chrome 117+ (widely available 2024).
▶How do I make a 12-column grid?
grid-template-columns: repeat(12, 1fr). Then span with grid-column: span N. Flexibility to match Bootstrap-style systems without the framework.
▶Why do my items overflow the grid?
Grid items have an implicit min-width: auto (like Flexbox) — they do not shrink below content width. In a narrow container, content may overflow. Fix: use minmax(0, 1fr) instead of 1fr to allow shrinking.
▶Does CSS Grid work on all browsers?
Yes, in all modern browsers since 2017 — Chrome 57+, Firefox 52+, Safari 10.1+, Edge 16+. Full support for basic features. subgrid requires newer versions (Firefox 71+, Safari 16+, Chrome 117+).
▶Can I use Grid without media queries?
For many common layouts, yes. auto-fit with minmax() creates responsive card grids without media queries. But complex responsive behavior (hide sidebar on mobile, reorder content) still needs media queries. Grid reduces media query usage significantly.
Additional resources
- CSS Grid Spec (W3C) — Official CSS Grid Level 1 specification.
- MDN CSS Grid Guide — Comprehensive Grid reference.
- A Complete Guide to CSS Grid (CSS-Tricks) — The definitive Grid visual guide.
- Grid Garden — Interactive Grid learning game.
- CSS Grid Layout Tutorial (Tooleras blog) — Our in-depth Grid tutorial.
Related tools
All CSS ToolsCSS Animation Generator
Build CSS keyframe animations and transitions with live preview and easing curves
CSS Border Radius Generator
Generate CSS border-radius — from simple rounded corners to organic blob shapes
CSS Box Shadow Generator
Create realistic CSS box shadows — single, layered, inset, neumorphism styles
CSS Clip Path Generator
Create custom CSS shapes with clip-path — polygons, circles, ellipses, SVG paths
CSS Flexbox Playground
Build flex layouts interactively — see changes live, copy production CSS
CSS Formatter
Beautify and indent CSS, SCSS, LESS code — configurable style, production-ready output
Learn more
Explore more tools
200+ free tools that run in your browser.
Browse all tools →