Published: April 2026 · 11 min read · Design Tools
CSS Grid is the most powerful layout system in CSS. It gives you precise control over both rows and columns simultaneously, making it possible to build complex page layouts that would have required JavaScript or hacks just a few years ago. Combined with a visual CSS grid generator, you can design entire page structures by clicking and dragging — no mental math required.
This guide covers everything from Grid fundamentals to advanced patterns, with practical examples and a clear comparison against Flexbox so you know exactly when to use each.
CSS Grid Layout is a two-dimensional layout system that divides a container into rows and columns, letting you place items at precise intersections. Unlike Flexbox, which handles one axis at a time, Grid controls both axes simultaneously — making it perfect for page-level layouts.
At its core, Grid transforms a container into a coordinate system. You define the grid structure (how many rows and columns, their sizes), then place items into specific cells, span them across multiple cells, or let the auto-placement algorithm handle it.
.grid-container { display: grid; grid-template-columns: 250px 1fr 1fr; /* 3 columns */ grid-template-rows: auto 1fr auto; /* 3 rows */ gap: 1rem; /* Space between cells */ }
The fr unit represents a fraction of available space. It's Grid's superpower:
fr
.grid { grid-template-columns: 1fr 2fr 1fr; /* Column 2 is twice as wide as columns 1 and 3 */ /* Total: 4fr, so column 1 = 25%, column 2 = 50%, column 3 = 25% */ }
Create repetitive patterns efficiently:
.grid { grid-template-columns: repeat(3, 1fr); /* 3 equal columns */ grid-template-columns: repeat(4, minmax(200px, 1fr)); /* 4 columns, min 200px */ }
The most readable way to define page layouts:
.page { display: grid; grid-template-areas: "header header header" "sidebar content content" "footer footer footer"; grid-template-columns: 250px 1fr 1fr; grid-template-rows: auto 1fr auto; min-height: 100vh; gap: 1rem; } .header { grid-area: header; } .sidebar { grid-area: sidebar; } .content { grid-area: content; } .footer { grid-area: footer; }
Create responsive grids without media queries:
.responsive-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1.5rem; } /* Automatically adjusts column count based on available width */
Place items precisely using line numbers:
.featured { grid-column: 1 / 3; /* Span columns 1 through 2 */ grid-row: 1 / 3; /* Span rows 1 through 2 */ } /* Shorthand: grid-area: row-start / col-start / row-end / col-end */ .hero { grid-area: 1 / 1 / 3 / 4; /* Full-width hero spanning 2 rows */ }
.dashboard { display: grid; grid-template-columns: 260px 1fr; grid-template-rows: 64px 1fr; grid-template-areas: "sidebar header" "sidebar main"; height: 100vh; } .dash-header { grid-area: header; } .dash-sidebar { grid-area: sidebar; } .dash-main { grid-area: main; }
.magazine { display: grid; grid-template-columns: 2fr 1fr; grid-template-rows: auto auto auto; gap: 2rem; } .featured-post { grid-column: 1 / -1; } /* Full width */ .post-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1.5rem; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 0.5rem; } .gallery img { width: 100%; height: 250px; object-fit: cover; border-radius: 8px; }
.holy-grail { display: grid; grid-template: "header header header" auto "nav main aside" 1fr "footer footer footer" auto / 200px 1fr 200px; min-height: 100vh; gap: 1rem; }
A CSS grid generator lets you build layouts visually instead of writing code by hand. Here's the typical workflow:
Generators are especially useful for learning Grid properties. By adjusting values visually and seeing the corresponding CSS update in real time, you develop an intuition for how Grid works much faster than reading documentation alone.
grid-template-columns: [start] 1fr [mid] 2fr [end]
minmax(auto, 1fr)
grid-auto-flow: dense
aspect-ratio
CSS Grid is supported by 96%+ of browsers globally, including all modern versions of Chrome, Firefox, Safari, and Edge. Subgrid has slightly lower support (89%+) but is rapidly increasing. For production use, Grid is safe to use without fallbacks in most contexts.
CSS Grid is a two-dimensional layout system that controls both rows and columns simultaneously, making it ideal for page-level layouts. Flexbox is one-dimensional, handling either a row or a column at a time, making it better for component-level layouts. Use Grid when you need precise control over a 2D structure (like a dashboard with header, sidebar, and content areas). Use Flexbox for aligning items within a single direction (like a row of navigation links or centering a card's content).
Use the repeat() function with auto-fill or auto-fit combined with minmax() for responsive grids without media queries. Example: grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)). This automatically creates as many columns as will fit in the available space, each at least 300px wide, and they stretch equally to fill remaining space. As the viewport narrows, columns drop to fewer per row automatically.
repeat()
auto-fill
auto-fit
minmax()
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr))
grid-template-areas lets you name regions of your grid and place items using readable string labels. Example: grid-template-areas: "header header" "sidebar main" "footer footer". Items reference areas with grid-area: "header". Use it for page layouts where the structure is well-defined and you want readable, maintainable code. It's the most visual way to express grid layouts in pure CSS.
grid-template-areas
grid-template-areas: "header header" "sidebar main" "footer footer"
grid-area: "header"
Yes. Modern CSS grid generators produce clean, standards-compliant CSS that's ready for production. Use them to prototype layouts visually, understand Grid properties interactively, and generate boilerplate code you can further customize. The generated code uses standard CSS Grid properties — no vendor prefixes, no JavaScript dependencies, no build tools required. Simply copy and paste into your stylesheet.
Visual Flexbox builder with real-time preview for one-dimensional layouts.
Design stunning gradients with a visual editor and get production-ready CSS.
Create multi-layered box shadows with a visual editor for depth and elevation.
← Back to Blog