What Is CSS Grid?
CSS Grid Layout is a two-dimensional layout system that lets you arrange content in rows and columns simultaneously. Unlike Flexbox (which is one-dimensional), Grid excels at page-level layouts: defining header, sidebar, main content, and footer areas that all align precisely on both axes.
Key Grid concepts:
- Grid container: The parent element with
display: grid. - Grid tracks: The rows and columns defined by
grid-template-rowsandgrid-template-columns. - Grid cells: The individual intersections of rows and columns.
- Grid areas: Named regions that span multiple cells, defined with
grid-template-areas. - fr unit: Fractional unit that distributes remaining space proportionally.
How to Use the CSS Grid Generator Online
- Open the CSS grid generator at DevKits.
- Set column tracks: specify the number of columns and their sizes (px, %, fr, auto, minmax).
- Set row tracks: specify row heights similarly.
- Drag to create grid areas: select cells and assign area names (header, sidebar, main, footer).
- Set gap values for column and row spacing.
- Copy the complete CSS for container and each named area.
Essential Grid CSS Syntax
.container {
display: grid;
grid-template-columns: 250px 1fr; /* fixed sidebar + flexible main */
grid-template-rows: 60px 1fr 60px; /* header + content + footer */
grid-template-areas:
"header header"
"sidebar main"
"footer footer";
gap: 1rem;
}
.header { grid-area: header; }
.sidebar { grid-area: sidebar; }
.main { grid-area: main; }
.footer { grid-area: footer; }
Key Features
- Visual grid canvas: click-and-drag to create and resize grid areas.
- Track size controls: set each column and row size with px, %, fr, auto, minmax().
- Named area assignment: type area names and see the grid-template-areas syntax generate.
- Gap controls: set row-gap and column-gap independently.
- Responsive helpers: auto-fill and auto-fit repeat() patterns for responsive grids.
- Complete CSS output: container + all grid-area child selectors.
Common Grid Patterns
Responsive Card Grid (auto-fill)
.grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
gap: 1.5rem;
}
Classic Page Layout
.page {
display: grid;
grid-template-columns: 240px 1fr;
grid-template-rows: 60px 1fr;
min-height: 100vh;
}
aiforeverthing.com — Visual grid builder, no signup
Frequently Asked Questions
What is the fr unit in CSS Grid?
The fr (fraction) unit represents a fraction of the available space in the grid container. 1fr 2fr creates two columns where the second is twice as wide as the first. 1fr 1fr 1fr is equivalent to three equal columns.
What is the difference between auto-fill and auto-fit?
Both create as many columns as will fit in the container. The difference: auto-fill keeps empty columns in the track, while auto-fit collapses empty columns, allowing items to grow and fill all available space. Use auto-fit for stretching cards to fill a row.
Can CSS Grid and Flexbox be used together?
Yes and they complement each other perfectly. Use Grid for the page/section layout, then Flexbox for the components within each grid area. A typical pattern: Grid defines the page structure, Flexbox arranges items within a card component.
What is the subgrid feature?
CSS Subgrid (grid-template-columns: subgrid) allows a grid item that spans multiple columns to align its own children to the parent grid's tracks. This solves alignment problems with nested grids and is supported in all modern browsers.
Is the tool free?
Yes, completely free with no signup required.
Recommended Hosting for Developers
- Hostinger — From $2.99/mo. Excellent for static sites and Node.js apps.
- DigitalOcean — $200 free credit for new accounts. Best for scalable backends.
- Namecheap — Budget-friendly shared hosting with free domain.