CSS Grid Generator
Adjust grid-template-columns/rows, justify-items, align-items, and gap with an interactive GUI and preview real CSS Grid layouts live. Copy the generated CSS with one click.
Tips
- The fr unit in grid-template-columns: repeat(3, 1fr) represents a share of the remaining space, so column ratios stay fixed even as the viewport width changes.
- The gap property only affects the spacing between rows and columns, unlike margin, which also affects the outside of the grid. You can also set row-gap and column-gap independently.
- Tracks set to "auto" size themselves to fit their content, which is handy for columns or rows whose content length is unpredictable.
- Overriding grid-column: span 2 on a single item lets you stretch just a header or footer across the full width of the grid.
- Reach for Grid when you need a full two-dimensional layout, and Flexbox when a single row or column of items is enough (see our CSS Flexbox generator too).
Frequently Asked Questions
Side Note — CSS Grid's Pursuit of a "Second Dimension" That Flexbox Doesn't Cover
CSS Grid Layout was designed as a two-dimensional layout system that lets you define rows and columns at the same time, in contrast to Flexbox, which focuses on laying items out in a single direction. Standardization at the W3C began around 2011, and once Chrome, Firefox, Safari, and Edge all shipped support together in 2017, adoption in real-world projects took off quickly.
Before Grid existed, arranging a page into the classic "holy grail" structure of a header, sidebar, main content, and footer required convoluted workarounds built on floats or table markup. CSS Grid introduced declarative properties such as grid-template-columns, grid-template-rows, and grid-template-areas that let developers recreate this familiar layout in just a handful of lines of CSS.
Today, much of the design work behind dashboard UIs, image galleries, and magazine-style layouts that revolve around rows and columns is built with CSS Grid. Support for "subgrid," which lets a nested grid inherit its parent's track sizing, has also spread across major browsers, making it easier to keep complex, multi-level layouts consistent.
In practice, a common convention has emerged where Grid handles the overall page skeleton and Flexbox handles the arrangement of elements inside individual components. The two aren't competitors — they're complementary tools, each suited to a different strength (one-dimensional alignment versus two-dimensional grid placement), and combining both within a single page is considered standard practice.