Skip to content

Spacing Systems

You already know that arbitrary spacing feels wrong. When buttons have 14px padding in one place and 11px in another, users notice — even if they cannot name why. Designers use spacing tokens to prevent this. In CSS, we do exactly the same thing: commit to a spacing scale and only use values from that scale.

The most widely used spacing scale is based on multiples of 4 (sometimes called a “4-point grid”) or multiples of 8 (an “8-point grid”). Every spacing value in your project comes from this sequence:

Step4pt scale8pt scale
14px8px
28px16px
312px24px
416px32px
520px40px
624px48px

In CSS it is common to express these in rem units (where 1rem = 16px by default):

rempx equivalent
0.25rem4px
0.5rem8px
0.75rem12px
1rem16px
1.5rem24px
2rem32px

padding — Space inside an element, between its border and its content. Grows the element itself. Think of the “horizontal/vertical padding” in a Figma auto-layout frame.

margin — Space outside an element, pushing away from its neighbors. Does not grow the element — it creates a buffer zone around it.

gap — Space between children in a Flex or Grid container. The cleanest, most predictable way to space items — it does not add space around the edges, only between items.

ScenarioUse
Space between items inside a flex or grid containergap
Internal padding of a button, card, or boxpadding
Push one element away from a siblingmargin
Center a block element horizontallymargin: 0 auto
Keep content away from the edges of the pagepadding on the body/container

Editable example — a card with a spacing system

Section titled “Editable example — a card with a spacing system”

Things to try:

  • Change .card padding from 1.5rem to 0.5rem — notice how cramped it feels
  • Change .page gap from 1rem to 3rem — notice how airy it becomes
  • Change .actions gap from 0.5rem to 2rem — the buttons drift apart
  • Try padding: 2rem on .card — it expands to match
You want 16px of space between buttons inside a flex container. The best property to use is:
What is the difference between padding and margin?
In an 8pt spacing scale, which value is NOT part of the scale?
How do you center a block element horizontally with margin?