CSS

CSS Grid Generator

Details

How to use CSS Grid Generator

What the tool does, how to run it, and what to expect from the result.

How to generate a CSS grid layout

CSS grid lays out children in rows and columns defined on the parent. Three properties do most of the work: display: grid, grid-template-columns to define the tracks, and gap to space them, and the children need no styling at all to fall into place.

The preview places real items in a live grid, so what you see is what your browser will render. Copy the declaration, then adapt the column definition for responsiveness.

  • Set the number of columns and rows, and watch the preview place items into the tracks.
  • Set the gap, which spaces the tracks without adding any margin at the outer edges.
  • Copy the generated declaration onto the parent element. The children need nothing.
  • Swap repeat(N, 1fr) for repeat(auto-fit, minmax(200px, 1fr)) so the grid reflows on narrow screens without media queries.
  • Change 1fr to minmax(0, 1fr) if a long word or a wide image is making the grid overflow its container.
Tips

Getting a better result out of CSS Grid Generator

Specific settings and thresholds, not general advice.

  • repeat(3, 1fr) is not responsive. It stays three columns at 320 pixels wide, squeezing each one to about 100 pixels. The idiom that actually adapts is repeat(auto-fit, minmax(200px, 1fr)), which fits as many 200-pixel-minimum columns as will go and reflows on its own with no media queries at all.
  • 1fr does not mean what most people think. A grid track sized 1fr will refuse to shrink below the intrinsic minimum width of its content, so one long unbroken string or a wide image blows the column out and the whole grid overflows. The fix is minmax(0, 1fr), which permits the track to shrink, and it is the single most useful piece of grid knowledge there is.
  • Declaring explicit rows is usually unnecessary. Grid creates implicit rows automatically as items are placed, so grid-template-rows is only needed when you want to control their size. Fixing the row count means an extra item silently lands in an unstyled implicit row.
  • gap replaced margins for grid spacing, and it is better in every respect: it never adds space at the outer edges, so there is no last-child margin rule to write and no negative-margin wrapper hack.
  • auto-fit and auto-fill look identical until the row is not full. auto-fit collapses the empty tracks so the existing items stretch to fill the row, while auto-fill keeps them, leaving a gap on the right. Pick auto-fit when you want items to expand, auto-fill when you want a consistent column width.
Limits

What CSS Grid Generator does not do

The honest boundary, so you do not lose time finding it yourself.

  • It generates equal-width columns via repeat with 1fr, so it cannot produce mixed tracks such as 2fr 1fr, fixed sidebars, or minmax constraints.
  • It does not generate the auto-fit or auto-fill patterns, which is what makes a grid responsive without media queries.
  • It does not support named grid areas, grid-template-areas, or per-item placement with grid-column and grid-row.
  • It emits no media queries, so the column count is fixed at every screen size.
At a glance

Who CSS Grid Generator is for

A quick way to understand who this helps, what it solves, and where it connects next.

Best fit

Frontend developers, designers, and anyone styling web pages.

Ideal for

Quickly building grid CSS visually without writing it by hand.

FAQ

Common questions

Short answers for the questions people usually have before trying a utility like this.

Is the CSS grid generator free?

Yes. It is completely free to use, with no signup, no account, and no paywall.

Can I use the generated CSS in commercial projects?

Yes. The CSS you copy from the tool is yours to use in any project, personal or commercial, with no attribution needed.

Does it stay local?

Yes. Everything runs in your browser, and nothing you configure is uploaded to a server.

How do I make this grid responsive?

Replace the fixed column count with an intrinsic one. Instead of repeat(3, 1fr), which is always three columns however narrow the screen gets, write repeat(auto-fit, minmax(200px, 1fr)). That tells the browser to fit as many columns as it can while keeping each at least 200 pixels wide, and to share the leftover space between them. The grid then goes from three columns to two to one entirely on its own, with no breakpoints and no media queries. It is the single most useful pattern in CSS grid.

My grid is overflowing its container. Why?

Because 1fr has a minimum size of auto, which means the track will not shrink below the intrinsic width of whatever is inside it. A long URL with no spaces, a wide image, or a table will force the column to be at least as wide as that content, and the grid overflows to the right. Change the track to minmax(0, 1fr), which sets the minimum to zero and lets the column shrink properly. This trips up nearly everyone at some point and the fix is almost always this.

What is the difference between auto-fit and auto-fill?

It only shows when there are fewer items than would fill a row. auto-fill keeps creating empty tracks to fill the available width, so four items in a six-column-capable grid leave two empty columns and the items stay narrow. auto-fit collapses those empty tracks to zero width, so the four items stretch to share the whole row. If you want cards to grow to fill the space, use auto-fit. If you want a consistent column rhythm even when the last row is short, use auto-fill.

Do I need to declare grid-template-rows?

Usually not. Grid generates implicit rows as it needs them, so if you define three columns and give it ten items, you automatically get four rows without saying anything. Declaring an explicit row count is only useful when you want to control those rows' heights. It also introduces a trap: if you fix the grid at two rows and a seventh item appears, it lands in an implicit row that none of your sizing applies to.

Grid or flexbox?

Grid when you are laying out in two dimensions and you want the tracks to control the items, which is the case for card galleries, dashboards, and page layouts. Flexbox when you are laying out along one axis and you want the items to control their own sizes, which is the case for toolbars, button rows, and navigation. The honest heuristic: if you are writing the same width on every child to make them line up, you wanted grid.

Recommendations

You Might Also Like

Nearby tools from the catalog that fit the same job or workflow.

Cleanor app

Do it all on your device

Cleanor puts these tools in one app: compress and convert images, video, and audio, work with PDFs, and scan text right on your device. Plus free up storage and clear inbox clutter with Email Cleaner. Start with a free trial.

  • iPhone
  • Android
  • Macsoon
  • Windowssoon