CSS Grid Generator
Tracks, Gaps and Named Areas
Design a grid and copy the CSS. Set column and row tracks in fr, px, percent, auto or minmax(), draw named areas by dragging, then copy grid-template-areas, the grid-area rules or Tailwind classes. 100% client-side. Zero data stored.
CSS Grid Generator Tool
Build a CSS Grid
Presets
Columns
Rows
Track sizes: 1fr, 200px, 25%, 12rem, auto, min-content, max-content, minmax(100px, 1fr), fit-content(300px), or one repeat(auto-fit, minmax(160px, 1fr)) track.
Draw named areas
Press and drag across the cells with a mouse, finger or pen. With the keyboard, arrow keys move between cells, Space or Enter starts a selection, the arrows stretch it, Enter creates the area and Escape cancels. Delete removes the area under the cursor.
Drag across the cells to draw a named area.
No named areas yet. The CSS below has only the tracks.
Dashed cells are placeholders so every track is visible. They are not part of the CSS.
CSS
Tailwind CSS
Tailwind grid-cols-3 means repeat(3, minmax(0, 1fr)), which is not the same as repeat(3, 1fr), so the template is an arbitrary value that matches the CSS exactly. The line labels are for reading; copy the classes after the colon. Tailwind 3 and 4.
Common Use Cases
Page Layouts
Draw a header, sidebar, main and footer and copy the template areas, the holy grail layout in one block of CSS.
Dashboards
Mix fixed and flexible tracks, span tiles across several rows and columns, and see the result before you write markup.
Responsive Galleries
Use repeat(auto-fit, minmax(160px, 1fr)) for a gallery that adds and removes columns on its own, with no media query.
Magazine Layouts
Give a feature story two rows and a wide banner a full row, with unequal columns that keep their proportions.
12-Column Systems
Start from twelve equal tracks with a gap and build your own spans on top, in plain CSS or Tailwind.
Learning Grid
Change a track or an alignment and watch the cells and the CSS move together, which makes the grid model click.
Grid Syntax Reference
Track Sizes
| Size | What it means |
|---|---|
| 1fr | One share of the free space |
| 200px, 12rem, 25% | A fixed length or a share of the container |
| auto | As big as the content needs, and it can stretch |
| min-content | The narrowest the content can be |
| max-content | The widest the content wants to be |
| minmax(100px, 1fr) | At least 100px, at most one share |
| fit-content(300px) | Content size, but never over 300px |
| repeat(auto-fit, minmax(160px, 1fr)) | As many 160px or wider columns as fit |
A run of identical tracks is written as repeat() only when that is shorter than listing them.
Alignment Properties
| Property | What it aligns |
|---|---|
| justify-items | Each item inside its cell, left to right |
| align-items | Each item inside its cell, top to bottom |
| justify-content | The whole set of columns inside the container |
| align-content | The whole set of rows inside the container |
The two content properties only matter when the tracks are smaller than the container, so give the grid a height and fixed track sizes to see align-content.
1fr is not always equal
1fr means minmax(auto, 1fr), so a wide item can stretch its column. Use minmax(0, 1fr) when you need columns that stay exactly equal.
Areas must be rectangles
A named area is one rectangle of cells. L shapes and areas that overlap are invalid CSS, so this tool will not draw them.
auto-fit and auto-fill
Both make as many columns as fit. With few items, auto-fit collapses the empty columns so the items grow, and auto-fill keeps them empty.
Related tools
For one-dimensional layouts use the Flexbox Playground, and round the corners with the Border Radius Generator.
Pro Tip: URL Parameters
Open the generator with a grid already loaded. Use ?preset= with holy, twelve, dashboard, gallery or magazine, or describe the grid with ?c= (columns), ?r= (rows), ?g= (gaps), ?a= (alignment), ?h= (height) and ?areas=. For example: /grid-generator/?preset=holy or /grid-generator/?c=200px~1fr&r=auto~1fr&areas=header.1.1.1.2~main.2.2.2.2
Tracks are joined by a tilde. g is row gap and column gap, a is justify-items, align-items, justify-content and align-content, h is a height in pixels or auto. Each area is name.row1.column1.row2.column2 with 1-based cell numbers. The link in your address bar updates only after you change something, and the Copy Link button builds it from your current grid.
Frequently Asked Questions
fr is a share of the free space in the grid container. After fixed tracks and gaps are subtracted, 1fr 2fr gives the first track one third and the second two thirds. Because 1fr is really minmax(auto, 1fr), a track will not get narrower than its content, so use minmax(0, 1fr) if you need columns that stay exactly equal.
Press and drag across the cells in the Draw named areas box with a mouse, finger or pen. With the keyboard, move with the arrow keys, press Space or Enter to start, stretch with the arrows and press Enter to create the area. Each area gets a name you can edit in the list, and the template areas and grid-area rules update at once.
In CSS every named area in grid-template-areas must be a single rectangle, and two names cannot occupy the same cell. An L shape or an overlap makes the whole declaration invalid, so the browser ignores it. The tool refuses those selections and tells you which area is in the way. To overlap items on purpose, place them with line numbers instead.
Both create as many columns as fit in the container. When there are fewer items than columns, auto-fill keeps the empty columns so the items stay at their minimum size, while auto-fit collapses the empty columns so the items stretch to fill the row. For a gallery that should fill its width, auto-fit with minmax(160px, 1fr) is the usual choice.
grid-template-areas needs a fixed number of columns, and an auto-fit or auto-fill track makes the count depend on the screen width. The tool keeps the areas you drew but leaves them out of the CSS and the preview while such a track is present. Replace it with fixed tracks to bring them back.
justify-items places each item inside its own cell along the row direction, while justify-content places the whole set of columns inside the container when the columns are narrower than it. The align versions do the same for the block direction. The content properties only show a difference when the tracks are smaller than the container, such as fixed pixel tracks in a wider grid.
The preview needs a height to show rows that share space and to show align-content. It is written to the CSS only while the field has a value. Clear the field and the height is left out, so the grid is as tall as its rows need.
Copy the classes after the colon of the Container line and put each area class on its element. The template is an arbitrary value such as grid-cols-[200px_1fr] because Tailwind grid-cols-3 means repeat(3, minmax(0, 1fr)), which differs from repeat(3, 1fr). The named areas use an arbitrary property and per-area classes like [grid-area:header]. They work in Tailwind 3 and 4.
Yes. CSS grid, named areas, minmax(), auto-fit and gap are supported in all current browsers. This tool writes plain grid CSS and does not generate subgrid or masonry layouts.
Yes to the link. Use ?preset= with holy, twelve, dashboard, gallery or magazine, or describe the grid with ?c=, ?r=, ?g=, ?a=, ?h= and ?areas=. The Copy Link button builds the link from your current grid. Nothing is sent anywhere: the preview and the CSS are made in your browser.
Why We Built This Grid Generator
Grid is the most powerful layout tool in CSS and the hardest to hold in your head. A template of tracks is one line, a template of areas is another, and the two have to agree on how many rows and columns there are. Most generators give you a grid of boxes and a block of numbers. We built one where you describe the tracks, draw the areas on the cells with your mouse, finger or keyboard, and see the real grid change in the preview.
The output is the shortest valid form: identical tracks collapse to repeat() only when that is shorter, defaults are left out, and every area gets a grid-area rule. You can copy the CSS, copy Tailwind classes that match it exactly, download a stylesheet, and share a link that restores the whole grid. Everything runs in your browser and nothing you design is uploaded.
The Grid Generator is part of RJL.io's collection of free developer tools. For one-dimensional layouts try the Flexbox Playground, round the corners with the Border Radius Generator, and build backgrounds with the Gradient Generator.