AnyTool
Your files never leave your device. All processing happens locally in your browser.

How do I generate CSS Grid code?

Define your column and row tracks (each as fr, px, %, em, rem, auto, min/max-content or minmax(a,b)), set the row and column gap, optionally switch on a responsive repeat(auto-fit, minmax()) so columns wrap themselves, or paint a named grid-template-areas layout onto the preview grid. The CSS Grid Generator serialises the full “.container” rule plus per-item grid-area rules and shows a live, numbered preview — all 100% in your browser, nothing uploaded.

  • Add / remove up to 12 column and 12 row tracks, each with its own unit
  • Units: fr, px, %, em, rem, auto, min-content, max-content, minmax(a, b)
  • Row & column gap in px / rem / em / %
  • Responsive repeat(auto-fit | auto-fill, minmax(min, 1fr)) — wrap without media queries
  • Named grid-template-areas painted cell-by-cell, validated as solid rectangles
  • Copy the container rule or the full CSS (with per-item grid-area rules); live preview
  • 100% client-side — the CSS is built from your inputs, nothing uploaded

What is

CSS Grid

CSS Grid Layout is a two-dimensional layout system that arranges elements into rows and columns at the same time. A grid container (display: grid) is divided into tracks defined by grid-template-columns and grid-template-rows, separated by a gap, and children are placed into cells either automatically in source order or explicitly with line numbers or named grid-template-areas.

Web Design

Related terms

grid-template-columnsgrid-template-areasfr unitminmax()repeat()auto-fit

Frequently Asked Questions

Yes. Your track lists, gaps and named areas are serialised into CSS entirely on your device — nothing is uploaded, and there is no server or CDN in the processing path.

Everything is 100% client-side. The tool holds the grid definition as plain numbers and strings, validates any named areas and serialises the “.container” rule and per-item grid-area rules right in your browser tab — no input is ever sent to a server, and there is no CDN in the processing path. You can copy just the container rule or the full CSS, and it works offline once the page is cached.

Both wrap columns without media queries. auto-fit collapses empty tracks so the present items stretch to fill the row; auto-fill keeps the empty tracks, leaving gaps at the end.

When you use repeat(auto-fit, minmax(min, 1fr)) or repeat(auto-fill, minmax(min, 1fr)), the browser fits as many columns as will hold the minimum size and wraps the rest — no media queries needed. The difference shows once the row is wider than the items need: auto-fit COLLAPSES the leftover empty tracks to zero width, so your existing items stretch to fill the whole row, whereas auto-fill KEEPS those empty tracks at full width, leaving visible gaps where future items could go. Use auto-fit when you want items to grow and fill; use auto-fill when you want a stable column rhythm.

Use Grid for two-dimensional layouts (rows and columns together) like page structure and card grids; use Flexbox for one-dimensional content like a nav bar or button row. They compose well.

CSS Grid is a two-dimensional system — it controls rows and columns at the same time — so it is the right tool for page-level layouts and card grids where alignment matters in both directions. Flexbox is one-dimensional, laying items out along a single row or column, which makes it the better fit for a nav bar, a toolbar or a group of buttons. In practice the two work together: Grid for the overall page, Flexbox inside a grid cell to align that cell’s contents. This generator builds Grid; a separate Flexbox playground handles the 1-D case.

You name cells in a matrix of strings; repeating a name across adjacent cells makes one area that spans them. Every named area must form a solid rectangle or the declaration is invalid.

grid-template-areas describes the layout as one quoted string per row, with a word for each column cell and a dot (.) for an empty cell. Repeating the same name across neighbouring cells — within a row and across rows — creates a single named area that spans them, and each child is placed with grid-area: name. The one hard rule is rectangularity: the cells sharing a name must form a filled rectangle, otherwise the whole grid-template-areas declaration is invalid and ignored. This tool paints areas cell-by-cell, checks the rectangle rule live, warns you if it fails, and emits the matching per-item grid-area rules automatically.

Detailed Explanation

Methodology

How the CSS Grid Generator Builds a Layout

