Type and spacing that grow smoothly with the viewport, with no breakpoints. One attribute turns it on, and three presets set how far the sizes move.
What it does
By default the type and spacing tokens are fixed: --font-size-5xl is 3rem on a phone and on a wide monitor. With data-fluid, each token becomes a clamp() value that grows with the viewport between 320px and 1440px wide. Below 320px it holds at its smallest value and above 1440px at its largest.
Because the change is in the tokens, everything that reads them follows: headings, body text, layout gaps, padding. There is no step where sizes jump.
Choose a preset in the demo, then resize the window. The line under the specimen shows two of the computed sizes.
Turning it on
Add data-fluid to <html>. It is off unless you add it.
<html lang="en" data-fluid> <html lang="en" data-fluid="compact"> <html lang="en" data-fluid="spacious">
The attribute also works on any other element and then applies to that subtree only. The sizes still follow the width of the viewport, not the width of the element.
To let readers choose, the <settings-panel> has a fluid scaling control that sets the attribute and remembers the choice. From script, use the theme manager.
import { ThemeManager } from 'vanilla-breeze'; ThemeManager.setFluid('spacious'); ThemeManager.setFluid('');
Presets
Each range runs from the value at a 320px viewport to the value at 1440px.
| Token |
Fixed |
compact |
data-fluid |
spacious |
| Ratio between type steps | Varies | 1.067 to 1.2 | 1.125 to 1.25 | 1.2 to 1.333 |
--font-size-m (body text) | 1rem | 1rem | 1rem to 1.06rem | 1rem to 1.13rem |
--font-size-5xl | 3rem | 1.48rem to 2.99rem | 2.03rem to 4.05rem | 2.99rem to 6.31rem |
--size-unit (spacing) | 0.25rem | 0.2rem to 0.25rem | 0.225rem to 0.275rem | 0.25rem to 0.3125rem |
--content-normal | 60rem | 40rem to 60rem | 40rem to 65rem | 42rem to 70rem |
--measure-normal | 65ch | 55ch to 65ch | 55ch to 70ch | 55ch to 75ch |
compact keeps headings close in size to the text and spacing at or below the fixed scale. It suits dense screens such as dashboards.
- The default is a moderate range that suits most content sites.
spacious gives large headings and looser spacing on wide screens. It suits landing pages and editorial layouts.
What changes
Type
Nine tokens, --font-size-xs to --font-size-5xl, are replaced. From the body size up, each gets a clamp() value. The steps are closer together on a narrow viewport, where a very large heading would wrap badly, and further apart on a wide one. The large sizes move the most and body text hardly moves.
No size gets smaller as the viewport widens. The two steps below the body size, --font-size-xs and --font-size-s, keep one value at every width in the default and compact presets. In spacious, --font-size-xs is constant and --font-size-s grows slightly.
--font-size-2xs stays fixed. The fixed scale and the rest of the type system are described in the Typography guide.
Spacing
Only --size-unit is replaced. The nine --size-* tokens are multiples of it, so the whole spacing scale becomes fluid: data-layout-gap, layout padding and the data-layout-density scales.
Content widths
--content-normal and --measure-normal grow with the viewport, so a centered column and a reading column are narrower on small screens and wider on large ones. The narrow and wide variants stay fixed. See Content Width.
What does not change
- Breakpoints. The widths where page layouts, main-level sidebars and splits collapse (48rem) are media queries and stay where they are.
- Layout thresholds. Grid column minimums, the switcher threshold and sidebar widths are fixed
rem values.
- Line height, colors, radii and shadows.
With themes
data-fluid combines with data-theme. Most themes set colors and fonts and leave sizes alone, so nothing more is needed.
The a11y-large-text theme raises the base sizes (body text at 1.25rem, a spacing unit of 0.3125rem). It has its own fluid values, so with data-fluid the body text runs from 1.25rem to 1.375rem and the larger sizes scale from that base. The named presets work with it too: compact and spacious give that preset's type and spacing values multiplied by 1.25.
<html lang="en" data-theme="a11y-large-text" data-fluid>
A preset of your own
A preset is a rule that sets the tokens. Write one with your own values and name it in the attribute. Each value is clamp(minimum, slope + intercept, maximum); use vi for the slope so it follows the inline size of the viewport.
[data-fluid="editorial"] { --font-size-m: clamp(1rem, 0.18vi + 0.96rem, 1.125rem); --font-size-xl: clamp(1.3rem, 0.6vi + 1.18rem, 1.75rem); --font-size-3xl: clamp(1.7rem, 1.6vi + 1.38rem, 2.8rem); --font-size-5xl: clamp(2.2rem, 3.4vi + 1.5rem, 4.6rem); --size-unit: clamp(0.225rem, 0.07vi + 0.21rem, 0.275rem);}
Tokens you leave out keep the default preset's values, because [data-fluid] matches any value. The library has no tool that generates these values.
Input type
Two adjustments depend on the pointer and not on the viewport. They are always on and do not need data-fluid.
| Query | Effect |
(pointer: coarse) | Buttons, selects and inputs get a minimum height of --size-touch-min (2.75rem, 44px). Their width and links are not changed. |
(hover: none) | The hover motion tokens --motion-hover-lift and --motion-hover-scale are set to none, so effects built on them do nothing on devices that cannot hover. |
When to leave it off
- Dense application screens. A dashboard or data table usually wants the same sizes at every width. Use fixed tokens, with
data-layout-density="compact" if you want them tighter.
- Embedded widgets. The sizes follow the viewport. A component that lives in a narrow column of a wide page gets wide-page sizes. Container queries suit that case better.
- A site that already sizes type at breakpoints. Two systems moving the same sizes are hard to reason about. Pick one.