
Spacing and Sizing Design Tokens
A spacing token set is a chosen scale, not a token per pixel. Here is the base unit, the naming trade-off, semantic roles, and when a size is worth tokenizing.
TL;DR: A spacing token set is a deliberate scale — a base unit and a progression — not a token for every pixel value someone once typed. Name the steps numerically or with t-shirt sizes depending on whether you value extensibility or readability, then put semantic spacing roles (inset, stack, inline, gap) on top so components consume intent, not raw steps. Sizing tokens often share the base unit but serve a different job; tokenize the repeated, leave the unique as a one-off. The scale keeps its value only if you resist adding in-between steps on demand and audit for raw values that bypass it. And the honest part: tokens make spacing consistent, but the scale's rhythm is a design decision, not a formula. This guide covers the scale, the naming trade-off, the semantic roles, and where sizing belongs.
A spacing scale is a primitive set
Spacing primitives are a scale, which means they are chosen, not collected. The difference is the whole point. A scale is a small, deliberate set of steps that everything snaps to; a collection is every value anyone ever needed, which is not a system at all — it is a record of ad hoc decisions with token names bolted on. The moment your spacing set has a value for every gap someone wanted, it has stopped being a scale and started being a junk drawer.
A base unit and a progression are what make the scale predictable. A base of 4 or 8 pixels divides cleanly and composes without fractional values, and a progression built on it — for example 4, 8, 12, 16, 24, 32, 48 — gives layouts a rhythm you can feel even when you cannot name it. The steps compile down to real CSS length values in the output, but the token set holds the scale. In the DTCG format, steps like these are typed as dimension tokens, a type it defines as an amount of distance in a single dimension in the UI, such as a position, width, height, radius, or thickness, and it requires the value to be an object with a numeric value and a unit of px or rem (Design Tokens Format Module 2025.10, dimension type, as of November 2026).
Naming the steps is a genuine trade-off, and it is worth stating concretely. Numeric names — space.4, space.8, space.12 — extend forever; adding a step is just a new number, and the name tells you the value. Their cost is that the name carries no sense of scale relative to its neighbors. T-shirt names — space.sm, space.md, space.lg — read as sizes and communicate relative magnitude at a glance, but they run out: inserting a value between md and lg forces an awkward md-plus and the scheme starts to fray. Numeric buys extensibility at the cost of readability; t-shirt buys readability at the cost of extensibility. Pick the one whose cost you can live with, and hold it consistently.
Semantic spacing roles
Above the raw scale sits a layer that names intent instead of magnitude. Semantic spacing roles describe what a gap is for: inset for padding inside a container, stack for vertical rhythm between elements, inline for horizontal spacing between siblings, gap for the space a layout distributes between its children. These roles are what components should consume — a card asks for its inset, not for space.16.
That indirection is what makes density themes straightforward. When components reference semantic spacing rather than scale steps, a compact theme can remap the roles to smaller steps and the whole product tightens without touching a single component. The mechanic of swapping one value set for another is covered in the article on theming; the point here is that consuming roles instead of steps is what lets a theme do it without changing the scale itself. A component wired directly to space.16 cannot be made denser without editing the component or changing what space.16 means everywhere it is used; one wired to an inset role follows the theme. The example below shows a semantic spacing role referencing a scale step.
{
"space": { "16": { "$type": "dimension", "$value": { "value": 16, "unit": "px" } } },
"spacing": {
"inset": { "md": { "$type": "dimension", "$value": "{space.16}" } }
}
}Here spacing.inset.md names intent — medium padding inside a container — and points at the scale step that currently fills it. A density theme remaps spacing.inset.md to a smaller step; the component asking for the inset role never changes. The role is the stable contract; the step behind it is an implementation detail.
Sizing tokens and where they belong
Sizing tokens — icon sizes, control heights, container widths — often share the base unit with spacing, which invites treating them as the same set. They are not. Spacing is the space between and around things; sizing is the dimension of the things themselves. A 16-pixel gap and a 16-pixel icon happen to share a number, but they answer different questions and change for different reasons, so they deserve separate roles even when they draw from the same base.
The real judgment is when a size should be a token at all. The rule is to tokenize the repeated, not the unique. An icon size that appears across dozens of components, a control height every input and button shares, a set of standard container widths — those are tokens, because a token is how a repeated decision stays consistent and changes in one place. A one-off width on a single marketing section that will never recur is not a token; making it one adds a name to maintain for a value used once. The test is not "is this a size" but "will this size be reused, and do I want it to move in lockstep when it changes."
| Value | Token or one-off | Why |
|---|---|---|
| Icon size used across components | Token | Repeated; must stay consistent |
| Standard control height | Token | Shared contract across inputs and buttons |
| A common set of container widths | Token | Reused layout constraint |
| A single section's bespoke width | One-off | Used once; a token would be noise |
Minimum and maximum bounds and fluid sizing have a place in the set too — a container that grows within a floor and ceiling can hold those bounds as tokens. But the breakpoint and fluid-scaling mechanics that make a size respond to the viewport belong to layout-specific areas, not here; the token set holds the values, and the responsive behavior is deferred.
Keeping the scale from sprawling
A scale earns its keep by being small, and it stays small only against steady pressure to grow. One leak is the in-between step added on demand: a layout needs 20 pixels, so someone adds space.20 between the 16 and the 24. Do it a few times and the scale has a value for everything, which is the same as having no scale — the constraint that made spacing consistent is gone. Resist the in-between step; snap the layout to an existing value, or reconsider the design that wanted a non-scale gap.
The other leak is the raw value that bypasses the tokens entirely — a hardcoded margin in a component that never touched the scale. These are the divergences that make the system a suggestion rather than a rule, and the way to catch them is to audit for spacing values that do not resolve to a token. That check is cheap and worth automating, because a raw value that ships is a scale step nobody agreed to.
The honest limit is where the discipline ends. Tokens make spacing consistent and enforceable, but they do not choose the rhythm for you. Whether the scale steps by fours or eights, whether the progression is linear or accelerates toward the large end, whether the product feels tight or airy — those are design decisions, not outputs of a formula. A well-built spacing token set encodes a rhythm faithfully and holds every component to it. It does not decide what the rhythm should be; that judgment stays with the people designing the product.