env(preferred-text-scale) demo

Back to overview

env(preferred-text-scale) exposes the OS-level font scale setting as a CSS environment variable. Use it to apply text scaling to specific elements.

The value depends on <meta name="text-scale"> (CSS Fonts 5 §2):

Usage

.scaled {
  font-size: calc(16px * env(preferred-text-scale, 1));
}

Demo

Change your OS text scale setting to see the difference between scaled and non-scaled text.

Scaled text

This text uses font-size: calc(16px * env(preferred-text-scale, 1))

Non-scaled text

This text uses font-size: 16px (no scaling)

Current preferred-text-scale value: 1

Testing

On desktop, emulate the OS text scale from DevTools (the --blink-settings=accessibilityFontScaleFactor flag had no effect in Chrome 157 Canary on macOS):

  1. DevTools Settings → Experiments → enable "Protocol Monitor", then reload DevTools.
  2. Open it with "Show Protocol monitor" from the command menu (Cmd/Ctrl + Shift + P).
  3. Send Emulation.setEmulatedOSTextScale with {"scale": 2}, then reload the page.

This is a demo for env(preferred-text-scale)

Try it in Chrome 138+.