CSS Grid Generator

Choose columns, rows and gap and copy ready-made CSS Grid code.

How to Use CSS Grid Generator

  1. Set Columns and Rows (1 to 12 each).
  2. Set the gap between cells.
  3. Check the numbered preview.
  4. Copy the CSS and add the class grid-container to your wrapper element.

What the code does

The output sets display: grid, then grid-template-columns: repeat(3, 1fr) and the same for rows. 1fr means one share of the free space, so every column gets the same width. gap adds space between cells but not around the outside edge. Rows set to 1fr share the container's height, so they only stretch if the container has a height; otherwise each row is as tall as its content.

Children of the container fill the cells in order, left to right and then down, without needing any CSS of their own.

Making it responsive

A fixed number of columns can be too many on a phone. A popular next step is grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)), which fits as many columns of at least 200px as there's room for. You can also change the column count inside a media query.

Key Features & Practical Use Cases

  • Image galleries and product listings with equal columns.
  • Dashboard tiles and card layouts.
  • Quickly starting a layout before fine-tuning it by hand.
  • Learning how grid-template-columns and gap work.

Frequently Asked Questions

What does 1fr mean?

One fraction of the available space. Three columns of 1fr each take a third of the width.

Should I use Grid or Flexbox?

Grid for two-dimensional layouts with rows and columns, Flexbox for lining items up in one direction. Try the Flexbox Generator for that.

Can items span several cells?

Yes, with grid-column: span 2 on the item, though this tool doesn't set that.

Does CSS Grid work in all browsers?

Yes. Every current browser supports it.

About OneClickly

OneClickly is a set of 119 free tools for PDFs, images, text, everyday math and code. They run in your browser, so the files and text you work with stay on your device.

Related Tools