Home › All Tools ›

CSS Grid Generator

Use CSS Grid Generator online for free at FreeToolZones — no sign-up, no watermark.

Loading tool...

The CSS Grid Generator lets you design a two-dimensional grid by choosing the number of columns and rows, setting the gaps between them, and picking alignment values, all while watching a live preview of coloured cells. Grid is the layout method for pages and sections where both rows and columns must align: photo galleries, dashboards, product listings, and full page frameworks. Unlike a single row of flexible items, a grid keeps every cell in its track, so content lines up in both directions at once.

Writing grid CSS by hand means keeping track of template definitions, gap properties, and alignment values that behave differently on the grid container than they do in other contexts. The CSS Grid Generator makes the structure visible. The preview shows every cell in its row and column, and the CSS panel shows a .grid rule that reproduces the layout. Copy the rule, rename the selector, and you have a working starting point for a real layout.

What Is the CSS Grid Generator?

The CSS Grid Generator is a visual editor for the container-level properties of CSS Grid Layout. It controls display: grid, grid-template-columns, grid-template-rows, column-gap, row-gap, justify-content, and align-items. Columns and rows are defined with the repeat function and fractional units, so each track gets an equal share of the available space: for example, three columns are expressed as repeat(3, 1fr) and two rows as repeat(2, 1fr).

The preview container holds one coloured cell for every combination of row and column, labelled Cell 1, Cell 2, and so on in reading order. Columns can be set from 1 to 8 and rows from 1 to 6, giving grids from a single cell up to 48 cells. Column gap and row gap are set independently with sliders from 0 to 40 pixels, so horizontal and vertical spacing can differ. The alignment dropdowns control how the grid tracks and the items within them are distributed and aligned.

The justify-content dropdown offers stretch, start, end, center, space-between, space-around, and space-evenly. The align-items dropdown offers stretch, start, end, and center. These values matter most when the grid tracks do not fill the container, or when items are smaller than their cells. In a grid where every track is 1fr and every cell is filled, some alignment differences are subtle, and the preview is the best way to see which combinations change anything for your chosen size.

  • Columns and rows: number inputs from 1 to 8 columns and 1 to 6 rows, with equal fractional tracks.
  • Independent gaps: column gap and row gap sliders, each from 0 to 40 pixels.
  • Justify-content: seven values for distributing tracks along the inline axis.
  • Align-items: four values for aligning items along the block axis.
  • Live cell preview: one labelled, coloured cell per grid position.

How to Use the CSS Grid Generator

Start with a small grid, such as three columns and two rows, and grow it only when you need more cells.

  1. Set the number of columns. Enter a value from 1 to 8 in the Columns field. The template becomes repeat with that many 1fr tracks, so all columns share the width equally.
  2. Set the number of rows. Enter a value from 1 to 6 in the Rows field. The template becomes repeat with that many 1fr tracks, so all rows share the height equally. The preview redraws with one cell per row and column combination.
  3. Adjust the column gap. Drag the Column gap slider between 0 and 40 pixels. This sets the horizontal space between columns only, with no extra space at the outer edges of the grid.
  4. Adjust the row gap. Drag the Row gap slider between 0 and 40 pixels. This sets the vertical space between rows. Try a larger row gap than column gap for article grids, where vertical breathing room matters more.
  5. Choose justify-content. Use the justify-content dropdown to control how the grid is distributed when the tracks do not fill the container width. Try center and space-between with a small number of columns to see the effect.
  6. Choose align-items. Use the align-items dropdown to control how items align within their cells. Stretch fills the cell, while start, end, and center place smaller items at the top, bottom, or middle.
  7. Copy the CSS. Click Copy CSS to copy the .grid rule. Paste it into your stylesheet and rename .grid to the class of your own grid container.

Key Features of the CSS Grid Generator

The tool keeps grid creation simple by using equal tracks, which covers the most common layouts, while still exposing the gap and alignment controls that make a grid feel polished.

  • Equal fractional tracks: the repeat and 1fr syntax guarantees that columns and rows divide the space evenly, without percentage arithmetic or rounding gaps.
  • Up to 48 cells: the combination of 8 columns and 6 rows supports large galleries and dashboards, while small grids stay easy to reason about.
  • Separate gap controls: column-gap and row-gap are generated as separate declarations, so horizontal and vertical spacing can be tuned independently.
  • Full alignment sets: the justify-content and align-items dropdowns include the values most often needed for centring, edge alignment, and even distribution.
  • Numbered cells: cell labels follow reading order, which makes it easy to discuss a specific position and to check that auto-placement fills the grid as expected.
  • Complete grid rule: the output lists display, both templates, both gaps, and both alignment properties in one rule.

Practical Use Cases

Grid excels whenever alignment in two directions matters. The examples below are the layouts where it outperforms a single row or column approach.

Photo and product galleries

A gallery with three or four equal columns and a consistent gap is the classic grid layout. Every image sits in a cell of the same width, rows line up cleanly, and the gap keeps the images from touching. Start with three columns and two rows here, then adjust the column count to suit your page width.

Dashboards and stat panels

Dashboards arrange widgets of similar size in rows and columns: charts, counters, and lists that must align in both directions. A grid with equal tracks and a moderate gap gives the dashboard a tidy, deliberate structure, and alignment values can centre or stretch widgets within their cells.

