Repository navigation
Description
This issue was discovered while implementing #7124, and when several EUI team members brought up recommending against px units as less accessible than rem and em.
Problem
By default, EUI sets a global pixel value font-size on html:
| font-size: ${`${font.scale[font.body.scale] * base}px`}; |
(Note: This value is unaffected by / does not respect the new defaultUnits token implemented in #7133).
What this means is that EUI does not respect user-set browser settings for default font sizes. Most browsers default this to 16px, but if a user wants a default font size of 32px (e.g. for vision issues), EUI will completely ignore that setting:
The above screenshot is of Firefox on MacOS, but this has also been reproduced and confirmed on Chrome as well.
Reproduction
- In your browser settings, change your browser default font size from 16px to any other value
- Go to https://eui.elastic.co and confirm that EUI does not adjust dynamically
For comparison, other websites that do respect custom user/browser font size:
- https://polaris.shopify.com/
- https://www.nytimes.com/
And other websites that also do not respect user/browser font size:
- https://fluent2.microsoft.design/
- https://github.com/
- https://www.google.com/
Proposed solution
To be clear, EUI has not respected the browser default font size since its inception (i.e., well before the Emotion conversion). To "fix"/change this now would potentially be a major breaking change for consumers or an unexpected surprise for users. If we want to change the default font size we set on html to be more accessible going forward, we need to make this choice very deliberately, and communicate that clearly to our consumers as well.
It might also be worth discussing the approach we want to take:
- Have the
htmlfont size respect the newdefaultUnitstoken, which means potentially allowing consumers to deliberately choose to make their applications less accessible (does this have valid use-cases?) - Have the
htmlfont size always be relative (e.g. using%instead) and ignoredefaultUnits
Activity
cee-chen commentedon Aug 29, 2023
CCing in the folks who had opinions on this during our sync today: @1Copenut @kyrspl @mdefazio
I'll bring this up at our next week's meetings as well for more discussion if we'd rather wait until then, but wanted to start this thread now for async thoughts in the meanwhile.
One thing that I strongly think is worth discussing: big name tech companies like Google, GitHub, and Microsoft (see links in PR description) follow this same pattern of ignoring browser default font sizes. Is this an oversight or a deliberate decision? What do they know that we don't? Does a more consistent visual experience trump user customization in this case, especially since browser zooming already exists?
To be clear, I don't necessarily agree with the above questions, but I want them to at least be discussed.
mdefazio commentedon Aug 29, 2023
I think I like this approach if i'm understanding the implications correctly.
We would still have a default for this token and a font-size would still be assigned to the html tag, right? So EUI behaves the same out-of-the-box with this change? It's just a matter of possible (poor) customization?
My gut reaction:
1Copenut commentedon Aug 29, 2023
I prefer the second option
The new
defaultUnitsprop is incredible. It puts consumers squarely in control of their applications and how they're represented. It also means consumers are free to build less accessible applications. I am okay with this as a fact for a few reasons:pxas their preferred CSS unit, users can still use browser zoom to make text and layouts largerMaking our default
html { font-size: 87.5%; }normalizes to 14px, but honors users' preferred font sizes across all browser tabs, not just a tab-specific zoom rate.Now, with all that said, there's a very non-zero risk to making this change. It'll be a manual QA effort and should have a long public comment period so there's no surprises when we make the cutover.
cee-chen commentedon Aug 29, 2023
Yes, that's correct. With our current
remdefault unit, ourhtmlCSS would change fromfont-size: 14pxtofont-size: 0.875rem.Just to clarify,
remandemis responsive to default browser font size changes (the same way that%is), it's just a question of whether we want consumers to be able to specifypxas well and make their app purposefully less accessible. Our newdefaultUnitstoken essentially allows them to do that anyway, so it's just a question of making thehtml {}global CSS the same way.cee-chen commentedon Aug 30, 2023
Just realized I missed a couple of (really excellent) questions from Defazio:
I think the answer is broadly yes, but I also think the accessibility benefit of allowing users to tweak their default font size outweighs this concern.
At this point we've already made
pxa specifiable unit (it's been in our types ever since the Emotion conversion, even though we don't use it internally), and it would be a breaking change to remove it. To be honest I don't think it would be worth it to do so. Consumers could go in and manually override every single one of our CSS selectors with their own font sizes and!importants anyway - at some point there is only so much control we have and we have to realize most of our value comes from sensible defaults and recommendations/warnings, but after that being overly restrictive does not benefit either us or the consumer.Yes - @y1j2x34 had a perfectly valid one in #7124. Their use-case is that they're using EUI for a browser extension, not a webpage. Their app renders on any website on the internet, which could be setting any font-size on the root
html {}. They don't want their extension to inherit from random font sizes, and would prefer to usepxfor that reason.For that use case, there literally isn't an accessible solution that respects browser default font sizes (because if the random website on the internet isn't using relative font sizes, neither does the extension). The only workaround the extension would have to make their font sizing more accessible would be to allow users to customize the app's base font size - which again, we can add a note and recommendation in our docs, but we can't do more than that.