DevLab
#
CSS⭐ Popularintermediate

CSS Grid Generator

generate CSS grid templates visually with live preview

By Bikram NathLast updated

Paste track sizes into column and row fields, set a gap value, and the tool renders a proportional grid preview while generating the matching `grid-template-columns`, `grid-template-rows`, and `gap` declarations. Useful for sketching a 12-column editorial layout before writing any markup: entering `repeat(12, 1fr)` with a 24px gap shows all twelve equal-width tracks live and outputs production-ready CSS.

Try it now — free, instant, no signup

What is CSS Grid Generator?

CSS Grid Generator lets you specify column tracks, row tracks, and gap sizes through form inputs and immediately renders a scaled preview. Enter `200px 1fr 200px` for columns and `auto auto` for rows and the preview draws two fixed sidebars flanking a flexible center column across two rows; the output is a declaration block ready to paste into any stylesheet.

The tool suits early-layout sketching when you want to see proportional track relationships before writing any CSS. Firefox DevTools and Chrome DevTools both have a built-in grid overlay inspector, but both require existing CSS and a live DOM. Layoutit (layoutit.com) is a closer alternative with drag-and-drop area naming and `grid-template-areas` output; reach for that when you need named areas, not just track sizing.

One thing to be aware of: the generator produces explicit grid track declarations. Any child elements that overflow the defined track count fall into the implicit grid, sized by `grid-auto-rows` and `grid-auto-columns`, which both default to `auto`. If your generated CSS defines three columns but a later layout change adds a fourth child, that child will not respect the explicit track widths without a matching `grid-auto-columns` value or an explicit column count increase.

When to use CSS Grid Generator

Prototype a three-column sidebar-main-aside layout with mixed fixed and flexible tracks before writing any component HTML.
Verify that `repeat(auto-fill, minmax(280px, 1fr))` produces the correct column count at 768px, 1024px, and 1440px breakpoints.
Extract a precise `gap` value for a photo gallery grid by adjusting the gap field until preview spacing matches a design mock.

Frequently Asked Questions

What is the difference between `fr` units and percentages in the columns field?
Percentages in `grid-template-columns` are calculated against the container width and ignore gap. A three-column `33.33% 33.33% 33.33%` layout overflows by the total gap width because percentages do not account for gutters. `fr` units distribute only the remaining space after fixed lengths and gaps are subtracted. `1fr 1fr 1fr` with a 24px gap produces three genuinely equal columns that account for the gutters, making `fr` the correct unit for most equal-distribution layouts.
Does the generated CSS need vendor prefixes for production?
No. `grid-template-columns`, `grid-template-rows`, and `gap` are unprefixed in every browser with more than 0.5% global usage as of 2026. The old `-ms-grid` prefix applied to IE 11's partial implementation, which used a completely different syntax including `-ms-grid-columns` and `-ms-grid-column-span`. IE 11 reached end of life in June 2022. Unless you have a documented requirement to support it, the generated output works as-is in all current browsers without modification.
Can this tool generate `grid-template-areas` for named regions?
No. The generator outputs track-based CSS: `grid-template-columns`, `grid-template-rows`, and `gap`. It does not produce `grid-template-areas` strings or the corresponding `grid-area` assignments for child elements. If you need named-area syntax, for example placing a header that spans all columns with `grid-area: header`, Layoutit at layoutit.com handles drag-and-drop area naming and exports the full `grid-template-areas` block alongside track declarations.
Why does my grid look different in the browser than in the preview?
The most common cause is implicit grid creation. The generator renders an explicit grid with only the tracks you define. When your actual HTML contains more children than the declared row count, browsers generate implicit rows sized by `grid-auto-rows`, which defaults to `auto` (shrink-to-content). The preview has no children to overflow, so it only shows explicit tracks. Adding `grid-auto-rows` to your generated CSS controls implicit row height in the live layout and usually resolves the discrepancy.
Does the output include `subgrid` support for nested containers?
No. The generator produces a flat, single-container grid declaration. `subgrid`, introduced in CSS Grid Level 2, lets a nested grid inherit its parent's track definitions via `grid-template-columns: subgrid` or `grid-template-rows: subgrid` on the child element. Browser support landed in Chrome 117, Firefox 71, and Safari 16, all current as of 2026. If you need subgrid on a child element, copy the generated parent CSS and add the `subgrid` keyword manually to the child's own grid declaration.

Related Tools