Skip to main content
CG

CSS Grid Generator

Visual CSS Grid builder — set rows, columns, gaps, and alignment, then copy the exact grid CSS in one click.

Did you like the tool? Thanks!
Share:

More CSS Tools

BS

Box Shadow Generator

Build pixel-perfect box shadows with live preview — control offsets, blur, spread, colour, and opacity, then copy the CSS in one click.

BR

Border Radius Generator

Shape rounded corners visually — control all four corners independently or link them together, with instant preview and CSS output.

TS

Text Shadow Generator

Add depth to your typography — control shadow offset, blur, colour, and preview on custom text with live CSS output.

GT

Gradient Text Generator

Transform plain text into vibrant gradient typography — choose colours, direction, and preview live with ready-to-use CSS.

CV

CSS Variables Generator

Define and preview CSS custom properties in real time — build your :root block visually and see variables applied to a sample card component.

FG

Flexbox Generator

Visual Flexbox playground — choose direction, alignment, wrapping, and gap; see numbered items rearrange live.

BG

Button Generator

Complete button styler — colours, borders, padding, shadows, hover state, and a live editable preview.

CA

CSS Animation Generator

Build CSS @keyframes animations visually — choose from 7 preset templates, tweak every parameter, and see your animation play live.

HC

Hover Card Generator

Design cards with smooth hover effects — lift, scale, shadow, and border transitions, all previewed live on a sample card.

SA

Scroll Animation Generator

Build scroll-triggered animations — elements fade and slide into view as the user scrolls, powered by Intersection Observer.


    

How to Use CSS Grid Generator

Set the number of columns (1 to 6) and rows (1 to 6) using sliders, adjust the column and row gap independently (0–40 px each), and choose alignment values for justify-items and align-items from the dropdowns (start, centre, end, stretch). The preview panel instantly renders a live grid with numbered cells so you can see exactly how the template areas map to your chosen dimensions. Each cell shows its index number in the centre, bordered and spaced according to your gap settings. Below the preview, the generated CSS is displayed in a syntax-highlighted code block — a single `.grid-container` rule with all the properties you have configured. Use the Copy CSS button to copy the entire rule to your clipboard and paste it directly into your stylesheet or a CodePen.

About CSS Grid Generator

CSS Grid is the most powerful layout system ever added to the web platform. Before Grid, web developers had to choose between tables (semantically wrong, rigid, inaccessible), floats (never designed for layout, required clearfix hacks and source-order dependencies), and Flexbox (one-dimensional — excellent for rows or columns, but unable to handle both axes simultaneously). Grid was the first native CSS module designed from the ground up for two-dimensional layout, and it fundamentally changed how complex page structures are built. At its core, CSS Grid works by establishing a grid container (with `display: grid`) and then defining its tracks — the rows and columns — using either explicit track sizes or the `repeat()` function for repeated patterns. The `grid-template-columns` property defines the column structure; `grid-template-rows` defines the row structure. Each track can be sized using any CSS length unit, the `fr` (fraction) unit for proportional distribution, `auto` for content-based sizing, or the `minmax()` function for flexible minimum and maximum constraints. This tool uses `repeat(N, 1fr)` syntax, where N is your chosen number of columns or rows, and `1fr` means each track gets an equal share of the available space. The `gap` property (shorthand for `row-gap` and `column-gap`, which themselves replace the older `grid-row-gap` and `grid-column-gap`) controls the spacing between grid cells. Unlike margins, gaps only appear between adjacent tracks — there is no gap on the outer edges of the grid — which means you do not need negative margins or `:last-child` selectors to remove unwanted outer spacing. This is one of the small but enormously useful quality-of-life improvements that Gap brought to CSS layout. The `justify-items` and `align-items` properties control how individual grid items are positioned within their grid cells. `justify-items` operates along the inline (row) axis — it controls horizontal alignment of items within their column track. `align-items` operates along the block (column) axis — it controls vertical alignment of items within their row track. Both accept four values: `start` (align to the beginning of the track), `end` (align to the end), `center` (centre — note: the CSS property value uses the American spelling, though the concept itself is universal), and `stretch` (the default, which expands the item to fill the entire track). Understanding the difference between the two axes is essential: `justify-items` is horizontal, `align-items` is vertical — the same naming convention used across Grid, Flexbox, and older alignment properties. The history of CSS Grid is instructive. The first draft of a CSS grid system was proposed by Microsoft in 2011 and shipped in Internet Explorer 10 behind an `-ms-` prefix. That early implementation was functional but incomplete and used a different syntax from the final standard. The CSS Working Group spent five more years refining the specification, and the final W3C Recommendation was published in 2017. By the time Grid shipped in Firefox 52, Chrome 57, and Safari 10.1 in March 2017 — a coordinated launch across all three major browser engines in the same month — it was already a mature, well-tested specification. The simultaneous launch was unprecedented and ensured that Grid adoption was not fragmented across browsers from day one. This tool exists because writing Grid CSS by hand involves mental arithmetic that is error-prone: you need to count columns, calculate `repeat()` counts, remember which property controls which axis, and verify the result visually. By providing sliders and dropdowns that update a live preview instantly, it removes the guesswork and lets you experiment freely — try six columns, then three; try `start` alignment, then `centre`; adjust the gap from 0 to 40 px and watch the cells spread apart — and only copy the CSS once you are satisfied with what you see. It is the equivalent of a visual drag-and-drop builder, but for the fastest and most precise layout method in CSS. The Grid specification also includes more advanced features that are beyond the scope of this tool but worth knowing about for when your layouts grow more complex: named grid areas (using `grid-template-areas` and the `grid-area` property to assign semantic names to regions of the grid), implicit tracks (what happens when you place an item outside the explicitly defined grid — controlled by `grid-auto-rows` and `grid-auto-columns`), the `grid-auto-flow` property (which determines whether auto-placed items fill rows first or columns first), and subgrid (which allows a nested grid to inherit the track definitions of its parent grid). These features make Grid capable of layouts that would have required JavaScript or server-side calculation in the pre-Grid era, and learning them is the natural next step after mastering the basics that this tool helps you visualise.

