Skip to main content

CSS Grid Generator

Columns 3 tracks
Rows 3 tracks
Gap
Column Gap
Row Gap
Alignment
justify-items
align-items
justify-content
align-content
Auto Flow & Implicit Tracks
grid-auto-flow
grid-auto-columns
grid-auto-rows
Selected Item
Click any item in the preview to edit its properties
grid-template-areas

Each quoted string = one row. Use . for empty cells.

Assign the same name to an item's grid-area field in the Items tab.

Area Map

Generated Code

Advertisement

Two Axes, Explicit Lines, and Clean Grid Markup

For years, building a sidebar alongside a sticky header and asymmetric bento cards meant nesting wrapper divs inside Flexbox containers or wrestling with fragile margin math. CSS Grid lets a single container govern columns and rows at the same time, keeping HTML flat and readable. Still, remembering whether line numbers count tracks or edges, or keeping quotes aligned inside grid-template-areas, slows down quick prototyping.

This visual builder lets you define column and row tracks, toggle viewport widths, inspect live track line numbers, assign spans or named areas in the Items and Areas tabs, configure subgrid nesting, and copy finished CSS, HTML, or nested SCSS straight into your project (or download a standalone starter HTML file). Everything runs locally inside your browser tab.

Three Ways to Place Items in CSS Grid

Open the Presets menu at the top and compare Bento Grid, Holy Grail, and Subgrid Demo. Each showcases a different CSS Grid placement strategy available in the editor:

1. Line Numbers and Negative End Spans

Turn on the Line Numbers toggle above the canvas and look at the blue and purple numbers along the top and left edges. A 3 column grid has 4 vertical line numbers (always tracks + 1), because lines mark the borders around tracks rather than the cells themselves. To make a hero tile span the first two columns, click the item in the preview, enter 1 for col-start and 3 (or click span 2) for col-end. Clicking the to end button sets col-end to -1, which always stretches an item cleanly to the final explicit grid line on the right, even if you add more columns later.

2. Named Template Areas

For full page shells (header, sidebar, main panel, footer), numeric coordinates feel cryptic six months later. Switch to the Areas tab and write visual ASCII rows using quoted strings such as "header header header" on row one and "nav main aside" on row two. Use a single period (.) wherever you want an empty cell. Two strict rules apply in CSS: every row must list the exact same number of columns, and every named region must form an unbroken rectangle (L shaped areas invalidate the entire grid-template-areas rule in browsers). Once defined, enter that area name inside an item's grid-area field to snap it into place.

3. Aligning Nested Cards With Subgrid

Ever placed three pricing or product cards in a row, only to see one card's button sit lower than its neighbors because its heading wrapped onto two lines? Normally, children inside a card only see the card's own dimensions, not the tracks of the outer row. Enabling grid-template-columns: subgrid or grid-template-rows: subgrid inside the Items panel turns a spanning grid item into a grid that inherits its parent's track lines directly, keeping card titles, descriptions, and footer buttons aligned across every column.

Choosing Track Sizing: fr, minmax(), auto-fit, and auto-fill

Click the quick preset chips beneath Columns in the Grid panel and you will spot five common track definitions. Knowing how they behave when screen width changes prevents broken card rows:

  • 1fr: Allocates one share of remaining free space after fixed widths (such as a 220px sidebar) and gap gutters are subtracted.
  • auto: Sizes the track around its content width or height, expanding as text grows.
  • minmax(150px, 1fr): Sets a hard lower floor of 150px while letting the column stretch evenly when space permits.
  • repeat(auto-fit, minmax(200px, 1fr)) vs repeat(auto-fill, minmax(150px, 1fr)): Both pack as many columns as fit cleanly into the container and wrap extras onto new rows without media queries. The subtle difference appears when you only have two cards inside a 1,200px container: auto-fit collapses empty phantom tracks to zero width so your two cards stretch to fill the row, whereas auto-fill keeps the invisible empty tracks reserved so your two cards stay at their compact width on the left.

One detail also surprises newcomers to CSS gap: both column-gap and row-gap add spacing strictly between adjacent tracks, never along the outer perimeter of the container. Add container padding separately whenever cards need breathing room against screen edges.

CSS Layout Bug Fix

Why Code Blocks and Long URLs Blow Out 1fr Tracks

Suppose you build a two column layout with grid-template-columns: 240px 1fr; and drop a wide <pre> code snippet or an unbroken URL inside the main column. Suddenly the whole page develops a horizontal scrollbar even though 1fr sounds flexible.

/* Expands past viewport when child content is wide */

.layout { display: grid; grid-template-columns: 240px 1fr; }

/* Allows track to shrink below min-content width */

.layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); }

In the CSS Grid specification, bare 1fr actually means minmax(auto, 1fr), so the track refuses to shrink narrower than its largest unbreakable child element. Writing minmax(0, 1fr) lowers that minimum to zero so overflow scrollbars, word-break, and text-overflow: ellipsis inside the column work as expected.

CSS Grid Layout FAQs

Q: When should I use CSS Grid instead of Flexbox?

Reach for CSS Grid when you want two dimensional control across both rows and columns at once (page shells, dashboards, bento grids, card matrices). Choose Flexbox for one dimensional layout along a single row or column (button groups, navbars, form rows) where items wrap based on their own content size.

Q: What does the 'fr' (fractional) unit mean in CSS Grid?

An fr unit represents a fraction of remaining free space inside the grid container after fixed pixel tracks, auto tracks, and gaps are allocated. A 2fr column receives twice as much leftover space as a 1fr column.

Q: Is CSS Grid supported across all modern browsers?

Yes. Core CSS Grid is supported across Chrome, Edge, Firefox, Safari, and mobile iOS and Android browsers worldwide. Subgrid (grid-template-columns: subgrid) is also supported in current versions of Chrome, Edge, Firefox, and Safari.

Q: How do I make my generated CSS Grid responsive on mobile screens?

Either use a fluid pattern like repeat(auto-fit, minmax(220px, 1fr)) for card grids, or start with a single column grid-template-columns: 1fr; by default and apply your multi column track definitions and grid-template-areas inside a @media (min-width: 768px) breakpoint. Test widths with the Viewport buttons above the preview before exporting.

Q: Can grid items overlap each other in CSS Grid?

Yes. Assigning two items to overlapping row and column line ranges places them in the same cells without needing position: absolute, and standard z-index rules control which item paints on top.

Related Frontend & CSS Utilities