CSS Grid is a two-dimensional layout system: a grid container (display: grid) is divided into COLUMN and ROW tracks at the same time, separated by a gap, and children land in the resulting cells. This generator’s engine (gridEngine.ts) holds the layout as typed track lists — each track being fr, px, %, em, rem, auto, min-content, max-content or minmax(a, b) — plus a row/column gap, and serialises grid-template-columns, grid-template-rows and gap into a copyable .container rule. Tracks can be added or removed (up to 12 each) and the CSS updates deterministically from the inputs.

  • Grid is 2-D: it defines columns AND rows simultaneously
  • Each track: fr, px, %, em, rem, auto, min-content, max-content, or minmax(a, b)
  • fr distributes leftover space; minmax(a, b) sets a floor and ceiling per track
  • Row and column gap in px / rem / em / %
  • Pure and deterministic — the same track lists always emit the same CSS
Use Cases

Responsive Columns: auto-fit vs auto-fill

Switching on responsive columns emits repeat(auto-fit | auto-fill, minmax(min, 1fr)) — the canonical way to make a card grid wrap by itself with no media queries. The browser fits as many columns as the minimum size allows and wraps the rest. The two keywords differ once the row is wider than the items need: auto-fit COLLAPSES the empty leftover tracks so the present items stretch to fill the row, while auto-fill KEEPS those empty tracks (leaving gaps where future items could sit). The tool spells out this difference so you pick the right one.

  • repeat(auto-fit | auto-fill, minmax(min, 1fr)) wraps columns without media queries
  • auto-fit collapses empty tracks → existing items stretch to fill the row
  • auto-fill keeps empty tracks → stable column rhythm with trailing gaps
  • The minmax floor is the item’s minimum width before wrapping
Limitations

Named grid-template-areas Must Be Rectangles

The tool can build a named layout with grid-template-areas: you paint an area name onto each cell of the preview, repeating a name across adjacent cells to make an area span them, and dots mark empty cells. The one hard rule from the CSS spec is rectangularity — the cells sharing a name must form a solid, filled rectangle, otherwise the entire grid-template-areas declaration is invalid and ignored. The engine validates this live: it checks each area’s cell count equals its bounding-box area, warns honestly when an area is not rectangular, and only then emits the areas block plus a per-item .area { grid-area: area } rule for each name.

  • Areas are declared as one quoted string per row; a dot (.) is an empty cell
  • Repeating a name across adjacent cells makes one area spanning them
  • Every named area MUST form a solid rectangle or the declaration is invalid
  • The engine validates rectangularity and omits invalid areas with a warning
  • A matching .area { grid-area } rule is emitted for every named area
Privacy & Security

Private by Design

Everything happens on the user’s device. The track lists, gaps and named areas are just numbers and strings that are validated and serialised into CSS locally in the browser tab — there is no server call and no CDN in the processing path. Nothing is uploaded, logged or stored; the output is plain CSS text copied to the clipboard, and the tool works offline once loaded.

  • Track lists, gaps and areas are serialised into CSS entirely in the browser
  • No upload, no CDN in the processing path, no server, no tracking
  • Output is plain CSS text copied locally to the clipboard
  • Works offline after first load; nothing is stored server-side
CSS Grid vs Flexbox — which layout tool to reach for
AspectCSS GridFlexbox
DimensionsTwo-dimensional (rows AND columns)One-dimensional (a single row OR column)
Best forPage scaffolds, dashboards, card grids, galleriesNav bars, toolbars, button groups, centring
ApproachLayout-first: define the grid, place contentContent-first: items flow along one axis
Explicit placementLine numbers or named grid-template-areasorder + align-self on individual items
Responsive wraprepeat(auto-fit | auto-fill, minmax())flex-wrap + flex-basis
They composeGrid for the overall page……Flexbox inside a grid cell

Grid and Flexbox are complementary, not competing. Use Grid when you need to align in two directions and Flexbox for single-axis content; the most robust layouts use both. Both have broad support in every modern browser. As of July 2026.