A CSS grid generator writes the layout code for a grid container. Enter the number of columns and rows, choose how the tracks are sized (equal fractions, fixed pixels, content or responsive auto-fit) and set the gaps. A live preview shows the result, with CSS and HTML to copy.
How to use the CSS Grid Generator
- Set columns and rowsEnter how many columns and rows the grid should have, from 1 to 12 each.
- Choose track sizesPick equal shares, fixed sizes, content-sized tracks or the responsive auto-fit option.
- Set the gapsDrag the column gap and row gap sliders. The numbered preview updates as you go.
- Copy the codeCopy the CSS for the container and the matching HTML structure.
The grid properties this tool writes
CSS Grid lays out the direct children of a container in rows and columns. The CSS grid generator uses the handful of properties that cover most layouts:
- display: grid turns the element into a grid container.
- grid-template-columns defines the column tracks.
repeat(3, 1fr)means three columns that share the free space equally. - grid-template-rows defines the row tracks. If rows should simply be as tall as their content (auto), the line is left out, because that is the default.
- gap sets the space between tracks. One value applies to both directions; two values mean row gap first, then column gap.
The fr unit is a fraction of the space left after gaps and fixed tracks are subtracted. A plain 1fr column will not shrink below the width of its content, so a long word or wide image can push the grid wider than its container. minmax(0, 1fr) removes that minimum and is the safer choice for content you do not control.
Responsive grids without media queries
Choose the Responsive column option to get repeat(auto-fit, minmax(200px, 1fr)). It tells the browser: make as many columns as fit, each at least 200 px wide, and share any leftover space between them. On a wide screen you might get five columns, on a tablet three and on a phone one, with no breakpoints to maintain. It is ideal for card lists, galleries and product grids.
- auto-fit stretches the existing items to fill the row.
- auto-fill (a one-word change) keeps empty column slots, so a single item does not stretch across the whole row.
Grid or flexbox? Use grid when you are controlling rows and columns together; use flexbox for a single row or column of items, such as a toolbar. They combine well: a grid for the page, flexbox inside each cell.
For consistent spacing, set gaps in rem with the PX to REM converter, and tidy your style sheet with the CSS formatter.
Frequently asked questions
How do I create a 3-column grid in CSS?
Set display: grid and grid-template-columns: repeat(3, 1fr) on the container, then add a gap. The CSS grid generator writes this from the numbers you enter.
What does 1fr mean?
One fraction of the free space in the grid container. Three columns of 1fr each take a third of the space left after gaps and fixed tracks.
How do I make a grid responsive?
Use grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)). The number of columns then adapts to the available width without media queries.
What is the difference between gap and margin?
gap adds space only between grid tracks, not around the outside edge, so you do not need to cancel margins on the first or last items.
Why does my grid overflow its container?
A 1fr track cannot become narrower than its content. Use minmax(0, 1fr) and allow long text to wrap or images to shrink with max-width: 100%.
Last updated 24 November 2026 by the TheTechFolk team.