Docs
Next

Gap

Space the children of a grid or flex container with the token gap scale, gap-none to gap-3xl.

On this page

The gap utilities set gap, column-gap and row-gap from the token gap scale, so every stack, row and grid on a site shares the same rhythm. With the default tokens the sizes are none, xs, sm, md, lg, xl, 2xl and 3xl.

Quick referenceLink to this section

ClassStyles
gap-nonegap: var(--gap-none);
gap-x-nonecolumn-gap: var(--gap-none);
gap-y-nonerow-gap: var(--gap-none);
gap-xsgap: var(--gap-xs);
gap-x-xscolumn-gap: var(--gap-xs);
gap-y-xsrow-gap: var(--gap-xs);
gap-smgap: var(--gap-sm);
gap-x-smcolumn-gap: var(--gap-sm);
gap-y-smrow-gap: var(--gap-sm);
gap-mdgap: var(--gap-md);
gap-x-mdcolumn-gap: var(--gap-md);
gap-y-mdrow-gap: var(--gap-md);
gap-lggap: var(--gap-lg);
gap-x-lgcolumn-gap: var(--gap-lg);
gap-y-lgrow-gap: var(--gap-lg);
gap-xlgap: var(--gap-xl);
gap-x-xlcolumn-gap: var(--gap-xl);
gap-y-xlrow-gap: var(--gap-xl);
gap-2xlgap: var(--gap-2xl);
gap-x-2xlcolumn-gap: var(--gap-2xl);
gap-y-2xlrow-gap: var(--gap-2xl);
gap-3xlgap: var(--gap-3xl);
gap-x-3xlcolumn-gap: var(--gap-3xl);
gap-y-3xlrow-gap: var(--gap-3xl);

Basic usageLink to this section

Add gap-{size} to a grid or flex container to space its children. The hatched area in these previews is the gap.

const hatch =
  'bg-[repeating-linear-gradient(315deg,var(--color-foundations-line-muted)_0_1px,transparent_0_50%)] bg-size-[10px_10px]'

export default function Demo() {
  return (
    <div className={`grid w-full grid-cols-2 gap-md rounded-lg ${hatch}`}>
      {['01', '02', '03', '04'].map((label) => (
        <div
          key={label}
          className="bg-theme-500 grid h-14 place-items-center rounded-lg font-mono text-sm text-white"
        >
          {label}
        </div>
      ))}
    </div>
  )
}

Row and column gapsLink to this section

Use gap-x-{size} and gap-y-{size} to set the column gap and the row gap separately.

gap-x-xl gap-y-xs
const hatch =
  'bg-[repeating-linear-gradient(315deg,var(--color-foundations-line-muted)_0_1px,transparent_0_50%)] bg-size-[10px_10px]'

export default function Demo() {
  return (
    <div className={`grid w-full grid-cols-3 gap-x-xl gap-y-xs rounded-lg ${hatch}`}>
      {['01', '02', '03', '04', '05', '06'].map((label) => (
        <div
          key={label}
          className="bg-theme-500 grid h-14 place-items-center rounded-lg font-mono text-sm text-white"
        >
          {label}
        </div>
      ))}
    </div>
  )
}

The whole scaleLink to this section

Each row below is a flex container with one gap size between two boxes.

const hatch =
  'bg-[repeating-linear-gradient(315deg,var(--color-foundations-line-muted)_0_1px,transparent_0_50%)] bg-size-[10px_10px]'

const sizes = ['gap-none', 'gap-xs', 'gap-sm', 'gap-md', 'gap-lg', 'gap-xl', 'gap-2xl', 'gap-3xl']

export default function Demo() {
  return (
    <div className="flex w-full flex-col gap-3">
      {sizes.map((size) => (
        <div key={size} className="flex items-center gap-4">
          <span className="color-label w-20 shrink-0 font-mono text-xs">{size}</span>
          <div className={`flex rounded-md ${size} ${hatch}`}>
            <div className="bg-theme-500 h-8 w-12 rounded-md" />
            <div className="bg-theme-500 h-8 w-12 rounded-md" />
          </div>
        </div>
      ))}
    </div>
  )
}

In componentsLink to this section

The gap prop of Stack and Columns takes the same size names and renders these classes, so you rarely write them by hand inside a page built from components.

Responsive and state variantsLink to this section

Each size is a responsiveSizing token, so its value changes per breakpoint on its own. With the default tokens gap-md is 32px on sm, 24px on md and 40px on lg (the full table is in Spacing and sizing). The Payload template and these docs also apply a fluid spacing rule to gap, so the value scales with the viewport between breakpoints; switch the preview below between device widths to see it.

To pick a different size per breakpoint, prefix the class with a breakpoint:

gap-xs md:gap-md lg:gap-2xl
const hatch =
  'bg-[repeating-linear-gradient(315deg,var(--color-foundations-line-muted)_0_1px,transparent_0_50%)] bg-size-[10px_10px]'

export default function Demo() {
  return (
    <div className={`grid w-full grid-cols-3 gap-xs rounded-lg md:gap-md lg:gap-2xl ${hatch}`}>
      {['01', '02', '03', '04', '05', '06'].map((label) => (
        <div
          key={label}
          className="bg-theme-500 grid h-14 place-items-center rounded-lg font-mono text-sm text-white"
        >
          {label}
        </div>
      ))}
    </div>
  )
}

State variants (hover:, focus-within:, group-hover:) work the same way, though a changing gap is rarely what you want.

The gap classes sit in Systhema's utilities.systhema sub-layer, so a Tailwind spacing utility such as gap-4 on the same element wins over gap-md. See Cascade layers.

CustomizingLink to this section

The scale comes from the gap group of the responsiveSizing collection: gap-md reads --gap-md, and so on. Change a value per breakpoint in Figma, or override it with customTokens.responsiveSizing:

systhema.config.ts
const config: SysthemaConfig = {
  customTokens: {
    responsiveSizing: {
      lg: { gap: { md: '48px' } },
    },
  },
}

A key you add to the group becomes a class of the same name. Add it to every breakpoint so it has a value everywhere:

systhema.config.ts
const config: SysthemaConfig = {
  customTokens: {
    responsiveSizing: {
      sm: { gap: { '4xl': '128px' } },
      md: { gap: { '4xl': '128px' } },
      lg: { gap: { '4xl': '160px' } },
    },
  },
}

That emits gap-4xl, gap-x-4xl and gap-y-4xl. How pixel values become CSS (fixed --spacing multiples or fluid vw) is set by the spacing option; see Responsive sizing. Turn the whole family off with blocks.gap: false (Component CSS blocks).