Skip to content

Spacing

Tailwind's four pixel scale for space inside components, and five named layout tokens for the space between them.

Space comes from two sources. Inside a component it is Tailwind's default scale, which upstream shadcn components already use. Between components, sections and the page edge it is a small set of named layout tokens defined in app/globals.css, so a client brand can loosen or tighten a whole layout by changing five values.

The scale

Tailwind's spacing unit is 4px: p-1 is 4px, p-4 is 16px, gap-6 is 24px. The system does not change it. Use these steps and nothing else.

1 · 4px
2 · 8px
3 · 12px
4 · 16px
6 · 24px
8 · 32px
12 · 48px
16 · 64px
Utility stepPixelsTypical use
1, 1.54, 6Between an icon and its label inside a button
28Between a label and its control
312Between buttons in a row, between list items
416Card padding on a small card, between fields
624Card padding, between cards
832Between groups inside a page

Never write an arbitrary value such as mb-[19px]. If the scale has no step you want, use the nearest one.

Purchasing

Luca confirms the supplier and the order ships on Friday.

BRV-2041, BresciaBRV-2042, Verona
Do

Keep to the scale and use one gap for each level of grouping.

Purchasing

Luca confirms the supplier and the order ships on Friday.

BRV-2041, BresciaBRV-2042, Verona
Don’t

Don’t write values off the scale.

Layout tokens

Five tokens set the rhythm of a page. Each is a CSS variable and also a spacing utility, so it works wherever Tailwind accepts a spacing value: px-page, gap-gutter, py-section, gap-stack, mt-title.

TokenValueUtilitiesDecides
--pad-xclamp(20px, 3.52vw, 64px)px-page, gap-pageThe margin at each side of the page, at every width.
--gutterclamp(16px, 1.67vw, 24px)gap-gutterThe space between columns.
--section-padclamp(56px, 8.33vw, 120px)py-sectionThe space between sections: this alone, nothing added.
--stack-gapclamp(40px, 4.45vw, 64px)gap-stack, mt-stackThe space from a section's head to its content.
--title-gap24pxgap-titleThe space from a title to its intro.

--header-height (72px, 64px below 1240px) is a sixth layout token. It sets h-header and scroll-mt-header, so anchors stop below a fixed header.

The pattern: one pair of margins at every width (px-page outside, gap-gutter between columns), py-section between sections, and inside a section two gaps, gap-title from the title to its intro and gap-stack from the head to its content.

Purchasing this week

Four orders across three sites wait on a supplier.

Brescia, 2 orders
Verona, 1 order
Mantova, 1 order

Resize the window and the example breathes: every value above except --title-gap is fluid.

  • Sizing for control heights and touch targets.
  • Breakpoints for how the layout changes by width.