Honoring Mobile OS Text Size
Honoring Mobile OS Text Size êŽë š
If your users scale the text size in Android or iDeviceOS, that doesnât always affect the size of text on a web page. Itâs a function of browser and authored code, as opposed to a standardized approach. That may be changing.
Support
The current state of affairs in the three rendering enginesâŠ
Firefox on Android supports scaling a web pageâs text if you adjust the system font size. It doesnât seem to care if you use px units. You donât need to do anything special; it just works.
Safari will not scale a web pageâs text with the OS settings unless the author adds some CSS. This code points to the system font properties (such as size):
body {
font: -apple-system-body;
/* other styles, including font-family */
}
This feature query checks for support while trying to limit it to touch devices only, then sets the font size:
@supports (font: -apple-system-body) and (not (-webkit-touch-callout: default)) {
:root {
font-size: 100%;
}
}
The rest of your styles have to use relative units or this breaks down.
Google has opted not to follow Firefoxâs lead and support OS text sizes by default. Google has also opted not to mimic Safari and make platform-specific features. Instead, Google has decided to use its weight in the CSSWG to mint a new value for the <meta> element:
<meta name="text-scale" content="scale">
For this to work, however, the author will need to âopt-inâ by not setting a base font size in your CSS:
body {
/* font-size: yeah, no */
}
You actually can set one, but it should be a percentage. You then need to avoid fixed units (such as px) throughout your site. If this seems familiar, itâs the core thesis of my aptly-named post The Ultimate Ideal Bestest Base Font Size That Everyone Is Keeping a Secret, Especially Chet.
Info
Read Josh Tumathâs post Try text scaling support in Chrome Canary for more details.
Frankenstyleâs Monster
Letâs combine those into one set of code that will work in Safari and now Chrome. Firefox was always on point, so no effort needed there.
Add this HTML to the <head> of your page (itâs the CSSWG code):
<meta name="text-scale" content="scale">
Add this to the CSS of your page (itâs Appleâs code):
body {
font: -apple-system-body;
/* other styles, including font-family */
}
@supports (font: -apple-system-body) and (not (-webkit-touch-callout: default)) {
:root {
font-size: 100%;
}
}
Done.
Frankenstyleâs Demo
I made a demo. It has images and a table. Visit the debug version (aardrian) in your mobile browser.
How to Test Frankenstyleâs Demo
Seriously, visit the debug version (aardrian) in your mobile browser. Iâm not dealing with desktop here.
With your Android device, install Chrome Canary from the Google Play store. If you are using an Android device with another app store, I leave it to you to sort that out. Then, using chrome://flags, enable Experimental Web Platform Features in Chrome Canary.
Android
In Android, go to Settings â Accessibility â Display size & text; in the Size options section, go to Font size and make it as large as possible.


The smallest Android text size setting and then the largest setting.
iDevices
In iDevices, go to Settings â Accessibility â Display & Text Size â Larger Text, toggle Larger Accessibility Sizes, then drag that slider all the way to the to max.


The smallest iPadOS text size setting and then the largest setting.
My Results from Frankenstyleâs Demo
These are before (small text) and after (largest text) images of Frankenstyleâs Demo. Your experience may differ. If youâre reading this from the future, it may differ a lot.
None of these required a browser reload. It may take a moment, so be patient.
Firefox


Frankenstyleâs Demo in Firefox on Android, behaving just as it would without the Frankenstyles.
Safari


Frankenstyleâs Demo in Safari on iPadOS. I scrolled the second one a bit to show the inline images.
Chrome Canary


Chrome Canary showing Frankenstyleâs Demo.
Other Reading
Things that may better inform those words and pictures above:
- CSSWG: Explainer: meta tag for text scaling behavior (
w3c/csswg-drafts) - CSSWG: Explainer:
env(preferred-text-scale)(w3c/csswg-drafts) (not addressed in this post) - CSS Fonts Module Level 5 §2. Text-Scale
<meta>element - Even though CSSWG issue OP suggests the
<meta>might better belong in WHATWG HTML (w3c/csswg-drafts), I could find no corresponding issue with WHATWG (whatwg/html). - Just as I was about to post this, I learned Manuel Matuzovic wrote A new meta tag for respecting text scaling on mobile just this morning.
- Yesterday Nat Tarnoff made the point that replicating platform features in the browser (ahem, overlays) is a poor idea, and this increased OS-level support bolsters his argument: Quick Tip: Do Not Replicate OS Behavior.