ShareYourGroupShareYourGroupCSS Lab

CSS grid generator

Grid lays items out in rows and columns at once. Start with columns and gap, and add the rest if you need it.

What the output means

auto-fit and auto-fill

Both repeat columns as long as they fit. The difference shows when there are few items: auto-fill keeps the empty columns, so the items stay at their minimum width, while auto-fit collapses the empty columns and stretches the items to fill the row. The tool uses auto-fit. Choose auto-fill by editing the word if you want items that never grow beyond a column.

Common mistakes

  1. A minmax minimum larger than the screen. On a 320 pixel phone a column of at least 400 pixels causes sideways scrolling. Use min(100%, 300px) inside minmax if you need large minimums.
  2. Writing 1fr columns with long unbreakable text, which can stretch the column. Add min-width: 0 to the item or use minmax(0, 1fr).
  3. Using grid for a single row of buttons, where flexbox is simpler.
When should I use grid and when flexbox?

Use grid when you think in rows and columns together, and flexbox when you think in one line. See the comparison page.

Can items span more than one cell?

Yes. On an item write grid-column: span 2;. The generator does not draw that, but the guide shows it.

This is an independent site. It is not connected with the W3C, MDN, Google, Apple, Mozilla or Microsoft. Browser and product names belong to their owners.