CSS Grid Generator: Rows, Columns & Gaps

Set grid rows, columns and gaps, preview the layout, and copy matching CSS and HTML. Includes common layout presets.

4
3
16px
16px
Presets:
Interactive Grid Matrix 4 cols × 3 rows
CSS Code
HTML Markup
Embed this tool on your website / blog No code required · Copy and paste
HTML Embed Code (iframe):
<iframe src="https://lucentool.com/css-grid-generator" width="100%" height="650" style="border:1px solid #e5e0d8;border-radius:12px;max-width:850px;width:100%;" frameborder="0"></iframe>
<div style="font-size:12px;color:#78716c;margin-top:6px;font-family:sans-serif;">Powered by <a href="https://lucentool.com/css-grid-generator" target="_blank" style="color:#c85a32;text-decoration:none;">Lucentool - CSS Grid Visual Layout Builder</a></div>

Build a regular CSS Grid

Set the row and column counts and adjust each gap. The preview updates along with CSS for the grid container and HTML for its items. Presets provide starting points for a gallery, dashboard, or header-and-footer layout.

Example: a three-column card grid

Choose 3 columns, 2 rows, and 16px for both gaps. The output contains 6 grid items, grid-template-columns: repeat(3, 1fr), grid-template-rows: repeat(2, 1fr), and 16px row and column gaps.

Adapt the copied code to your page

The controls generate equal-width tracks; they do not support dragging items to merge cells or editing arbitrary named areas. Add your own content, breakpoints and item sizing after copying the code. A three-column grid stays three columns until you add a responsive rule.

Where it breaks down

updateGrid() turns the column count, row count and both gap values into grid-template-columns, grid-template-rows and gap, then renders the result with real CSS so the preview is the browser's own layout engine rather than a drawing. Every control change rebuilds the rules and re-renders. copyText() puts both the container declaration and the child rule on the clipboard in one action, because a grid that only half-copies is worse than none.

Formats, sizes and other limits

Regular grids only. Named areas, auto-fill combined with minmax(), subgrid and container queries are not generated, and no media queries are produced — the preview is a single fixed container width, so narrow screens need breakpoints you add yourself. Cell content, alignment and spanning are outside the scope of the generator.

Privacy: no data leaves this tab

The CSS is assembled as a string in this tab and copied to your clipboard; no layout data is uploaded and no style is applied to any remote page.

Frequently asked questions

Can it produce named grid areas?

No. Those are hand-written declarations; the generator covers evenly divided tracks, which is the common case.

Is the output responsive?

Not by itself. Add your own media queries or use clamp() values in the gap and track sizes.

Does the copy button include both rules?

Yes — container and child. Pasting only one of them is the usual reason a copied grid appears to do nothing.