WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
NEW
260880
WebKit does not respect system font size for rem units
https://bugs.webkit.org/show_bug.cgi?id=260880
Summary
WebKit does not respect system font size for rem units
James Please
Reported
2023-08-29 15:05:16 PDT
Context: Operating systems regularly allow users to set a custom font size scale. This can be useful for users who have vision problems, for example. It is a best practice for software, including web pages, to respect this font size setting. In the browser, the way to accomplish this is with rem units. And in fact, all browsers except for Safari work this way. To confirm this, you can create a webpage with the following CSS: ``` p { font-size: 1rem; } ``` And create a paragraph element with text. On any OS and any browser (except Safari) you can open this webpage and then change your system-level font scale setting. Observe that the text in this paragraph will match the system-level scale value. The problem: Safari always renders `1rem` as `16px`. A possible workaround: Sources on the web suggest the following workaround: ``` html { font: -apple-system-body; } ``` This does work to make Safari respect font size settings, but it introduces a new problem on macOS. It sets the "unscaled" value of 1rem to be 13px rather than the normal 16px. The consequence of this is that all text will display smaller on macOS. Proposed solutions: (1) The best solution for developers would be to update Safari so that it treats rem units the same as every other browser. (2) A stop-gap solution would be a new webkit-only prefix that would *only* enable the dynamic font size, but not change the base font size value nor the font-family. Something like: ``` html { font-size: -apple-system-font-size; } ``` (3) If the Webkit team thinks that Safari is actually treating rem units correctly and that everyone else is doing it wrong, then the web platform needs a new solution to respect the OS-level font scale setting.
Attachments
Add attachment
proposed patch, testcase, etc.
Radar WebKit Bug Importer
Comment 1
2023-08-29 15:05:25 PDT
<
rdar://problem/114662159
>
James Please
Comment 2
2023-09-19 07:22:51 PDT
This is still a problem on Safari 17. Reproducible example:
https://jsfiddle.net/7ub8362m/
I consider this to be a major bug as it means that users of Safari are unable to use browser or OS-level font size settings, which is one of the most common a11y settings configured on devices. Is the Webkit team able to confirm if this is a bug or if it's intended behavior?
Daniel
Comment 3
2024-01-08 13:54:33 PST
Also curious about this - would love being able to respect the iOS font size system option
Daniel
Comment 4
2024-01-08 14:10:26 PST
I think this is an ok workaround: ``` @supports (font: -apple-system-body) { @media (hover: none) { html { // Respect iOS font size settings font: -apple-system-body; } } } ``` The idea is to exclude macOS by only applying the rule to touch devices, since all iOS devices are touch devices and none of macOS are. However I noticed that even on iOS `font: -apple-system-body` seems to set another font size than the standard size, but you can compensate for that with something like this (note that this site has a slightly larger base font size so you can't just copy paste below): ``` body { // base font size font-size: 1.15rem; @supports (font: -apple-system-body) { @media (hover: none) { // -apple-system-body on iOS has a slightly different base font size, respect the one from before font-size: 1.085rem; } } } ``` I came up with above values by looking at the computed styling and making sure they match, pre and post adding the `font: -apple-system-body;`
James Please
Comment 5
2025-05-06 07:41:35 PDT
Any updates here? This is a pretty substantial a11y regression that's been present in Webkit for several years now. rem and em units are completely broken in Safari.
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug