Spacing and Density
One scale of nine sizes sets every gap and padding. How to pick a step, what each layout uses by default and how to tighten or loosen a whole region.
One scale
Spacing in Vanilla Breeze comes from nine tokens, --size-3xs to --size-3xl. Layout gaps, padding and the spacing inside components all read them. You name a step, not a number, so spacing stays consistent across a page and changes in one place.
| Step |
Token |
Default |
Multiple of --size-unit |
3xs | --size-3xs | 0.125rem | 0.5 |
2xs | --size-2xs | 0.25rem | 1 |
xs | --size-xs | 0.5rem | 2 |
s | --size-s | 0.75rem | 3 |
m | --size-m | 1rem | 4 |
l | --size-l | 1.5rem | 6 |
xl | --size-xl | 2rem | 8 |
2xl | --size-2xl | 3rem | 12 |
3xl | --size-3xl | 4rem | 16 |
Every step is a multiple of --size-unit, which is 0.25rem. Change the unit and the whole scale moves with it. That is how fluid scaling and the large-text accessibility theme resize spacing.
The demo changes the gap of one grid, and the density of the region around it.
Gap
data-layout-gap sets the space between a layout's children. It takes a step name or none.
<main data-layout="stack" data-layout-gap="2xl"> <section data-layout="stack" data-layout-gap="s"> <h2>Departures</h2> <p>Updated every minute.</p> </section> <ul data-layout="grid" data-layout-gap="l"> <li>...</li> </ul></main>
A useful habit: small steps inside a component (a heading and its text), medium steps between components, large steps between sections of a page.
Defaults
Leave the attribute off and each layout uses its own default.
| Layout |
Default gap |
| Stack, grid, switcher, sidebar, reel, media | m |
| Cluster | s |
| Split | xl |
| Regions | None |
| Cover | None. Its children are pushed apart by the free space. |
| Center | None. Adding data-layout-gap turns the center into a column with that gap; the bare attribute gives m. |
| Page layouts | m, except app-shell and dashboard, which have none |
Nested layouts start again
A gap applies to the element it is on and not to layouts inside it. A grid inside a stack with data-layout-gap="3xl" has the grid's default gap of m.
Padding and edges
Most layouts have no padding: they arrange children and leave the edges to their parent. These are the ones that do.
| On |
Attribute |
Values |
Default |
| Cover | data-layout-padding | none, s, m, l, xl | m |
| Reel | data-layout-padding | none, s, m, l | s, so focus rings and shadows on the items are not clipped |
| Center | data-layout-gutter | none, s, l | m on the inline sides |
| Imposter | data-layout-margin | s, m, l, xl | None. The distance from the edge it is pinned to. |
| Card | data-padding | none, s, m, l, xl | m |
| Canvas | data-padding | none, s, m, l, xl | See the canvas page |
<section> | data-padding | Bare, small, xsmall, none | No padding without the attribute |
The surfaces (card, canvas) and <section> use data-padding without the layout- part. On a section it sets the space above and below, for the bands of a marketing page, and it uses three separate tokens that grow with the viewport: --section-padding-normal (3rem to 6rem), --section-padding-small (2rem to 4rem) and --section-padding-xsmall (1.5rem to 3rem).
In your own CSS
Use the same tokens, so your components line up with the library's and follow density and fluid scaling.
.fare-table { padding: var(--size-m) var(--size-l); margin-block-end: var(--size-xl);}
To move the whole scale, set --size-unit. Every step is recalculated from it. A fixed unit of your own replaces the one a fluid preset sets, so use one or the other.
:root { --size-unit: 0.275rem;}
Density
data-layout-density replaces the size tokens for one region. Everything inside that reads a --size-* token becomes tighter or looser at once: gaps, card padding, button padding. Put it on <html> for a whole page or on any element for a part.
<main> <h1>Fleet status</h1> <section data-layout-density="compact" aria-label="Vehicles"> ... </section></main>
| Value |
--size-m becomes |
Line height |
Suits |
compact | 0.75rem | 1.4 | Dashboards, data tables, admin screens |
| (no attribute) | 1rem | Unchanged | Most pages |
spacious | 1.5rem | 1.8 | Landing pages, marketing sections |
The other steps move by similar amounts. The attribute page has the full table. compact also makes --font-size-s a little smaller. No other type size changes.
What to watch for
- It shifts the scale; it does not rename the steps.
data-layout-gap="m" inside a compact region is 0.75rem. You do not rewrite your gaps.
- Touch targets. On touch screens buttons and inputs keep a minimum height of 2.75rem whatever the density, but the space between them shrinks. Check a compact region on a phone.
- It is not
data-density. That attribute is a setting on one <table>, <dl> or tree nav and changes only that component's rows.