CSS Grid Generator

Visual CSS Grid layout builder with live preview. Define rows, columns, gaps, grid areas, and item placement. Generate production-ready CSS Grid code. Everything runs in your browser.

Live Preview
Columns (grid-template-columns)
Rows (grid-template-rows)
Gap
Row Gap px
Col Gap px
justify-items
align-items
justify-content
align-content
0 Items
Named Grid Areas

Define named areas using the visual ASCII syntax. Each quoted line is a row. Use a dot (.) for empty cells.

Layout Presets

How to Use CSS Grid Layout

CSS Grid Layout is the most powerful layout system available in CSS. It is a two-dimensional system, meaning it can handle both columns and rows simultaneously. You define a grid container with display: grid, then set up the track sizes with grid-template-columns and grid-template-rows. Child elements become grid items that can be placed and sized across the grid.

Defining Tracks

Grid tracks are defined using grid-template-columns and grid-template-rows. You can use fixed units (px), flexible units (fr), percentages (%), auto, and the minmax() function. The fr unit distributes available space proportionally — 1fr 2fr gives the second column twice the space of the first.

Placing Items

Grid items are placed using grid-column and grid-row properties. You specify start and end lines: grid-column: 1 / 3 spans from line 1 to line 3 (two columns). You can also use span: grid-column: span 2 makes the item span two columns from its auto-placed position.

Named Grid Areas

The grid-template-areas property lets you name regions of your grid with an ASCII-art-like syntax. Assign names with grid-area on child elements, then define the layout visually in the container. This makes complex layouts extremely readable and easy to modify for responsive designs.

Alignment

CSS Grid provides full alignment control. justify-items and align-items control how items are positioned within their grid cells. justify-content and align-content control how the entire grid is positioned within the container when the grid is smaller than the container.

Features

CSS Grid vs Flexbox

Use CSS Grid for two-dimensional layouts (page structure, dashboards, galleries) and Flexbox for one-dimensional component layouts (navbars, button groups, card content). They complement each other perfectly — it is common to use Grid for the overall page layout and Flexbox within individual grid items.

Browser Support

CSS Grid Layout is supported in all modern browsers: Chrome 57+, Firefox 52+, Safari 10.1+, and Edge 16+. The gap property (shorthand for row-gap and column-gap) is supported in Chrome 66+, Firefox 61+, Safari 12+, and Edge 16+. No vendor prefixes are needed.

Embed this tool on your site
<iframe src="https://devtoolbox.dedyn.io/tools/css-grid-generator" width="100%" height="900" frameborder="0"></iframe>

Frequently Asked Questions

What is CSS Grid Layout?
CSS Grid Layout is a two-dimensional layout system for the web. Unlike Flexbox which handles one axis at a time, CSS Grid lets you control both rows and columns simultaneously. You define a grid container with display: grid, then specify row and column tracks using grid-template-rows and grid-template-columns. Grid items can be placed precisely into cells, span multiple rows or columns, and even overlap. It is supported in all modern browsers and is the preferred method for building complex page layouts.
What is the difference between CSS Grid and Flexbox?
CSS Grid is a two-dimensional layout system (rows AND columns), while Flexbox is one-dimensional (row OR column). Use Grid for overall page layouts like headers, sidebars, and content areas. Use Flexbox for components within those areas like navigation links, card contents, or button groups. They work best when used together: Grid for the macro layout and Flexbox for micro layouts within grid items.
What are grid-template-areas and how do I use them?
grid-template-areas lets you name regions of your grid layout using a visual ASCII-art-like syntax. You assign names to grid items with grid-area, then reference those names in the container using grid-template-areas. For example: grid-template-areas: 'header header' 'sidebar main' 'footer footer'; creates a classic page layout. This approach makes your CSS more readable and easier to rearrange for responsive designs using media queries.
Keyboard Shortcuts
Ctrl+Enter Generate CSS
Ctrl+Shift+C Copy CSS
Ctrl+L Reset all