Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessibility fix: Allow iOS browsers to auto-scale fonts based on user preference #34107

Open
chrislachance opened this issue May 25, 2021 · 12 comments

Comments

@chrislachance
Copy link

Please add font:-apple-system-body to the :root element CSS to allow iOS devices to auto-scale font sizes based on user preference set in Accessibility > Display & Text size.

@chrislachance
Copy link
Author

See this Codepen for the full code example. https://codepen.io/chrislachance/pen/OJpmgrM

@ffoodd
Copy link
Member

ffoodd commented May 26, 2021

Wrapping a few resources for the record:

So to sum up my findings, I'd be in favor of trying this and heavily test the dedicated branch on iOS and MacOS browsers, since it's known to be tricky.

BTW @chrislachance what kind of "weirdness" does desktop Safari, that worth mentioning in your pen?

@chrislachance
Copy link
Author

chrislachance commented May 26, 2021 via email

@ffoodd
Copy link
Member

ffoodd commented May 26, 2021

Do you have any link or resource to share regarding this? Currently unable to find any relate resource from Jonathan Neal on the topic :/

@chrislachance
Copy link
Author

csstools/sanitize.css#219

@ffoodd
Copy link
Member

ffoodd commented May 27, 2021

X-ref from other repos to keep an eye on the topic

Not much discussions for now apart from Jonathan Neal on sanitize.css.

@chrislachance
Copy link
Author

chrislachance commented May 27, 2021 via email

@montygoldy
Copy link

"font:-apple-system-body" this solution not working for android chrome

@chrislachance
Copy link
Author

chrislachance commented May 30, 2021 via email

@jefferyto
Copy link

jefferyto commented Jun 4, 2021

Looks like Apple is unwilling to change User Agent Stylesheet at the moment as well.

At the default system text size, -apple-system-body appears to set the font size to 17px. I imagine even a 1px difference (from the assumed 16px default for the root/html element) may break a lot of layouts in the wild. This may also make it untenable to include as a default for any major CSS framework.

@chrislachance
Copy link
Author

Unfortunately, you may be right. But doing it anyways may be the right thing to do.

@tedw
Copy link

tedw commented Mar 16, 2023

FWIW here’s is how I have been doing this for the past few years:

// Support iOS accessibility text size
// Note: Only apply on iOS due to bug with Safari 14 on Big Sur
// https://webkit.org/blog/3709/using-the-system-font-in-web-content/
// https://www.interactiveaccessibility.com/blog/text-resizing-web-pages-ios-using-dynamic-type
// https://dev.to/colingourlay/how-to-support-apple-s-dynamic-text-in-your-web-content-with-css-40c0
// https://gist.github.com/colingourlay/d95908ec5cd4854c7a5afa06f3989479
&.ua-ios {
  @supports (font: -apple-system-body) {
    font: -apple-system-body;
  }
}

FYI the ua-ios class is added to the <html> tag via a small bit of inline JS in the <head> (see example below) but you could remove that if you aren’t supporting Safari 14 on Big Sur.

Update: See this SO post for an updated way to detect iOS https://stackoverflow.com/a/9039885/673457

// Detect iOS
// http://stackoverflow.com/questions/9038625/detect-if-device-is-ios/9039885#9039885
if (/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream) {
  document.documentElement.classList.add('ua-ios');
}

FWIW I also use this bit of CSS to ensure form fields don’t zoom on iOS, which happens if the font size is below 16px.

// Prevent zoom on iOS
// https://css-tricks.com/16px-or-larger-text-prevents-ios-form-zoom/
// http://www.456bereastreet.com/archive/201212/ios_webkit_browsers_and_auto-zooming_form_controls/
:where(input, select, textarea) {
  font-size: max(1em, 16px);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants