Free layout CSS tool

CSS Gap Generator

Tune row-gap and column-gap for Flexbox or Grid, preview the spacing live on real boxes, and copy the ready-to-use CSS.

Ready-to-use CSS

Consistent spacing without margin hacks

Space out Flexbox or Grid items cleanly, without the double-margin and edge-spacing problems that come from margin-based gutters.

Two real layout modes

Switch between a wrapping Flexbox row and a fixed four-column Grid to see how gap behaves in each.

Independent row & column gap

Set row-gap and column-gap separately, or let the tool combine them into the gap shorthand automatically.

Copy in one click

Grab the full display, template and gap declarations, ready to paste into your stylesheet.

How to use the gap generator

  1. Pick a layout modeChoose Flexbox for a wrapping row or Grid for a fixed four-column layout.
  2. Adjust the slidersSet row-gap and column-gap independently and watch the boxes reflow live.
  3. Copy the CSSSelect Copy CSS to grab the generated display, template and gap rules.

About the CSS gap property

The gap property (along with its longhand row-gap and column-gap) sets spacing directly between the rows and columns of a Flexbox or Grid container, rather than around or inside individual items. That distinction matters: a margin applied to every item also adds space at the outer edges of the container and, in Flexbox, stacks unevenly between wrapped rows, so developers historically had to zero out the margin on the last item in each row or wrap everything in a negative-margin container. gap avoids all of that by living on the container itself and only ever inserting space between adjacent items. gap was originally a Grid-only feature but has been supported for Flexbox in every major browser for several years now, so it is safe to reach for as the default way to space out any flex or grid layout. The shorthand accepts one length for both axes, or two lengths in the order row-gap then column-gap, and any valid CSS length unit works, not just pixels.

Order matters in shorthand

gap: 16px 24px sets row-gap to 16px and column-gap to 24px, in that order.

Works with wrapping

In Flexbox, gap correctly spaces wrapped rows the same way it spaces items within a single row.

Any CSS length unit

gap accepts px, rem, %, and other length units, not only pixels.

CSS gap generator FAQ

What is the CSS gap property?

gap is a shorthand CSS property for row-gap and column-gap. It sets the spacing between rows and columns in both Flexbox and Grid layouts without adding margin to individual items.

Does gap work with Flexbox as well as Grid?

Yes. gap originally shipped for Grid but is now supported for Flexbox in all modern browsers, where it adds spacing between flex items, including wrapped rows, without the double-margin problem of margin-based spacing.

What is the difference between row-gap and column-gap?

row-gap sets the space between rows and column-gap sets the space between columns. The gap shorthand accepts one value for both, or two values in the order row-gap then column-gap.

Why use gap instead of margin on flex or grid items?

Margin on individual items has to be applied carefully to avoid extra space at the edges of the container and stacks awkwardly between wrapped rows. gap is applied once on the container and only adds space between items, never around the outer edge.

Is CSS gap free to use in production today?

Yes. gap for both Flexbox and Grid is supported in all current major browsers and has been for several years, so it is safe to use without a fallback in almost all projects.

Try other tools

Keep building with these free online CSS tools.