Details & Tips

Property reference for the generated CSS: **display: grid** — The container becomes a block-level grid container. Its direct children become grid items and are placed into the grid cells automatically by the auto-placement algorithm. Unlike Flexbox, which is inherently one-dimensional and wraps overflowing items to a new line, Grid places items into a rigid two-dimensional structure defined by the explicit tracks. **grid-template-columns: repeat(N, 1fr)** — The `repeat()` function is a convenience that avoids writing `1fr 1fr 1fr` N times. The first argument is the repeat count (your chosen number of columns); the second is the track size. The `1fr` unit means "one fraction of the remaining free space in the grid container." If you have three `1fr` columns and the container is 900 px wide with a total gap of 32 px (two 16 px gaps), each column is (900 - 32) / 3 = 289.33 px. The `fr` unit is what makes Grid adaptive — change the container width and the column widths recalculate automatically. **grid-template-rows: repeat(N, auto)** — Same pattern but for rows. Using `auto` (rather than `1fr`) means each row is as tall as its tallest content. If you prefer equal-height rows regardless of content, swap `auto` for `1fr` in your final CSS. **gap: Xpx Ypx** — Shorthand for row-gap and column-gap. When two values are given, the first is row-gap (vertical spacing) and the second is column-gap (horizontal spacing). When one value is given, it applies to both axes. This tool uses the two-value form so row and column spacing can be set independently. **justify-items: value** — Horizontal alignment of grid items within their column track: `start` snap to left, `end` snap to right, `center` centre horizontally, `stretch` fill the column width. **align-items: value** — Vertical alignment of grid items within their row track: `start` snap to top, `end` snap to bottom, `center` centre vertically, `stretch` fill the row height. **Numbered cells preview:** Each cell in the preview is a `<div>` inside the grid container with its index number displayed in the centre. The cells have a border and a subtle background colour for visibility. The grid container itself has a dashed border so you can see its boundaries. The gaps are rendered as the background of the grid container showing through — this is the default browser behaviour and matches how gaps appear on a real page. **Responsive behaviour:** CSS Grid is responsive by nature — the `fr` units and `auto` rows adapt to the container width and content. The preview panel in this tool is constrained to a fixed minimum height (300 px) to keep it usable, but the CSS you copy will adapt to whatever container you paste it into. For mobile-first responsive designs, combine the copied Grid CSS with `@media` queries that change the number of columns (e.g. `grid-template-columns: repeat(1, 1fr)` on small screens, `repeat(3, 1fr)` on larger ones).

Frequently Asked Questions

How do I use the CSS Grid Generator?
Set the number of columns and rows using the sliders, adjust the gap size, choose alignment options from the dropdowns, and watch the preview update live. Click Copy CSS to copy the generated code to your clipboard.
What does justify-items do?
It controls the horizontal alignment of grid items within their column track. Options are start (left), end (right), centre (middle), and stretch (fill the column width, the default).
What does align-items do?
It controls the vertical alignment of grid items within their row track. Options are start (top), end (bottom), centre (middle), and stretch (fill the row height, the default).
What is the fr unit in the generated CSS?
fr stands for \"fraction\" — it divides the available space in the grid container proportionally. If you have three 1fr columns, each gets one-third of the space remaining after gaps are subtracted.
What is the difference between gap, row-gap, and column-gap?
gap is the shorthand — it sets both row and column spacing. This tool lets you set them independently, which generates the two-value form: `gap: rowGap columnGap`.
Why do the gaps appear between cells but not on the outer edges?
That is how the CSS gap property works by design — it only applies between adjacent tracks, never on the outer edges of the grid container. This eliminates the need for negative margins or last-child overrides.
Can I use the generated CSS in a responsive design?
Yes — the CSS is standard and works in all modern browsers. For responsive layouts, wrap the copied code in an @media query that overrides the column count for different screen widths (e.g. one column on mobile, three on desktop).
What browsers support CSS Grid?
CSS Grid is supported in all modern browsers since March 2017, including Chrome, Firefox, Safari, and Edge. Internet Explorer 11 has partial support with an -ms- prefix and a different syntax, but the CSS generated by this tool uses the standard syntax.
How is the grid preview built?
The preview panel is a live div with inline styles matching your chosen settings. The cells are numbered child divs (1 to rows × columns) automatically placed by the grid auto-placement algorithm.
Can the tool generate named grid areas?
No — this tool focuses on the core Grid properties (tracks, gaps, and alignment). Named grid areas and advanced features like subgrid require semantic knowledge of your layout that a visual tool cannot infer.
Is my data sent to a server?
No — the grid preview and CSS generation run entirely in your browser using JavaScript. Nothing you configure is transmitted anywhere.

Part of These Collections

Also Available As

css grid generator, grid template builder, grid layout, css grid, grid-template-columns, grid-template-rows, justify-items, align-items, grid gap, grid generator, visual grid, layout builder

Found a Problem?

Let us know if something with CSS Grid Generator isn't working as expected.

Thanks — we'll take a look.