Frontend Tools
CSS Grid Generator
Generate responsive CSS grid code with auto-fit or auto-fill, a minimum column width, a column limit and gaps, or a fixed column layout, with a live preview.
How to use CSS Grid Generator
Choose a responsive auto-fit or auto-fill layout or a fixed number of columns, then set the minimum column width, maximum columns, row and column gaps and the container selector. Copy the CSS shown under the preview.
- Choose the layoutPick auto-fit to stretch items, auto-fill to keep empty tracks, or a fixed number of columns.
- Set columns, width and gapsEnter the maximum columns (0 for no limit), the minimum column width and the row and column gaps.
- Preview and copyChange the number of preview items to test wrapping, then copy the CSS for your container selector.
What the generated template does
The defaults, auto-fit with up to 4 columns, a 220px minimum width and 16px gaps, give grid-template-columns: repeat(auto-fit, minmax(min(100%, max(220px, (100% - 48px) / 4)), 1fr)). The max() part raises the minimum track width to a quarter of the space left after three 16px gaps, so no more than four columns ever fit. The table shows when each count kicks in: 2 columns from 456px, 3 from 692px and 4 from 928px. min(…, 100%) stops a single column overflowing a container narrower than 220px.
auto-fit, auto-fill and fixed columns
Both auto-fit and auto-fill create as many tracks as will fit. With only a few items, auto-fit collapses the empty tracks so the items stretch across the row, while auto-fill keeps the empty tracks and the items stay at their column width. A fixed layout outputs repeat(3, minmax(0, 1fr)), equal columns that long content can't push wider, but they won't wrap on small screens either, so pair them with media queries. When the row and column gaps match you get gap: 16px; otherwise gap lists the row gap, then the column gap.
Accuracy and data handling
After adding generated code to a project, test it in the target browsers and responsive sizes. The calculation runs in your current browser; the tool code does not send the input to a processing API.
FAQ
What does 1fr mean in grid-template-columns?
fr is a share of the free space. minmax(220px, 1fr) means a column is at least 220px wide and otherwise takes an equal share of what's left, so all the columns grow evenly.
What's the difference between auto-fit and auto-fill?
Both fit as many columns as the container allows. With few items, auto-fit collapses the empty columns and stretches the items, while auto-fill keeps the empty tracks so the items don't widen.
How do I limit a responsive grid to a maximum number of columns?
Enter the maximum in Columns. The code uses max() to raise the minimum column width to 1/N of the container minus the gaps, so a wide screen never fits more than N columns.
More Frontend Tools
Related toolsShrink HTML by removing comments and spare whitespace, with the byte saving shown.
Strip comments and whitespace from JavaScript safely, with the size saving shown.
Indent messy or minified HTML into readable, nested lines, including inline CSS and JS.
Unminify CSS into tidy, indented rules with one declaration per line.
Reformat compressed JavaScript into indented, readable code without touching strings.
Convert between px, rem, em, % and pt using your own root and parent font sizes.