CSS Grid Generator
Design CSS grid layouts visually with our free online CSS Grid Generator. Click to place items, drag to span rows/columns, and export clean CSS code instantly.
What is the CSS Grid Generator?
The CSS Grid Generator is a free interactive visual builder that turns clicks into clean, copy-ready CSS Grid code. Whether you are wireframing a Holy Grail layout, prototyping a photo gallery, or learning how grid-template-columns and grid-area work, this tool gives you a live preview, per-track sizing controls, and one-click export.
CSS Grid is the most powerful layout system in CSS. Unlike Flexbox which works in one dimension, Grid lets you control rows and columns simultaneously. This generator makes it easy to experiment with Grid concepts like the fr unit, minmax(), named areas, and item placement without writing any code by hand.
The fr Unit in CSS Grid
The fr unit means a fraction of the available free space in the grid container. After fixed sizes (px, em, %) are subtracted, the remaining space is divided proportionally among fr tracks. For example, 1fr 2fr 1fr gives the middle column twice as much free space as the others. Use fr for flexible, proportional layouts that adapt to container size.
CSS Grid vs Flexbox
Flexbox is one-dimensional and arranges items along a single axis (a row or a column). CSS Grid is two-dimensional and controls rows and columns at the same time. Use Flexbox for navbars, button groups, or single rows of cards. Use Grid for full page layouts, photo galleries, dashboards, and any design where you need precise alignment across both axes. Many modern UIs combine both: Grid for the page skeleton and Flexbox inside individual cells.
Six Built-in Presets
- Holy Grail — Classic page layout with header, sidebar, content, aside, and footer using named areas.
- Photo Gallery — Image walls with asymmetric featured shots on a uniform grid.
- Dashboard — Admin panels with KPI cards, charts, and mixed track sizing with multi-row spans.
- Card Grid — Responsive product or article grids using
minmax()patterns. - Magazine — Editorial layouts with hero sections, sidebars, and heavy column spans.
- 12-Column System — Bootstrap-style framework with 12 equal
1frcolumns and custom spans.
Tips for Cleaner Grid CSS
- Prefer
frover%—frrespects gaps while%does not, so percentage-based grids can overflow. - Use
grid-template-areasfor named regions — far more readable than line numbers and self-documenting. - Reach for
minmax()withauto-fitfor responsive grids without media queries. - Set explicit gaps with
gap: 1reminstead of margins on items — gaps never collapse and never need cleanup. - Combine Grid for the page skeleton and Flexbox for intra-cell alignment. Do not force one tool to do both jobs.
How to Use the CSS Grid Generator
- Pick a starting preset from the six options at the top, or build from scratch.
- Set rows and columns using the + and − buttons, and edit each track size with
fr,px,%,auto, orminmax(). - Click any empty cell to add an item, or click an existing item to select it and use the span controls to change its row/column span.
- Adjust gaps and alignment with the range sliders and dropdowns.
- Toggle the grid line overlay to see exactly where lines 1, 2, 3 fall — great for learning placement.
- Switch between the CSS and HTML tabs, then click Copy or Download to grab the generated code.
For more CSS and design tools, try the CSS Flexbox Generator, CSS Box Shadow Generator, and CSS Gradient Generator.
Frequently Asked Questions
Does this generator support grid-template-areas?
The Holy Grail preset uses grid-template-areas in its exported CSS. For other presets we use line-based placement (grid-column / grid-row) since it adapts more flexibly when you click and rearrange items.
Can I export the HTML too?
Yes. Switch to the HTML tab in the code panel to copy a ready-to-use HTML structure that matches the generated CSS exactly.
What does the fr unit mean?
The fr unit stands for a fraction of the available free space. After fixed-size columns consume their space, the remaining room is divided among fr columns proportionally. For example, 1fr 2fr 1fr makes the middle column twice as wide as each outer column.
How do I make a grid item span multiple cells?
Use grid-column: span 2 to make an item two columns wide, or grid-column: 1 / 4 to span from line 1 to line 4. In this generator, click any item to select it, then use the + and − buttons in the item editor to grow or shrink its span.
What is minmax() in CSS Grid?
minmax(min, max) defines a track size with a lower and upper bound. It is most often paired with auto-fit or auto-fill in repeat() to build responsive grids without media queries. For example, repeat(auto-fit, minmax(200px, 1fr)) creates as many 200px-minimum columns as fit the container.
Does the tool work on mobile?
Yes. The builder reflows to a single column on phones, the controls stay tappable, and the preview remains interactive on touch screens.