Open noahmanger opened 8 years ago
There's a pretty similar discussion to this going on here: https://github.com/18F/web-design-standards/issues/992
I'm leaning towards the opinion that you shouldn't touch base font size (leaving it at 100%) and just deal with some math when you use rem and em values. From reading different things, I'm not sure there is a best practices, seems like many people are doing different things.
One thing as mentioned in the standards issue: there are potentially accessibility/browser issues when you set your base font size to a px (and maybe even percentage) value. As an organization that highly values accessibility, I think it should be of higher priority then developer ease when determining our standards on this.
Some research on what other sites and style libraries are doing:
100%
on <html>
, 875rem
on <body>
10px
on <html>
, 14px
on <body>
100%
on <html>
, 100%
on <body>
100%
on <html>
, 100%
on <body>
15px
on <html>
, none on <body>
62.5%
on <html>
, 160%
on <body>
<html>
, 16px
on <body>
0.75em
on <html>
, none on <body>
100%
on <html>
, 100%
on <body>
100%
on <html>
, 100%
on <body>
18px
on <html>
, 18px
on <body>
100%
on <html>
, 62.5%
on <body>
100%
on <html>
, 14px
on <body>
100%
on <html>
, 100%
on <body>
100%
on <html>
, .875rem
on <body>
10px
on <html>
, 100%
on <body>
10px
on <html>
, 16px
on <body>
100%
on <html>
, 14px
on <body>
18F/Gov:
<html>
, 1em
on <body>
10px
on <html>
, 16pt
on <body>
62.5%
on <html>
, 1.5em
on <body>
18px
on <html>
, none on <body>
<html>
, none on <body>
100%
on <html>
, 1rem
on <body>
62.5%
on <html>
, 1.5rem
on <body>
10px
on <html>
, 14px
on <body>
100%
on <html>
, font-size(1)
? on <body>
100%
on <html>
, none on <body>
<html>
, 0.875em
on <body>
<html>
, 18px
on <body>
62.5%
on <html>
, 1.4rem
on <body>
100%
on <html>
, 1em
on <body>
@noahmanger do the issues with other libraries still happen if you set:
html {
font-size: 100%;
}
body {
font-size: 62.5%;
}
?
@maya, thanks! I'll try that out..
Hmm. Yeah worth a shot. We set a lot of the spacing and component font sizes as rem
, which will change the way the fec-style stuff is sized if html { font-size: 100%}
, right? But maybe it would be better to set more of that with ems
.
On Thu, 2016-04-28 at 10:36 -0700, Noah Manger notifications@github.com wrote:
Hmm. Yeah worth a shot. We set a lot of the spacing and component font sizes as
rem
, which will change the way the fec-style stuff is sized ifhtml { font-size: 100%}
, right? But maybe it would be better to set more of that withems
.
Yeah, my thinking was that using ems
, you could scale a component's
size just by changing the font-size
of that component. Increasing the
html
size would similarly scale up all the components.
When using rems
, you don't have have the option of adjusting a single
component. I've never built a component library before, so I don't have
much practical experience here.
Aaron D Borden Human and Hacker
@noahmanger on WDS, we currently have what I posted above and 1rem still equals 10px. You end up having different base ems and rems, tho. I just posted it above to see if it would help in the meantime with your issue.
That being said, we're still exploring if this is the right overall solution, given everything @msecret posted.
Ah! I didn't realize that. In that case, it might just work :finerscrossed:.
Yeah, I'm sure there's a smart way to do sizing by balancing rems and ems to get some of the cascade benefits @adborden . The challenge is always having unintentional cascades, a problem that rem sizing is meant to fix.
Ok, turns out we still set html to 100% on WDS, but have been thinking about doing what I posted above, we just didn't arrive at a solution yet. I think what I posted was backwards: if you used that, 1rem = 16px (or browser settings) and 1em = 10px. To answer your question @adborden, rem would come form html and em would come from what was set next or 62.5% in this case.
Is that right?
Thats an interesting idea: have each component set it's own font-size and then have all measurements in the component be em
so it won't break when the html
font size changes. That being said, the more global tag based rules would still break because they'd be off the global size.
I'm also not sure I like the solution of using em
s on one style library and rem
s on another just to ensure they can work with each other. I think em
s and rem
s both have valid use cases within a site, so that feels to be breaking how you could potentially use them successfully.
I don't know that setting a font size for every single component is the right way to go either, feels like you'd want a typographic system that serves all components in a predictable way.
The solution here could even be more brute force: set a standard across 18F and create tools to make it easier to modify all your existing font sizes in your code to update to the standard.
Next steps: we have to determine the accessibility concerns with setting a global font size in px and in % (they might have different concerns). This will likely mean more in depth research on what others in the accessibility and front end community have found and potentially our own research with accessibility tools and settings.
Currently the frontend guide recommends setting global font-size in pixels:
And then setting everything else in REMs.
In FEC Style we follow the recommendations originally described here and set:
This defers to the default font-size users set in their browsers, rather than overriding it to a pixel value (a usability and accessibility win, AFAICT).
But! As @adborden points out here, this poses issues when trying to integrate our style repo with other libraries that depend on font-size being set to 100%.
I haven't kept up-to-date on the current thinking around best practices on this, so I'm not sure what to do. But wanted to open an issue for discussion.