Map Extract
Free tool

CSS grid generator

Lay out cards, team photos or service tiles in neat rows and columns. Choose a fixed number of columns or let them wrap on smaller screens, then copy the grid CSS.

Runs in your browser. Nothing you enter is uploaded.

Generating a grid

  1. Set columns and rows

    Type the number of columns and rows. Each column becomes an equal fraction of the width (1fr).

  2. Or make it responsive

    Fill in Responsive: minimum column width (px) and the fixed column and row settings are replaced by an automatic layout.

  3. Set the gaps

    Enter the column gap and row gap in pixels.

  4. Preview and copy

    Change Items in preview to see how up to 24 boxes fill the grid, then copy the .grid rule or download grid.css.

Example: a services page that works on phones

A web designer is laying out nine service tiles for an electrician's website. With 3 columns, 2 rows and 16 px gaps the tool produces the first rule, which suits a desktop but squeezes tiles on a phone.

Typing 240 into the responsive box produces the second rule. On a wide screen several tiles sit side by side; on a narrow phone the layout drops to a single column automatically.

Input
Columns 3, rows 2, gaps 16; then responsive minimum width 240
Result
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(2, auto);

Responsive:
grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));

Grid terms in the output

fr
A fraction of the free space. Three columns of 1fr share the width equally.
repeat()
Shorthand for repeating a track size, so repeat(3, 1fr) means 1fr 1fr 1fr.
auto-fill
Creates as many columns as fit in the container at the given size.
minmax()
Sets a smallest and largest size for each column; here at least your minimum width and at most an equal share.
column-gap and row-gap
The space between columns and between rows, without space at the outer edges.

Questions people ask

How do I make a responsive grid without media queries?

Use grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)). Each column is at least 240 pixels wide and the browser fits as many as there is room for, so the layout goes from several columns on a laptop to one on a phone. Type a minimum width here to generate it.

Should I use grid or flexbox?

Grid suits layouts in two directions, where rows and columns line up, such as a gallery or a card grid. Flexbox suits a single row or column whose items size themselves, such as a navigation bar. Many pages use grid for the overall layout and flexbox inside each card.

Why are my grid rows different heights?

The rows generated here are auto, so each row is as tall as its tallest item, and the other items in that row stretch to match it. To make every row the same height across the whole grid, replace the grid-template-rows line with grid-auto-rows: 1fr in your stylesheet.

Where your data goes

The preview and the CSS are generated in your browser. Nothing you enter is uploaded.

Checked against the tool on

Top