FormatterHQ

CSS Grid Generator

Set up a CSS grid with a fixed column count or responsive auto-fit/auto-fill columns, adjust rows, gaps and alignment, and copy the CSS and HTML.

Loading tool…
Ready.

How to use the CSS Grid Generator

  1. Choose Columns: Fixed count (set Column count and Column size) or Responsive auto-fit / auto-fill (set a Minimum column width).
  2. Optionally set a Row count (0 keeps rows implicit) and a Row size such as auto, 120px or minmax(100px, auto).
  3. Adjust Column gap, Row gap and Number of items, and pick justify-items and align-items.
  4. Copy the CSS or HTML with Copy or Download, or use Copy CSS + HTML and Download HTML demo. Reset restores the defaults.

A CSS grid generator for fixed and responsive layouts

CSS Grid places items in rows and columns at the same time, which makes it the natural tool for card galleries, dashboards and page layouts. This CSS grid generator builds the container rule for you: pick a fixed number of columns or a responsive pattern, set gaps and alignment, and watch numbered items fill a live grid before you copy the CSS and HTML.

Example output

The defaults create three equal columns with a 16px gap:

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

Switching to Responsive auto-fit with a 220px minimum width and different gaps gives a layout that needs no media queries:

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px 24px;
}

When the gaps differ, the shorthand lists the row gap first and the column gap second. The HTML tab contains the container with one <div> per item.

Options explained

Fixed columns

Column count (1 to 12) and Column size become repeat(count, size). The size field accepts any track size: 1fr for equal shares, 200px for fixed widths, or minmax(0, 1fr). The fr unit divides the free space after fixed tracks and gaps are subtracted.

auto-fit vs auto-fill

Both create as many columns as fit, each at least the minimum width. The difference shows when there are fewer items than columns:

  • auto-fit collapses the empty tracks, so the existing items stretch to fill the row.
  • auto-fill keeps the empty tracks, so items stay at column width and leave space at the end.

Set Number of items to 2 on a wide screen to see it in the preview. Use auto-fit when a few cards should fill the width, and auto-fill when cards should keep a consistent size.

Rows

With Row count at 0 the grid creates rows automatically as items need them, sized by content. A positive count adds grid-template-rows: repeat(n, size); items beyond those rows still go into implicit rows, which you can size with grid-auto-rows.

Alignment

justify-items positions each item horizontally inside its cell and align-items vertically. Both default to stretch (omitted from the output), which makes items fill their cells. Values such as center shrink items to their content.

Tips and common mistakes

  • 1fr columns can grow. 1fr has a minimum of auto, so a long word, table or image can widen its column and make the grid uneven. Use minmax(0, 1fr) in the Column size field to keep columns equal.
  • Overflow on small phones. minmax(220px, 1fr) forces at least 220px, which can overflow a very narrow screen. A safer pattern is minmax(min(220px, 100%), 1fr).
  • Spanning items. To make a featured card wider, add grid-column: span 2 to that item. The generator produces the container rule; placement rules go on the items.
  • Grid does not reorder content for assistive technology. Visual placement never changes the DOM order, so keep the HTML in reading order.

Grid vs flexbox

Use grid when items should line up in both directions, such as a gallery where every row has the same column edges. Use the CSS flexbox generator for one-dimensional rows or columns where content size should decide the spacing, like toolbars and navigation. The two combine well: a grid for the page, flexbox inside each card. For headings that scale smoothly across these layouts, the CSS clamp generator calculates fluid sizes, and the CSS minifier compresses the finished stylesheet.

Privacy

The grid preview and generated code are created in your browser. Nothing is uploaded.

Frequently asked questions

How do I make a responsive grid without media queries?
Use grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)). The browser fits as many columns of at least 220px as the container allows and wraps the rest onto new rows, which is what the Responsive auto-fit mode generates.
What does the fr unit mean?
fr stands for a fraction of the free space in the grid container. repeat(3, 1fr) splits the remaining width into three equal parts, while 2fr 1fr gives the first column twice the share of the second.
Is gap the same as grid-gap?
Yes. grid-gap, grid-row-gap and grid-column-gap are the older names; current browsers support the shorter gap, row-gap and column-gap, which also work for flexbox.
How do I make one item span two columns?
Add grid-column: span 2 to that item, or grid-row: span 2 for rows. With auto-fit layouts, make sure the grid always has at least two columns, or the spanning item creates an extra implicit column.
How do I center a single element with grid?
Give the parent display: grid and place-items: center. That shorthand sets align-items and justify-items to center, centering the child both ways.

Last updated October 3, 2026

Related tools

CSS Animation Generator Generate CSS @keyframes animations — fade, slide, zoom, bounce, pulse, shake, spin and more — with duration, delay, easing and loop controls. CSS Background Pattern Generator Generate repeating CSS background patterns — stripes, polka dots, checkerboard, grid, zigzag and more — using only gradients, no images. CSS Border Radius Generator Set border-radius per corner in px or %, or shape organic blobs with the 8-value "fancy" border-radius syntax. Live preview and copyable CSS. CSS Box Shadow Generator Design layered CSS box-shadows with sliders for offset, blur, spread, colour and opacity. Supports inset shadows, presets and a Tailwind class. CSS Button Generator Design a CSS button with colours, gradient, padding, radius, border, shadow and hover/focus states, then copy clean HTML and CSS. CSS Clamp Generator (Fluid Typography) Calculate a CSS clamp() value that scales font size or spacing smoothly between two viewport widths, with a table of computed sizes. CSS Loader & Spinner Generator Create lightweight pure-CSS loading spinners — ring, dual ring, bouncing dots, bars and pulse — with custom colour, size and speed. CSS Pretty Print Opinionated CSS pretty print with Prettier: normalises case, leading zeros, quotes and semicolons so a team's stylesheets look alike. CSS Scrollbar Generator Style scrollbars for Chrome, Edge and Safari (::-webkit-scrollbar) and Firefox (scrollbar-color) at once, with a scrollable live preview. CSS Gradient Text Generator Fill headings with a colour gradient using background-clip: text. Pick two or three colours and an angle and copy cross-browser CSS. CSS Text Shadow Generator Generate CSS text-shadow effects — soft shadows, hard 3D offsets and neon glows — with live preview on your own text, then copy the CSS. CSS to LESS Converter Convert CSS to LESS online. Rules sharing a selector are nested automatically.