Skip to main content
Preparing workspace

CSS Grid Generator

Build CSS Grid layouts visually: set columns, rows and gaps, click tracks to size them as fr, auto or px, and copy grid-template CSS. Free.

Still loading. If the tool doesn’t appear, reload this page.

Planned features and workflows

About this tool

CSS Grid Generator

Generate CSS Grid layouts visually. Adjust column/row counts, gaps, and copy complete CSS grid-template code instantly.

To build a CSS grid, set the columns, rows and gap, click any track to size it as fr, auto or px, and copy the CSS, for example display: grid; grid-template-columns: 1fr 2fr 1fr; gap: 16px. The live preview updates as you change it, and you can download the CSS with a ready-made HTML scaffold.

How to use CSS Grid Generator

  1. In Grid Structure Controls, set the Columns and Rows sliders — each runs from 1 to 8 tracks.

  2. Use the Column Gap and Row Gap sliders (0 to 40px) to define the space between grid cells, then click a Col or Row chip under Column Track Sizing or Row Track Sizing to cycle its unit through 1fr, 2fr, auto and a fixed pixel width.

  3. Once the Grid Container Visualizer looks right, press Copy to take the generated grid-template-columns and grid-template-rows rules, or Download for grid-layout-template.txt with the matching HTML.

Why use CSS Grid Generator

  • Per-track sizing, not just a count

    Every column and row is individually clickable and cycles through 1fr, 2fr, auto and a fixed px size, so you can build asymmetric grids instead of only even ones.

  • Row and column gaps kept separate

    The two gaps have their own sliders and are emitted in the correct row-then-column order of the gap shorthand, a common place to get the values backwards.

  • Ships the HTML with the CSS

    The download pairs the grid rule with a matching container and one numbered .grid-item div per cell, so the layout renders the moment you paste it.

Common use cases

  • You need a three-column page shell where the sidebar stays at a fixed width and the two content columns share the rest — click the first track until it reads 120px and leave the others on 1fr.
  • A designer handed you a mock with tighter vertical spacing than horizontal, and you want the gap shorthand written correctly rather than guessing which of the two values is the row gap.
  • You are learning why fr units behave differently from percentages and want to flip one track between 1fr, 2fr and auto to watch the remaining space redistribute.

Frequently asked questions

How many columns and rows can I generate?

Between 1 and 8 of each, giving a maximum of 64 cells. Any track beyond what you have sized defaults to 1fr, so a fresh grid starts out perfectly even.

Link to answer
What does the gap value mean when there are two numbers?

In gap: 12px 20px the first value is the row gap (vertical space between rows) and the second is the column gap. Both sliders here run from 0 to 40px and are written in that order, so the shorthand matches what you see in the preview.

Link to answer
What is the difference between 1fr and auto for a track?

1fr claims an equal share of the leftover free space, while auto sizes the track to its content and only grows if space remains after the fr tracks are satisfied. Use a fixed value like 120px when the track must not change size at all.

Link to answer
Does the generated CSS work without the HTML?

Yes — the rule targets a .grid-container class, so applying that class to any element with children turns them into grid items. The bundled HTML is only a scaffold: it creates one numbered .grid-item div per cell so you can see the grid immediately.

Link to answer