Utilities✨ Premium

Typography Adapts

Heading and paragraph whose size, weight, letter spacing and line height change in four steps based on the width of the block that holds them.

CSS@containerTypography

Updated

This effect is part of Effect.Labs — 840 vanilla effects, some free, some premium. Utilities has 43 effects, including 3 free. Explore the category →

3 usage examples

Plumevère magazine — the same quote as a full-width pull quote and in the “In short” box — Typography Adapts example 1

① Plumevère magazine — the same quote as a full-width pull quote and in the “In short” box

WhenIn a portrait of an organ builder, the quote spans the article width and takes the 400 px step: big tight heading, airy standfirst. Further down, the 172 px “In short” box reuses the component at its smallest step.
WhyEditors drop the same block anywhere; the type hierarchy follows the room, with no “large” or “small” class to pick.
SettingsTwo roots; the quote gets a red rule from the scene CSS, the box has a border and an “In short” label above the component.
Tremaudin newsletter editor — widening the text column next to an image — Typography Adapts example 2

② Tremaudin newsletter editor — widening the text column next to an image

WhenDrag the handle between the text column and the image: the heading goes from 12 to 18 then 26 px and the text opens up. On load the column runs from 190 to 420 px and back.
WhyWriters see how each column width renders before sending, without setting font sizes by hand.
SettingsHandle setting the column width between 170 and 430 px; the last step (550 px) does not fit in the scene and is not shown.
Ardoisine whiteboard — notes drop to the small step when comments open — Typography Adapts example 3

③ Ardoisine whiteboard — notes drop to the small step when comments open

WhenTwo notes are pinned on the board at 18 px. Clicking “Comments” opens a column on the right: the board shrinks, each note goes under 250 px and its text returns to the smallest step.
WhyNotes stay whole and readable at a glance, even when the panel takes room.
SettingsButton (aria-expanded) opening a 172 px column; each note is a root with a coloured top edge added by the scene.

How it works

The .fx-0759-root element (#0a0a0f background, full width) declares container: tya-text / inline-size. Inside, .tya-block adds 16 px of padding around an h3 and a paragraph. At its narrowest, the heading is 12 px at weight 800 and the text 10 px with a 1.4 line height: enough to fit a thumbnail.

Three @container tya-text rules take over. At 250 px: a tighter 18 px heading (letter-spacing: -0.02em) and 13 px text with a touch of spacing. At 400 px: a 26 px heading at weight 700, 15 px text, 1.6 line height. At 550 px: a 34 px heading tracked in hard (-0.04em), 17 px text, 1.7 line height. The heading tightens as it grows while the text opens up, the way a magazine layout is adjusted by hand.

Each change eases in through transition: .4s on the block, the heading and the paragraph. The component has no script: just CSS rules applied to the block's real width.

Accessibility

  • Very small first step: under 250 px the paragraph is 10 px, below what many readers read comfortably. If the block may be narrow on mobile, raise the base size of .tya-block p to 12 or 13 px.
  • Pixel units: sizes are in px; browser zoom enlarges them, but some systems' “text size” setting does not. Switch to rem to honour that setting.
  • Structure untouched: only styles change; the heading stays an h3 (adjust to your hierarchy) and the text a paragraph.
  • Reduced motion: under prefers-reduced-motion: reduce, size transitions are removed.

Browser compatibility

Container queries only. Measured in Chromium 151, Firefox 153 and WebKit 26.5: four states at the same widths (switches between 230 and 260, 380 and 430, 520 and 620 px), no error, no overflow.

Chrome 105+✓ Full (measured)
Firefox 110+✓ Full (measured)
Safari 16+✓ Full (measured in WebKit)
Edge 105+✓ Full
Mobile iOS 16+✓ Full
Android Chrome 105+✓ Full

Without @container the text stays at the smallest step (12 px / 10 px): set a larger base size if your audience uses old browsers.

The code

HTML structure to paste into your page (the CSS + JS come with your purchase):

index.html — structure
<div class="fx-0759-root">
  <div class="tya-block">
    <h3>Heading</h3>
    <p>Paragraph</p>
  </div>
</div>

One-time payment, no subscription — the code is yours forever

Customize

Options passed to the API or data-* attributes:

Option / propertyDefaultEffect
Steps (CSS — @container tya-text (min-width: 250px / 400px / 550px)) 250, 400 and 550 px Drop the last one if your blocks never exceed 500 px; add one at 720 px for a very large quote.
Base sizes (CSS — .tya-block h3 and .tya-block p) 12 px and 10 px Go up to 15 px and 13 px to keep the small step readable on mobile.
Heading tracking (CSS — letter-spacing per step) 0 → -0.02 → -0.03 → -0.04 em With an already tight typeface, keep 0 for the first two steps.
Colours (CSS — .fx-0759-root, h3, p) #0a0a0f background, white heading, 70 % white text For a light background: white background, #111 heading, #444 text.
Speed (CSS — transition: .4s) 0.4 s none if the block changes width often (dragging a column) and the animation gets in the way.
Continuous version (CSS) Steps For a size that follows the width continuously, replace the steps with font-size: clamp(12px, 6cqi, 34px) on the heading (container units).

FAQ

The steps also change weight, tracking and line height, which a single fluid formula does not. You can mix both: steps for tracking, clamp() in cqi units for size.
That is the first step (10 px for the paragraph). Raise the sizes in the base rule, or lower the first step to 200 px so your sidebar reaches it.
Yes, as long as the selectors follow: replace h3 with your tag in the HTML and in the .tya-block h3 rules.