CSS Grid & Flexbox Generator — Free Online Tool

Generate CSS Grid layouts visually. Set columns, rows, gaps, areas. Drag to design grid templates. Copy CSS code for grid-template. Live preview.

Use this free online CSS Grid & Flexbox Generator directly in your browser. No signup required, no data leaves your device. Part of Utilier — a collection of 133+ developer utilities.

What is CSS Grid Generator & Layout Designer?

CSS Grid is a two-dimensional layout system for web pages, allowing you to create complex grid-based layouts with rows and columns. This tool generates CSS Grid code visually — define the number of columns and rows, set gaps, create named grid areas, and see the layout rendered in real-time. The output is ready-to-use CSS (display: grid, grid-template-columns, grid-template-rows, grid-gap, grid-template-areas) for modern responsive layouts.

  • Column and row definition: Set the number of columns and rows. Define track sizes using fr units, pixels, percentages, auto, or min-max().
  • Gap (gutter) control: Set spacing between grid items with grid-gap, column-gap, and row-gap. Visual feedback shows gaps between cells.
  • Grid template areas: Name grid areas (header, sidebar, main, footer) and assign items to areas. Creates semantic, maintainable layouts.
  • Responsive grid: Use fr units (fractional units) for fluid layouts. 1fr 1fr 1fr creates 3 equal-width columns that adapt to container width.
  • CSS code output: Generates complete CSS Grid code including grid-template-columns, grid-template-rows, grid-template-areas, and item placement.

Why use CSS Grid generator?

CSS Grid syntax is complex, especially for named areas and responsive layouts. This tool makes grid creation visual and eliminates syntax errors.

  • Visual design: See the grid layout as you design it. No need to imagine how grid-template-columns: 1fr 2fr 1fr looks — see it rendered.
  • Learn Grid syntax: See how visual changes translate to CSS code. Great for learning grid-template-areas, fr units, and minmax().
  • Save time: Avoid trial-and-error in the browser. Design the grid visually, copy CSS, paste into your project.
  • Complex layouts made easy: Named grid areas (grid-template-areas) are tedious to write manually. The tool generates the syntax automatically.
  • Responsive grids: Experiment with fr units, auto-fit, and minmax() for responsive layouts that adapt to screen sizes.
  • Browser compatibility: Generates modern Grid syntax supported by all current browsers (Chrome, Firefox, Safari, Edge). IE11 requires fallbacks.

When to use CSS Grid generator

Use whenever you need a CSS Grid layout.

  • Creating page layouts with header, sidebar, main content, and footer areas.
  • Designing responsive grid-based card layouts (blog posts, products, image galleries).
  • Building dashboard layouts with multiple panels (charts, tables, widgets).
  • Learning CSS Grid by experimenting with columns, rows, and named areas.
  • Prototyping layouts quickly before implementing in code.
  • Generating grid code for complex layouts (12-column grids, asymmetric layouts).
  • Replacing float or flexbox layouts with modern Grid for better control.

How to use CSS Grid generator

Set columns, rows, gaps, and areas; copy CSS code.

  1. Set number of columns: Choose the number of columns (e.g., 3). Set column sizes using fr units (1fr = one fraction), pixels (200px), percentages (25%), or auto.
  2. Set number of rows: Choose the number of rows. Set row sizes using fr, pixels, auto, or min-content/max-content.
  3. Adjust gaps (gutters): Set grid-gap (spacing between all items), or set column-gap and row-gap separately. Common values: 20px, 1rem, 2%.
  4. Define grid areas (optional): Name grid areas (header, sidebar, main, footer) and assign items to areas using grid-template-areas. Visual editor shows area boundaries.
  5. Preview the grid: See the grid layout rendered in real-time. Add sample content to grid items to visualize the final layout.
  6. Copy CSS code: Click 'Copy CSS' to get the grid container and item CSS. Paste into your stylesheet. HTML structure is also shown.

Key features

  • Column and row configuration: Set columns and rows using fr, px, %, auto, min-content, max-content, or minmax(). Visual editor for track sizes.
  • Gap control: Set grid-gap, column-gap, row-gap. See spacing between items in real-time.
  • Named grid areas: Create grid-template-areas with semantic names (header, sidebar, main). Assign items to areas visually.
  • Fractional units (fr): Use fr units for responsive, fluid layouts. 1fr 2fr 1fr creates columns at 25%, 50%, 25% of container width.
  • Auto-placement: Let Grid auto-place items, or manually assign items to specific grid cells using grid-column and grid-row.
  • Live preview: Real-time rendering of grid layout. See changes instantly as you adjust columns, rows, or gaps.
  • CSS code output: Generates complete CSS for grid container and items. Includes grid-template-columns, grid-template-rows, grid-template-areas, grid-gap.

