A CSS grid generator turns the two-dimensional layout math of CSS Grid — column tracks, row tracks, and the gap between them — into simple sliders and presets you can see working before you write a single line of CSS. This tool builds a live grid preview that updates instantly as you adjust columns, rows or gap, and produces the exact display: grid declaration to copy into your stylesheet, including ready-made presets for the layout patterns developers build most often: even column grids, sidebar layouts, and the classic "holy grail" page structure.
What This CSS Grid Generator Does
CSS Grid Layout is a two-dimensional layout system — unlike flexbox, which arranges items along one axis at a time, grid lets you define both columns and rows simultaneously and place items within that structure. This generator controls the three properties that define the grid's shape: number of columns, number of rows, and the gap between all grid tracks.
Move any slider and the preview grid above rearranges its boxes in real time using equal-fraction (fr) sized tracks, so you can see proportions before committing to code. The presets dropdown jumps straight to common real-world patterns — a two, three, or four-column grid, a sidebar-plus-content layout, or a full holy-grail page skeleton with header, navigation, main content, aside and footer — each generating correct, ready-to-use CSS instantly.
How to Use the CSS Grid Generator
- Start from a preset, or go custom. Pick a common pattern from the dropdown for an instant starting point, or leave it on Custom and build from scratch.
- Set the number of columns and rows. Each slider controls one dimension of the grid; the preview updates immediately to show the resulting track structure.
- Adjust the gap. This sets consistent spacing between every row and column simultaneously — no separate margin rules needed.
- Review the live preview. Confirm the proportions and spacing look right before copying anything.
- Copy the CSS. Paste the generated code onto your container element; each grid item then just needs to exist as a direct child — no extra positioning CSS required for a basic grid.
How CSS Grid Actually Works
A grid container is created with display: grid, then shaped with grid-template-columns and grid-template-rows, each accepting a space-separated list of track sizes. As MDN's grid layout basic concepts guide explains, the most flexible unit for grid tracks is fr — a fraction of the remaining available space. A definition like grid-template-columns: 1fr 1fr 1fr; creates three equal-width columns that automatically grow and shrink together as the container resizes, which is why the column and row presets use fr tracks rather than fixed pixel widths (the holy-grail preset is the exception, with two 160px side columns) — it's the pattern that survives a responsive redesign without modification.
Grid also supports mixed units in the same declaration — for example grid-template-columns: 240px 1fr; gives you a fixed-width sidebar alongside a content column that fills whatever space remains, whereas this tool's "Sidebar + content" preset uses proportional tracks, 1fr 3fr, so the sidebar stays a quarter of the width. The repeat() function is a shorthand worth knowing too: grid-template-columns: repeat(3, 1fr); is functionally identical to writing 1fr 1fr 1fr but scales more cleanly when you're generating a larger number of equal tracks.
The Holy Grail Layout Pattern
The "holy grail" layout — a header spanning the full width, a footer spanning the full width, and a three-column middle section with navigation, main content, and a sidebar — was notoriously difficult to build reliably with older CSS techniques like floats. CSS Grid makes it straightforward using grid-template-areas, which lets you name each region and place elements by name rather than by row/column index. This generator's holy-grail preset outputs a named-areas grid where header and footer each span the full width, and the middle row splits into nav, main and aside tracks — a pattern still widely used for admin dashboards, documentation sites, and classic content layouts.
Grid vs. Flexbox — Choosing the Right Tool
CSS Grid and flexbox are complementary, not competing, layout systems. Grid is the right choice whenever you need to control both rows and columns together — page skeletons, image galleries, dashboards, and any layout where items need to align on both axes simultaneously. Flexbox remains the better choice for one-dimensional arrangements — a single row of navigation links, a horizontal button group, or vertically stacking form fields. In practice, most real interfaces nest the two: a CSS Grid page skeleton with flexbox used inside individual grid cells to align that cell's own content. If you need that one-dimensional alignment inside a grid cell, pair this tool with our CSS flexbox generator.
Responsive Grids Without Media Queries
One of CSS Grid's most powerful features — beyond what this generator's basic column/row sliders expose — is repeat(auto-fit, minmax(200px, 1fr)), which creates a grid that automatically adds or removes columns based on available width, with no media query required. Each track never shrinks below the minimum (200px in that example) and grows to fill remaining space equally above it. This pattern is worth knowing once you've got the fixed-column basics from this tool down, since it's the technique behind most modern responsive card and product grids that reflow smoothly from a single column on mobile up to four or five on a wide desktop screen.
Arb Digital designs and builds responsive websites for clients worldwide. If you want layout handled as part of a complete design, see our web design service.
Web Design Services All Free ToolsCommon Mistakes to Avoid
- Mixing up grid-template-columns and the number of items. The number of tracks you define controls the grid structure; the number of child elements is independent — extra items simply wrap onto additional automatic rows.
- Using fixed pixel widths for every column. Fixed widths don't adapt to different screen sizes; use
frunits (as this generator does) for tracks that should grow and shrink proportionally. - Forgetting the gap property and using margins instead. Margins on grid items create inconsistent spacing at grid edges;
gap(or the legacygrid-gap) handles internal spacing cleanly across the whole grid. - Not planning for content overflow. A grid item with more content than its track can hold will either overflow or force the track to grow unexpectedly — set
min-width: 0on grid items containing long unbreakable text or wide media if this becomes an issue. - Reaching for grid-template-areas for simple layouts. Named areas are powerful for complex or asymmetric layouts like the holy grail, but for a simple even column grid, plain
grid-template-columnsis simpler to read and maintain.
Related Free Tools From Arb Digital
Pair this generator with the CSS flexbox generator for aligning content inside individual grid cells. Style your grid items with the border radius generator and box shadow generator, set backgrounds with the CSS gradient generator, and confirm your text stays readable with the color contrast checker. Browse everything at our free online tools hub.
Worked Example With the Default Inputs
With the sliders at their defaults (3 columns, 2 rows, 16px gap) the preview shows six numbered boxes in two rows of three, and the textarea holds:
.grid-container {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(2, 1fr);
gap: 16px;
}
The tool draws one box per cell, so columns times rows gives the item count: 3 x 2 = 6. In your own page you supply the six child elements. If you add a seventh, the grid creates a third row automatically (an implicit row), and that row is sized to its content rather than by the repeat(2, 1fr) you wrote.
How to Read the Result
- The labels next to Columns, Rows and Gap show the current slider values, so you can read the exact numbers that went into the CSS.
- The numbered boxes show the cell order. Items fill left to right, then top to bottom, unless you place them explicitly.
repeat(3, 1fr)means three equal tracks that share the free width after the gaps are subtracted. The rows line is equal fractions of height, which only splits a fixed height evenly. In an auto-height container the rows size to their content, so give the container a height if you want the rows to fill it.- The gap is applied between tracks only, never around the outside edge.
Presets to Try
| Preset | Tracks it writes | Notes |
|---|---|---|
| Custom (default) | repeat(3, 1fr) columns, repeat(2, 1fr) rows, 16px gap | Columns 1-8, rows 1-6, gap 0-60px |
| 2-column grid | repeat(2, 1fr), one row | Moves the sliders to 2 columns, 1 row |
| 3-column grid | repeat(3, 1fr), one row | Moves the sliders to 3 columns, 1 row |
| 4-column grid | repeat(4, 1fr), one row | Moves the sliders to 4 columns, 1 row |
| Sidebar + content | 1fr 3fr | Sidebar gets a quarter of the width; the column and row sliders are not used |
| Holy grail | 160px 1fr 160px columns, auto 1fr auto rows, named areas | Writes grid-template-areas plus a grid-area rule for each of the five regions |
What to Do Next
- Copy the CSS onto your container and rename
.grid-containerto your own class. - For a card or product grid that should reflow on phones, swap the fixed column count for
repeat(auto-fit, minmax(220px, 1fr)). This tool does not generate that form. On very narrow screens,minmax(min(220px, 100%), 1fr)stops a track from overflowing a container narrower than 220px. - On the holy-grail output, collapse the layout for phones by redefining
grid-template-areasas a single column inside a media query. - Style the items with the border radius generator and box shadow generator.
What This Tool Does Not Cover
- All tracks are equal (
1fr) except in the sidebar and holy-grail presets. There are no mixed pixel,minmax()orautotracks in custom mode. - There is one gap value for rows and columns. CSS lets you set
row-gapandcolumn-gapseparately. - It does not place or span individual items, and it does not output
auto-fitorauto-fill.
Named Areas and Source Order
Named areas let you rearrange a page in a media query by rewriting a short text map, with no HTML changes. Be careful when you place items in a visual order that differs from the markup. Keyboard focus and screen readers follow the DOM order, not the painted order, so a layout that looks logical on screen can feel jumbled when tabbing through it. Keep the markup order close to the visual order and use areas for adjustments, not wholesale reshuffling.
Frequently Asked Questions
CSS Grid is a two-dimensional layout system that controls rows and columns simultaneously, making it ideal for page skeletons, dashboards, and image galleries. Flexbox is one-dimensional, arranging items along a single row or column, and is better suited to navigation bars, button groups, and simple alignment tasks.
fr stands for "fraction" — a unit representing a share of the available space in the grid container. grid-template-columns: 1fr 1fr 1fr creates three equal-width columns that grow and shrink together proportionally as the container resizes, without needing a fixed pixel value.
Use grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)). This automatically fits as many columns as will comfortably fill the row, with each track never shrinking below 200px, and reflows the column count as the viewport changes — all without writing a single media query.
It's a classic page structure with a full-width header and footer, and a three-column middle row containing navigation, main content, and a sidebar. CSS Grid's grid-template-areas makes this layout simple to build and maintain by naming each region rather than positioning elements by row and column index.
No — for a basic grid, applying display: grid and the template properties to the parent container is enough; direct child elements automatically become grid items and fill the defined tracks in source order. Explicit placement (grid-column, grid-row, or named areas) is only needed for custom item positioning.
Yes — completely free, with no sign-up and no limits. All grid calculations run locally in your browser, and you can build and copy as many grid layouts as you need.
This tool runs entirely in your browser — nothing you enter is uploaded or stored.