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.
| Utility step | Pixels | Typical use |
|---|---|---|
| 1, 1.5 | 4, 6 | Between an icon and its label inside a button |
| 2 | 8 | Between a label and its control |
| 3 | 12 | Between buttons in a row, between list items |
| 4 | 16 | Card padding on a small card, between fields |
| 6 | 24 | Card padding, between cards |
| 8 | 32 | Between 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.
Keep to the scale and use one gap for each level of grouping.
Purchasing
Luca confirms the supplier and the order ships on Friday.
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.
| Token | Value | Utilities | Decides |
|---|---|---|---|
--pad-x | clamp(20px, 3.52vw, 64px) | px-page, gap-page | The margin at each side of the page, at every width. |
--gutter | clamp(16px, 1.67vw, 24px) | gap-gutter | The space between columns. |
--section-pad | clamp(56px, 8.33vw, 120px) | py-section | The space between sections: this alone, nothing added. |
--stack-gap | clamp(40px, 4.45vw, 64px) | gap-stack, mt-stack | The space from a section's head to its content. |
--title-gap | 24px | gap-title | The 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.
Resize the window and the example breathes: every value above except --title-gap is fluid.
Related
- Sizing for control heights and touch targets.
- Breakpoints for how the layout changes by width.