Article and card listings

Blog indexes and card listings benefit from grid because cards in the same row share a baseline, even when their text lengths differ. Use a row gap slightly larger than the column gap to separate rows of cards clearly, and keep the column count low enough that cards stay readable on narrow screens.

Page frameworks

A simple page framework with a sidebar and a main area, or with header, content, and footer rows, can start as a grid. This tool generates equal tracks, which suits symmetric frameworks. For unequal areas, such as a narrow sidebar beside a wide main column, use the copied rule as a starting point and edit the template values by hand.

Feature and pricing sections

Feature lists with icons and short text, and pricing tables with three plans, are natural grids. Three columns with a generous gap give each feature room to breathe, and centred alignment keeps icons and headings lined up across the row.

Tips and Best Practices

Grid layouts stay maintainable when the structure is simple and the spacing is consistent. These practices help.

  • Start with equal tracks: equal 1fr tracks are predictable and responsive. Introduce unequal tracks only when a specific area genuinely needs more space.
  • Use gap, not margins: gaps apply only between tracks, so the outer edges of the grid stay flush with their container. Margins on cells create uneven edges and double spacing.
  • Keep the column count modest: more than four or five columns can make content cramped on smaller screens. Plan a smaller column count for narrow viewports in your own responsive code.
  • Test with real content lengths: preview cells are uniform, but real cards have different amounts of text. Check that tall content in one cell does not make the whole row feel unbalanced.
  • Combine grid with flexbox: use grid for the overall arrangement and flexbox inside each cell for the arrangement of the cell contents. The two methods complement each other well.
  • Name the selector meaningfully: rename .grid to something descriptive, such as gallery-grid or dashboard-grid, so the purpose of the rule is clear when you revisit the code.

Limitations

This generator produces only equal fractional tracks. It does not support mixed track sizes, fixed pixel or percentage tracks, auto-placement controls, named grid areas, grid-template-areas, item spanning with grid-column or grid-row, or implicit track sizing. If your layout needs a cell that spans two columns, or a sidebar narrower than the main area, you must edit the copied template by hand.

The preview shows automatically placed cells in reading order, with no control over individual cell placement. The tool also does not generate responsive variants, so a grid that should collapse to fewer columns on small screens needs additional media queries in your stylesheet. Treat the output as a clean starting structure, not a finished responsive layout.

  • Equal 1fr tracks only; no mixed, fixed, or named tracks.
  • No spanning, placement, or grid-area controls.
  • No responsive variants in the output.
  • Output uses the .grid selector; rename it for your project.

Frequently Asked Questions

What does 1fr mean?

One fractional unit, written 1fr, represents one share of the free space in the grid container. When all tracks are 1fr, they divide the space equally. A track of 2fr would take twice the space of a 1fr track, but this tool generates equal tracks only, so every track is 1fr.

What is the difference between column-gap and row-gap?

Column-gap sets the horizontal space between columns, and row-gap sets the vertical space between rows. Keeping them separate lets you use tighter horizontal spacing and looser vertical spacing, which suits many card and article layouts. Both are included in the generated rule.

Should I use grid or flexbox?

Use grid when you need alignment in two directions, with rows and columns that line up. Use flexbox when you need arrangement along a single line, such as a navigation bar or a toolbar. Many pages use both: grid for the page structure and flexbox inside components.

How many cells will my grid have?

The number of preview cells equals the number of columns multiplied by the number of rows. Three columns and two rows give six cells. Eight columns and six rows give 48 cells. In your own markup, the number of child elements determines how many cells are actually filled.

Can I make one cell span two columns with this tool?

No. Spanning is an item-level property set on the child element, not on the grid container, and this tool generates container properties only. Add a grid-column rule to the child element in your own stylesheet, using the container rule from this tool as the base.

Grid Thinking: Tracks Before Items

The hardest habit to build with CSS Grid is thinking in tracks before thinking in items. Beginners often place items first and then wonder why the grid does not align, when the grid is defined by its tracks: the columns and rows that the items flow into. The CSS Grid Generator encourages the right habit by asking for columns and rows before anything else. The template definitions it produces, using repeat and fractional units, are the skeleton of the layout, and everything else, gaps and alignment, is a refinement of that skeleton.

Equal tracks are a deliberate simplification, and understanding when they stop being enough is part of learning grid. A dashboard with a narrow navigation column and a wide content column needs unequal tracks, and a magazine layout with a featured story spanning two columns needs spanning. Both are natural extensions of the equal-track starting point this tool provides: edit the template to give one track a larger fraction, or add a spanning rule to one item, and the rest of the structure stays intact. Starting equal and then breaking symmetry in one place keeps the layout understandable, while designing unequal tracks from the beginning often produces a grid that nobody, including its author, can reason about a month later.

Alignment in grid also rewards a tracks-first view. Justify-content distributes the tracks themselves when they do not fill the container, while align-items positions items inside their cells. In an equal-track grid that fills its container, justify-content may appear to do nothing, which confuses learners who expect every control to have a visible effect. The preview in this tool shows that honestly: with full tracks, some alignment combinations look identical. That is not a fault of the tool; it is how grid works, and learning to recognise when alignment matters and when it does not is a genuine piece of grid literacy.

Related Tools

These tools cover flexbox, responsive behaviour, and content that often lives inside grid cells.

Browse More Tools