UtilitiesPremium

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.

CSS@containerTypography

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

Navigation notices sharing the top of the screen — a canal boat hire company's app — Fluid Typography example 1

① Navigation notices sharing the top of the screen — a canal boat hire company's app

WhenCruising the canal, the boat's app shows the notices in force. On its own, “Lock 12 closed” spans the full width (528 px), at the large step. A second notice comes in: each drops to 261 px, the middle step. With a third, the three 172 px columns fall to the small step, button included.
WhyThe more notices there are, the quieter each one gets; an urgent notice arriving alone speaks up in large type, with no rule to write for every combination.
SettingsThree roots in a page grid (grid-auto-flow: column, 6 px gap); one background per severity (red, amber, blue) set on the root, white button, inner padding cut to 14 × 16 px. The notices arriving is simulated by the page: a timer shows 1, 2 then 3 of them every 0.5 s. The block only reads its width.
Home screen of a peer-tutoring app at ⅓, ½ or ⅔ of the screen — tablet in split view — Fluid Typography example 2

② Home screen of a peer-tutoring app at ⅓, ½ or ⅔ of the screen — tablet in split view

WhenThe app shares the tablet with a notepad. At a third of the screen (174 px) its welcome block fits small; at half (262 px) it moves to the middle step; at two thirds (346 px) “Hello Inès” shows large.
WhySplit view changes the app's width without changing the tablet's: a media query would see nothing, the container query follows.
SettingsThe root spans the full width of the app. Three buttons ⅓ ½ ⅔ set the share of the screen; in the capture, a scene animation runs through the three shares every 0.9 s — the component only reads its width.
“Added to basket” notification that opens on hover — a seed shop's online store — Fluid Typography example 3

③ “Added to basket” notification that opens on hover — a seed shop's online store

WhenThe visitor has just added a packet of tomato seeds: the notification waits in the corner, narrow (196 px), at the small step. The pointer moves over it, or the keyboard reaches “View basket”: it opens to 340 px and the message moves to the large step, heading at 28.8 px.
WhyClosed, it confirms the purchase without covering the product; open, it reads at a glance and leads to the basket.
SettingsOne root in a frame pinned bottom right, whose width the page changes on hover and focus (:hover, :focus-within, 0.3 s; closing waits 0.5 s). Serif heading, fir-green background, yellow button. In the capture, the mouse is what passes over the notification.

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-text to .8rem.
  • Keyboard: the button is a real <button type="button">, reached with Tab, with a 2 px lilac outline (:focus-visible). The heading is an h2: change the level if your page already has one above it.
  • Reduced motion: with prefers-reduced-motion: reduce the 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).

Chrome 105+✓ Full (measured in Chromium 149)
Firefox 110+✓ Full (measured in Firefox 151) — transition also plays on load
Safari 16+✓ Measured in WebKit 26.5; real Safari not verified
Edge 105+✓ Not verified (same engine as Chrome)
Mobile iOS 16+✓ Not verified on a device
Android Chrome 105+✓ Measured in 390 px emulation: large step, no overflow

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):

index.html — structure
<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 / propertyDefaultEffect
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

No. There are three fixed sizes and two thresholds; between 260 and 319 px, for instance, nothing changes. For a size that truly slides, replace the heading rules with font-size: clamp(1rem, 8cqi, 1.8rem): the cqi unit is 1 % of the root's width and needs the same browsers.
Typography Adapts is a reading block: heading and paragraph, four steps up to 550 px, sizes in pixels, and it also retouches weight, letter spacing and line height. Fluid Typography is a call-to-action block: it adds a button that grows with the text, stops at 320 px because it targets small slots, and counts in rem.
Firefox computes the style once without knowing the container's width, then applies the right step: the 0.3 s transition plays between the two. Chrome and Safari's engine show the right size straight away. If it bothers you, remove the two transition declarations.