Common use cases

  • Page layouts: Create classic page layouts with header, sidebar, main content, footer using named grid areas.
  • Card grids: Design responsive card grids (blog posts, products, portfolios) with auto-fit and minmax() for fluid columns.
  • Dashboard layouts: Build multi-panel dashboards with charts, tables, and widgets arranged in a grid.
  • Image galleries: Create grid-based galleries with equal-sized or asymmetric image tiles.
  • Form layouts: Align form labels and inputs using Grid (label in column 1, input in column 2).
  • Learning CSS Grid: Experiment with Grid features (fr units, named areas, spanning) and see CSS output.

Examples

CSS Grid layouts generated by this tool.

Simple 3-column layout

Columns: 1fr 1fr 1fr. Rows: auto. Gap: 20px.
.container { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }

Three equal-width columns. Items auto-place into grid cells. Gap adds 20px spacing between items.

Classic page layout with named areas

3 columns (1fr 2fr 1fr), 3 rows (auto 1fr auto). Areas: header (all columns), sidebar, main, aside, footer (all columns).
.container { display: grid; grid-template-columns: 1fr 2fr 1fr; grid-template-rows: auto 1fr auto; grid-template-areas: 'header header header' 'sidebar main aside' 'footer footer footer'; }

Header and footer span all columns. Main content is wider (2fr) than sidebars (1fr). Semantic area names.

Responsive card grid (auto-fit)

Columns: repeat(auto-fit, minmax(250px, 1fr)). Gap: 20px.
.container { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 20px; }

Columns auto-adjust based on container width. Each column is at least 250px, max 1fr. Perfect for product grids or blog cards.

Dashboard with fixed and flexible tracks

Columns: 200px 1fr 200px. Rows: 60px 1fr 40px.
.container { display: grid; grid-template-columns: 200px 1fr 200px; grid-template-rows: 60px 1fr 40px; }

Fixed-width sidebars (200px), flexible main content (1fr). Fixed-height header (60px) and footer (40px), flexible body (1fr).

12-column grid (Bootstrap-style)

Columns: repeat(12, 1fr). Gap: 15px.
.container { display: grid; grid-template-columns: repeat(12, 1fr); gap: 15px; }

12 equal columns. Items span multiple columns using grid-column: span 6; (half width), span 4; (third width), etc.

Technical reference

CSS Grid syntax and features:

Grid container
display: grid; Creates a grid container. All direct children become grid items.
grid-template-columns
Defines column track sizes. Example: 1fr 2fr 1fr (3 columns: 25%, 50%, 25%). 200px auto 200px (fixed, flexible, fixed).
grid-template-rows
Defines row track sizes. Example: auto 1fr auto (header auto-height, content fills space, footer auto-height).
fr units
Fractional units. 1fr = one fraction of available space. 1fr 1fr = two equal columns. 1fr 2fr = columns at 33%, 67%.
grid-gap (gap)
Spacing between grid items. grid-gap: 20px; (20px all around). column-gap and row-gap for separate control.
grid-template-areas
Named areas for semantic layouts. Example: 'header header' 'sidebar main' 'footer footer'. Assign items with grid-area: header;
minmax()
Sets min and max track size. minmax(200px, 1fr) = at least 200px, up to 1fr of space. Good for responsive layouts.
auto-fit / auto-fill
Creates responsive columns. grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); auto-adjusts column count based on width.
Browser support
All modern browsers (Chrome, Firefox, Safari, Edge). IE11 supports older Grid syntax with -ms- prefix. No IE10 or older.
Comparison to Flexbox
Flexbox is one-dimensional (row or column). Grid is two-dimensional (rows and columns). Use Flexbox for components, Grid for layouts.

Common mistakes to avoid

Using Grid for simple one-dimensional layouts better suited for Flexbox

Why it happens: CSS Grid is designed for two-dimensional layouts (rows and columns). For simple one-dimensional layouts (a horizontal row of buttons, a vertical list), Flexbox is simpler and more appropriate. Using Grid adds unnecessary complexity (defining rows/columns when you only need one dimension). Flexbox has better browser support for old browsers and is more performant for simple layouts.

How to avoid it: Use Flexbox for one-dimensional layouts: navigation bars, button groups, vertical lists. Use Grid for two-dimensional layouts: page layouts with header/sidebar/main/footer, card grids, dashboards. Rule of thumb: if you only set grid-template-columns or grid-template-rows (not both), consider Flexbox instead.

Forgetting to set display: grid on the container, causing grid properties to not work

