Frontend ToolsA little help for every day

Search by name or task, such as JSON or percentage.

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.

View all tools
ResultUpdates as you type
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, max(220px, (100% - 48px) / 4)), 1fr));
  gap: 16px;
}
ColumnsContainer width
1Any width
2≥ 456px
3≥ 692px
4≥ 928px

auto-fit collapses empty tracks, so a few items stretch across the row; min(…, 100%) stops overflow in narrow containers.

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.

  1. Choose the layoutPick auto-fit to stretch items, auto-fill to keep empty tracks, or a fixed number of columns.
  2. Set columns, width and gapsEnter the maximum columns (0 for no limit), the minimum column width and the row and column gaps.
  3. 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.

Often Used Together

Next step

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 tools