Fluid Typography
A call-to-action block — heading, one line, button — whose type steps up three times as its slot passes 260 then 320 px wide. CSS only, sizes in rem.
Updated
This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. Utilities has 43 effects, including 3 free. Explore the category →
3 usage examples



How it works
The component groups three elements inside .aty-content (20 px of padding): an h2.aty-title, a paragraph .aty-text and a purple button.aty-btn. The root .fx-0747-root declares itself the measured container with container: aty-text / inline-size: its own width is in charge, not the window's. Dropped into a 164 px column, it shows a 1rem heading (16 px), a .72rem line (11.5 px) and a small button.
Two @container aty-text rules do the rest. At 260 px the heading goes to 1.4rem, the line to .82rem, and the button thickens (10 × 20 px of padding, .82rem label). At 320 px the heading reaches 1.8rem (28.8 px) and the line .88rem; the button stays as it is. The measured thresholds land exactly: 259 px gives the first step, 260 px the second, 320 px the third.
The name says “fluid”, the code delivers steps: between two thresholds nothing varies. What softens the jump is transition: font-size .3s on the heading and the line, and transition: .3s on the button. No script ships, and the button has no action: giving it a link or a handler is up to you.
Accessibility
- Sizes in rem: all three steps follow the text size the reader picked in the browser. With a 20 px setting, the heading of the large step measures 36 px instead of 28.8. The thresholds themselves stay in pixels.
- Tiny first step: under 260 px the line is 11.5 px. That is short for reading text; keep a single teaser line there or raise
.aty-textto .8rem. - Keyboard: the button is a real
<button type="button">, reached with Tab, with a 2 px lilac outline (:focus-visible). The heading is anh2: change the level if your page already has one above it. - Reduced motion: with
prefers-reduced-motion: reducethe three transitions are switched off and the step change is immediate. - Contrast: the line is 65 % white on
#0a0a0f, the label white on the button's purple gradient; both clear the AA threshold for body text.
Browser compatibility
Everything rests on container queries (container, @container). Recorded in Chromium 149, Firefox 151 and WebKit 26.5: same computed sizes at all three steps, switches at exactly 260 and 320 px, two instances of different widths on one page with no influence on each other. A Firefox quirk: on page load it plays the transition once (the text starts at the small step and reaches its own in 0.3 s).
A browser that ignores @container keeps the first step whatever the room: everything stays readable and clickable, just small. If that audience matters to you, write the middle step's sizes into the base rule.
The code
HTML structure to paste into your page (the CSS + JS come with your purchase):
<div class="fx-0747-root">
<div class="aty-content">
<h2 class="aty-title">Heading</h2>
<p class="aty-text">Text</p>
<button type="button" class="aty-btn">Action</button>
</div>
</div>
One-time payment, no subscription — the code is yours forever
Customize
Options passed to the API or data-* attributes:
| Option / property | Default | Effect |
|---|---|---|
Thresholds (CSS — @container aty-text (min-width: 260px) and (min-width: 320px)) |
260 and 320 px | Spread them (300 and 480 px) if your slots are wide; add a third rule for one more step. |
Heading sizes (CSS — .aty-title in each rule) |
1rem → 1.4rem → 1.8rem | Keep a ratio of about 1.3 between two steps: below that, the jump goes unnoticed. |
Line sizes (CSS — .aty-text) |
.72rem → .82rem → .88rem | Start from .8rem if the small step has to carry more than one line. |
Button (CSS — .aty-btn) |
#7c3aed → #6d28d9 gradient, 8 px corners, a single change at 260 px |
Swap background and color for your colours; add a line to the 320 px rule to make it grow a second time. |
Background and padding (CSS — .fx-0747-root, .aty-content) |
#0a0a0f, 20 px |
On a light page: white background, .aty-title in #111, .aty-text in #555. |
Change duration (CSS — transition) |
0.3 s | none for a hard switch, and to remove Firefox's load animation. |
FAQ
font-size: clamp(1rem, 8cqi, 1.8rem): the cqi unit is 1 % of the root's width and needs the same browsers.transition declarations.