Created
March 10, 2022 15:03
-
-
Save tedw/a85955f1cf0a9865ff844a991bcfe641 to your computer and use it in GitHub Desktop.
CSS for supporting iOS accessibility text size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var ua = navigator.userAgent, | |
d = document.documentElement, | |
classes = d.className; | |
// Replace 'no-js' class name with 'js' (optional) | |
classes = classes.replace('no-js', 'js'); | |
// Detect iOS user-agent string | |
// http://stackoverflow.com/questions/9038625/detect-if-device-is-ios/9039885#9039885 | |
if (/iPad|iPhone|iPod/.test(ua) && !window.MSStream) { | |
classes += ' is-ios'; | |
} | |
// Apply classes to <html> element | |
d.className = classes; | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
html.is-ios { | |
@supports (font: -apple-system-body) { | |
font: -apple-system-body; | |
} | |
} | |
// Set the desired font-family on <body> since we’re applying “-apple-system-body” on <html> | |
body { | |
font-family: "My Custom Font", -apple-system, BlinkMacSystemFont, Segoe UI, sans-serif; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment