Skip to main content

CSS Grid Generator

Build CSS Grid layouts visually and copy the code.

How it works

  1. 1

    Define the grid

    Set columns and rows using size inputs, or pick a preset layout to start from.

  2. 2

    Place items

    Click cells in the preview to add items and shift-click to span areas.

  3. 3

    Copy the CSS

    Copy the generated container and item CSS to use in your project.

Common use cases

  • Holy Grail layout

    Holy Grail preset with 3 columns and 3 rows

  • Custom card grid

    3 equal columns, 24px gap, auto rows

About This Tool

Visual CSS Grid layout builder. Define columns and rows with flexible units (fr, px, auto, minmax), set gaps, place items into grid areas, and see the result live.

Layout presets: Start from common patterns like Holy Grail (header, sidebars, main, footer), Dashboard (4-column card grid), Card Grid, or Sidebar + Content, then customize freely. Copy clean CSS for both the container and individual items.

All layout building happens in your browser — no data is transmitted anywhere.

CSS Grid is the most powerful layout system available in CSS. Unlike Flexbox, which operates on a single axis, Grid lets you control both rows and columns simultaneously, making it ideal for full-page layouts, dashboard interfaces, card grids, and any design that requires precise two-dimensional control.

The grid-template-columns and grid-template-rows properties define the structure of your grid. Each value in the list creates a track (column or row). The fr (fraction) unit is the most important Grid unit — it distributes available space proportionally. A template of 1fr 2fr 1fr creates three columns where the middle one is twice as wide as the outer ones. Combined with fixed units like px and auto, fr gives you precise control over how space is allocated.

The minmax() function is essential for responsive Grid layouts. It defines a size range: minmax(200 px, 1fr) means the track should be at least 200 px wide but can grow to fill available space. A common responsive pattern is repeat(auto-fit, minmax(300 px, 1fr)) which creates as many 300 px columns as fit in the container and stretches them to fill the space — all without media queries.

Grid gaps (row-gap and column-gap, or the shorthand gap) add consistent spacing between tracks without adding margins to the items. This is cleaner than the older margin-based spacing approach and works perfectly with responsive layouts.

Grid template areas provide the most readable way to define complex layouts. Instead of positioning items by line numbers, you name areas with ASCII-art-like strings: "header header" "sidebar main" "sidebar footer". This makes the layout intent immediately clear and is easy to modify. Template areas are particularly useful for full-page layouts with header, navigation, content, and footer regions.

The Holy Grail layout — a header, two sidebars, main content, and footer — is one of the most common page-level grid patterns. It was notoriously difficult to implement before CSS Grid, requiring float hacks or complex Flexbox nesting. With Grid, it is a simple template-areas definition.

Dashboard layouts typically use a multi-column grid for cards and widgets. A 4-column grid with auto rows creates a flexible card layout that fills the available space. Cards can span multiple columns or rows using grid-column and grid-row properties.

Responsive grid techniques: Use auto-fit or auto-fill with minmax() for automatic responsive columns. Change grid-template-areas at different breakpoints for completely different layouts at each screen size. Use min() or max() to set upper and lower bounds on track sizes.

More examples

Examples

Holy Grail layout

Input

Holy Grail preset with 3 columns and 3 rows

Output

CSS with header, sidebars, main content, and footer areas

Custom card grid

Input

3 equal columns, 24px gap, auto rows

Output

grid-template-columns: 1fr 1fr 1fr with gap applied
Frequently Asked Questions
What is the difference between CSS Grid and Flexbox?
CSS Grid is a two-dimensional layout system designed for rows and columns simultaneously. Flexbox is one-dimensional and works best for laying out items in a single row or column. Use Grid for full page layouts and complex two-axis arrangements, and Flexbox for component-level alignment within grid cells.
What units can I use for column and row sizes?
You can use fr (fractional unit), px (fixed pixels), auto (content-sized), % (percentage of container), rem, and minmax() for responsive ranges. The fr unit is most powerful — 1fr means "take an equal share of remaining space".
What are the built-in presets?
The generator includes Holy Grail (header, two sidebars, main content, footer), Dashboard (4-column card grid), Card Grid (3-column equal grid), and Sidebar + Content (two-column with fixed sidebar). Select any preset and then customize freely.
What is grid-template-areas and when should I use it?
grid-template-areas lets you name regions of your grid layout using strings like "header header" and "sidebar main". It makes the intent of a layout self-documenting and is great for full page templates. Use the toggle in the code output section to switch between column-based and area-based syntax.
What is the fr unit?
The fr (fraction) unit represents a share of the available space in the grid container. 1fr 1fr creates two equal columns. 1fr 2fr creates two columns where the second is twice as wide. fr distributes space after fixed-size tracks and gaps are accounted for.
How do I make a responsive grid without media queries?
Use repeat(auto-fit, minmax(300px, 1fr)) for grid-template-columns. This creates as many 300px columns as fit in the container, then stretches them to fill the space. When the container narrows, columns automatically wrap to the next row.
What is the difference between auto-fit and auto-fill?
auto-fill creates empty tracks to fill the container, while auto-fit collapses empty tracks to zero. In practice, auto-fit stretches your items to fill the space, while auto-fill preserves the defined size. For most responsive layouts, auto-fit produces the desired behavior.
How do I span items across multiple grid cells?
Use grid-column: span 2 to span across two columns, or specify start and end lines like grid-column: 1 / 3. In the visual editor, click a cell to start and shift-click another cell to span. Grid line numbers start at 1.

Learn More

Related Guides

Discover More Tools

View all Design Tools →