Size & Density
The size axis (sm / md / lg, --fp-size-*) and the density axis (--fp-density) — how big each thing is, and how tightly things are packed.
Two axes, one sentence each:
Size is how big each thing is. Density is how tightly things are packed.
A dense dashboard with normal-sized buttons is data-density="compact" with size untouched. A marketing page with big buttons and more whitespace is data-size="lg" on the hero and data-density="relaxed" on the page. Density is set on <html>; size on any element. The two compose.
The size axis
Size is an inherited context with three public tiers — sm, md, lg. Set it anywhere; everything beneath follows, including components nested inside other components’ shadow trees.
<!-- the whole app -->
<html data-size="sm">
…
</html>
<!-- a region -->
<section data-size="lg">…</section>
<!-- one component -->
<fp-button size="sm">Compact</fp-button>Precedence, highest first: the element’s own size; a composing parent’s part; the nearest data-size ancestor; the document default, which is md. An unset size means inherit — it never means “medium, pinned”.
A tier is a set of dimensions, not a multiplier
“What small looks like” is answered once, in the sizes section of theme-config.json. Small can mean tight padding and readable text, and the hit-area floor is set per tier apart from the visual box (in the table below, sm has a 24px box and a 36px floor). A ratio can express neither, which is why the engine does not use one.
| Dimension | Config key | xs | sm | md | lg |
|---|---|---|---|---|---|
--fp-size-inset-inline | insetInline | s-4 | s-5 | s-6 | s-7 |
--fp-size-inset-block | insetBlock | s-2 | s-3 | s-4 | s-5 |
--fp-size-gap | gap | s-1 | s-2 | s-2 | s-3 |
--fp-size-font-size + -line-height | font | caption | label | body | body-lg |
--fp-size-title-font-size + -title-line-height | titleFont | label | body-lg | title | headline |
--fp-size-icon | icon | icon-size-sm | icon-size-sm | icon-size-md | icon-size-lg |
--fp-size-box | box | 20px | 24px | 32px | 40px |
--fp-size-min-target | minTarget | 28px | 36px | 44px | 52px |
Spacing knobs are steps on the spacing ladder, so density keeps flowing through inset and gap. Fonts are typography roles; a role carries its line-height, because the line-height tokens are lengths. minTarget is a floor, never a height — a control is as tall as its text and padding make it, and at least this.
Retune any cell without restating the tier:
{
"sizes": {
"sm": { "insetInline": 3, "minTarget": 40 }
}
}What the engine emits
Four token sets from one config block:
| Token | Meaning |
|---|---|
--fp-size-{tier}-{dim} | Definition — what a tier is. Components never read these. |
--fp-size-{dim} | Resolved — the current tier at this point in the tree. :root holds md. |
--fp-size-down-{dim} | Step-down — the tier one below the current one, floored at sm. |
--fp-size-compact-{dim} | Compact — one tier below with no floor, so at sm it reaches the private xs tier. For chips, tags and menu rows. |
xs is defined in config like the others but has no size="" rule; only the compact set reaches it.
And one rule per public tier, matched on [data-size] for any element and size="" for a component, that re-points the resolved, step-down and compact sets:
[data-size="sm"],
[size="sm"] {
--fp-size-inset-inline: var(--fp-size-sm-inset-inline);
…
--fp-size-down-inset-inline: var(--fp-size-sm-inset-inline); /* floored */
…
--fp-size-compact-inset-inline: var(--fp-size-xs-inset-inline);
…
}A component’s host element lives in the light DOM, so that rule reaches it and the tokens inherit into its shadow tree. For a component that another component renders inside its own shadow root, where the document rule cannot reach, every sized component adopts the same rules in :host([size]) form from one shared generated sheet. Components carry no tier CSS of their own — they consume the resolved names. fp-button, for example:
:host {
--_padding-x: var(
--fp-button-padding-inline,
max(var(--fp-inset-control), var(--fp-size-inset-inline))
);
--_gap: var(--fp-button-gap, var(--fp-size-gap));
--_font-size: var(--fp-button-font-size, var(--fp-size-font-size));
--_min-touch-target: var(--fp-button-target-min-size, var(--fp-size-min-target));
}The component hook comes first in every chain, so --fp-button-padding-inline still overrides the axis. The padding is floored by the corner-safe inset (see Shape).
The dimensions
| Resolved token | What it sizes |
|---|---|
--fp-size-inset-inline | inline padding of a control or surface |
--fp-size-inset-block | block padding |
--fp-size-gap | the gap inside one thing — an icon and its label |
--fp-size-font-size | control text |
--fp-size-line-height | its line-height |
--fp-size-title-font-size | a surface’s title |
--fp-size-title-line-height | |
--fp-size-icon | an icon box |
--fp-size-box | the box of a content-less thing that stands alone — avatar, swatch, thumb |
--fp-size-min-target | the hit-area floor |
Radius is not a size dimension: a small card and a large card share a corner, which comes from the shape tokens. Spacing between things — an action row, a list, sections of a card — is not a size dimension either. That is the --fp-gap-* roles, and density’s job.
Touch targets
Under (pointer: coarse) every tier’s --fp-size-min-target is raised to --fp-touch-target-min (44px). A small button on a phone has a small visual box and a full-size hit area. On a fine pointer the floor is the tier’s own.
Composition: controls one step down
A surface — a card’s actions, a modal’s footer, a drawer’s footer — puts its controls one tier below itself, from whatever it inherited. The part that hosts them carries data-size-down, and one shared stylesheet inside those components re-points the resolved set to the step-down set:
[data-size-down] {
--fp-size-inset-inline: var(--fp-size-down-inset-inline);
--fp-size-inset-block: var(--fp-size-down-inset-block);
/* … all ten … */
}A card with no size in an lg region gets md actions; the same card under sm gets sm actions (the floor). A size on the button wins, because it is a declaration on a nearer element. There is no arithmetic and no !important anywhere in the chain.
This is a documented default, not a rule of the system. To keep full-size controls in one surface, give the controls their own size:
<fp-card>
…
<fp-button slot="actions" size="md">Save</fp-button>
</fp-card>Override one dimension
Unlayered consumer CSS beats the axis without !important, per dimension:
.tight-toolbar {
--fp-size-inset-inline: var(--fp-s-3); /* everything else stays lg/md/sm */
}Density
Density is --fp-density, one continuous multiplier that every --fp-s-* step and every --fp-gap-* role is emitted against. Set it with the data-density attribute on <html>. The steps are declared on :root, so data-density (or --fp-density) on an inner element does not move them.
| Token | Value | Use |
|---|---|---|
--fp-density | 1 | the master multiplier |
--fp-density-compact | 0.75 | tables, dashboards, data grids |
--fp-density-default | 1 | standard |
--fp-density-relaxed | 1.25 | marketing, editorial |
<html data-density="compact">
…
</html>Every --fp-s-* step is calc(<length> * var(--fp-density, 1)), wrapped in round(nearest, …, 0.0625rem), so a density switch on <html> rescales the whole ladder and snaps it to the pixel grid. Because the size tiers’ spacing knobs are ladder steps, density flows through inset and gap as well.
Icon sizing
The icon sizes scale with --fp-type-scale. --fp-size-icon picks one of them per tier (sm, md, lg by default), and that is what controls such as fp-button use for their icon box.
| Token | Default |
|---|---|
--fp-icon-size-sm | round(nearest, calc(1rem × --fp-type-scale), 0.0625rem) |
--fp-icon-size-md | round(nearest, calc(1.25rem × --fp-type-scale), 0.0625rem) |
--fp-icon-size-lg | round(nearest, calc(1.5rem × --fp-type-scale), 0.0625rem) |
Each is rounded to the nearest 0.0625rem (1px at a 16px root font size), so a type scale does not leave an icon on a fractional pixel.
Decision matrix
| You want to… | Use |
|---|---|
| Make one button bigger | <fp-button size="lg"> |
| Make everything in a toolbar smaller | <div data-size="sm"> |
| Make the whole app compact | <html data-size="sm"> |
| Tighten all whitespace in a dashboard | <html data-density="compact"> |
| Change what “small” means | sizes.sm in theme-config.json |
| Change one dimension in one place | --fp-size-inset-inline: … in your own CSS |
| Keep full-size buttons inside a card | size on the buttons themselves |
Migration from --fp-component-size
The multiplier (--fp-component-size, --fp-component-size-{sm,md,lg}, the --fp-scale-* size aliases, the private --_s) and the per-component size multipliers are gone. A subtree that used to be scaled with --fp-component-size: var(--fp-component-size-sm) takes data-size="sm" instead; a component whose --fp-{tag}-size hook was a multiplier takes size="sm". A few --fp-{tag}-size hooks remain as plain lengths, such as --fp-avatar-size (the avatar’s box, default var(--fp-size-box)) and --fp-spinner-size. fp-field’s own density attribute went with them — there is one density axis, data-density.