Why it happens: grid-template-columns, grid-template-rows, and other grid properties only work if the parent element has display: grid. If you forget this, the properties are ignored and items stack vertically (default block layout). This is the most common Grid error for beginners.

How to avoid it: Always set display: grid; on the container element. Example: .container { display: grid; grid-template-columns: 1fr 1fr 1fr; }. Check DevTools to verify the element has display: grid applied.

Using pixel-based column widths for responsive layouts, breaking on small screens

Why it happens: If you set grid-template-columns: 300px 300px 300px; (900px total), the grid overflows on screens smaller than 900px, causing horizontal scroll. Pixel-based grids are not responsive. This is common when designing for desktop only.

How to avoid it: Use fr units, percentages, or minmax() for responsive grids. Example: grid-template-columns: 1fr 1fr 1fr; (always 3 equal columns). Or use auto-fit/auto-fill: repeat(auto-fit, minmax(250px, 1fr)); (columns adjust to screen width). Test on mobile devices.

Misaligning grid-template-areas syntax (inconsistent column count or quotes)

Why it happens: grid-template-areas requires each row to be a quoted string with the same number of area names. If one row has 3 areas and another has 2, or if you forget quotes, the CSS is invalid and the grid breaks. Example: grid-template-areas: 'header header' 'sidebar main footer'; (row 1 has 2 columns, row 2 has 3 — invalid).

How to avoid it: Ensure every row in grid-template-areas has the same number of area names. Use a dot (.) for empty cells. Example: 'header header' 'sidebar main' 'footer footer'; (all rows have 2 columns). Use multi-line strings for readability: grid-template-areas: 'header header' 'sidebar main' 'footer footer';

Not testing Grid layouts in IE11, causing broken layouts for users on older browsers

Why it happens: IE11 supports CSS Grid but uses an older syntax with -ms- prefixes and does not support grid-template-areas, auto-placement, or many modern features. If you use modern Grid syntax without fallbacks, IE11 users see a broken layout. IE11 still has ~1-2% market share in some regions (2026).

How to avoid it: For IE11 support, use Autoprefixer to generate -ms- prefixed CSS. Or provide a Flexbox or float-based fallback using @supports (display: grid) { /* Grid code */ }. Test in IE11 or use BrowserStack. For most modern sites, IE11 support is optional (check your analytics).

Frequently asked questions

What is the difference between CSS Grid and Flexbox?

Flexbox is one-dimensional (row or column). Use for navigation bars, button groups, or lists. Grid is two-dimensional (rows and columns). Use for page layouts, card grids, or dashboards. Grid gives more control over both axes simultaneously. You can use both together (Grid for page layout, Flexbox for components).

What are fr units in CSS Grid?

fr (fractional unit) represents a fraction of the available space in the grid container. 1fr 1fr 1fr creates 3 equal-width columns (each 1/3 of the container). 1fr 2fr creates 2 columns (33% and 67%). fr units are fluid and responsive — they adapt to container width.

How do I create a responsive grid that auto-adjusts columns?

Use repeat(auto-fit, minmax(250px, 1fr)). auto-fit creates as many columns as fit in the container. minmax(250px, 1fr) ensures each column is at least 250px wide, up to 1fr. Example: grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); Columns auto-adjust based on screen width.

What is grid-template-areas and when should I use it?

grid-template-areas lets you name grid areas (header, sidebar, main) and assign items to areas using grid-area: header;. Use for semantic, maintainable layouts. Example: grid-template-areas: 'header header' 'sidebar main' 'footer footer'; Items assigned with grid-area: header; automatically span the correct cells.

How do I create gaps (gutters) between grid items?

Use gap: 20px; (sets both row and column gaps). Or use column-gap: 20px; row-gap: 10px; separately. The gap property is the modern syntax (old syntax: grid-gap). Gaps add spacing between items but not on outer edges.

Can I use CSS Grid in all browsers?

All modern browsers (Chrome, Firefox, Safari, Edge) support CSS Grid. IE11 supports Grid with older -ms- prefix syntax (limited features). IE10 and older do not support Grid. For broad compatibility, use Autoprefixer or provide Flexbox fallbacks. Check caniuse.com for detailed support.

How do I make a grid item span multiple columns or rows?

Use grid-column: span 2; (span 2 columns) or grid-column: 1 / 3; (start at line 1, end at line 3). For rows: grid-row: span 2; or grid-row: 1 / 4;. Example: .item { grid-column: span 2; } makes the item twice as wide.

References

Privacy and availability

  • Runs entirely in your browser — zero server processing
  • No signup or account required
  • Works offline once loaded
  • Fast, lightweight, no external dependencies
  • Available as a browser extension for Chrome and Firefox