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):
legacy or no meta: the OS scale on mobile, but always 1 on desktop.scale: the OS scale on every platform. The root font size is scaled too, so this page pins
body to 16px to show the difference..scaled {
font-size: calc(16px * env(preferred-text-scale, 1));
}
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
On desktop, emulate the OS text scale from DevTools (the --blink-settings=accessibilityFontScaleFactor flag had no effect in Chrome 157 Canary on macOS):
Emulation.setEmulatedOSTextScale with {"scale": 2}, then reload the page.This is a demo for env(preferred-text-scale)
Try it in Chrome 138+.