3 ms·
> It's still a mistake to tie layout to the resolution of a web page You've got to tie it to something. Your argument falls apart because "em" are still define
by crazygringo 6y ago
> It's still a mistake to tie layout to the resolution of a web page
You've got to tie it to something. Your argument falls apart because "em" are still defined in terms of "px" at the root element. You're always defining layout relative to a logical resolution. Also, responsive design reports viewport widths in logical pixels, so logical pixels are still what everything is ultimately tied to.
> Set Firefox to Zoom Text Only (View->Zoom)
Nobody does that anymore. That was how browsers zoomed two decades ago. For a long time now, browser zoom defaults to zooming all content, i.e. logical pixel size. Heck, Chrome doesn't even have a text zoom option anymore. I'm actually surprised Firefox still does -- maybe it's a backwards-compatibility thing?
It's true that maybe two decades ago defining sizes based on em was a best practice, precisely because browsers only zoomed font sizes. But that ceased having relevance a long time ago, once browsers stopped using text zoom (except as an obscure setting).
Today, in the browsers and browser settings 99% of people use, px vs em has zero difference for the user. It's just a matter of programming taste. (Especially now that it's generally recommended to use rem over em anyways.)
- danShumway 6y ago> because "em" are still defined in terms of "px" at the root element No they're not, they're tied to the resolved font size of the current element they're in. That matters if someone overrides part of the CSS, so even from a pure engineering perspective this makes a real difference. It also matters if the user changes the font size of their browser. `em` units define font size in relation to the current font size. That font size might be set elsewhere in CSS using pixels, it might be set by the browser. It might be set using viewport width, it might be set using percentages. It might be set in pixels and overridden by the user using the browser's minimum font size feature. In all of those cases, as a designer you will be glad that you used `em` units for container width and child text rather than pixels. > Nobody does that anymore. That was how browsers zoomed two decades ago. This is how Firefox's default font sizing works today. I listed that zoom option so it would be easier for you to play with it, that's the only reason. But if you go into your settings and change the default font size of the browser (which is absolutely something that people who have bad vision still do today), then you will see the same result in the JSFiddle I linked.
- crazygringo 6y ago> This is how Firefox's default font sizing works. That's misleading. Firefox's default zoom sizing zooms fonts together with everything else. Virtually nobody uses font-only zooming. People with bad vision still overwhelmingly use page zoom -- because if your vision is bad you need everything enlarged, including things like icons and images. Also, your description of how font size for em's is set is incorrect. It's always set ultimately relative to px. If set by the browser, it's a default stylesheet that specifies "body { font-size: 16px; }". It cannot be set as a percentage of viewport size using HTML/CSS, that doesn't exist as an option in font-size. If the browser sets a minimum font size, that too is ultimately in px. Your whole argument hinges on people using font-zooming, when that died for all intents and purposes many, many years ago. There's no reason for web designers to accomodate nonstandard font zoom anymore -- forcing all UX units to be in ems just re-implements page zoom using text zoom, which is utterly redundant. Use px or use rem, they're functionally equivalent -- it's just a matter of developer preference.
- danShumway 6y ago> Virtually nobody uses font-only zooming. I don't know how you can claim this. I have set up multiple computers for elderly people and taken advantage of that feature. Heck, I have taken advantage of that feature on devices with weird aspect ratios like the older Surface Pros. > It cannot be set as a percentage of viewport size using HTML/CSS, that doesn't exist as an option in font-size What? font-size: 1vw; > If the browser sets a minimum font size, that too is ultimately in px. This is being pedantic. If a user or a parent container is setting the font size, that is clearly a different scenario then setting it in the container itself. If you're going to go down this route we might as well claim that browser fonts are set based on physical pixels as well, since ultimately the browser resizes its internal representation of pixels based on the device aspect ratio. > it's just a matter of developer preference. I don't know any experienced developer who writes CSS for a living that would claim this. Pixel-based CSS files are a nightmare to maintain when nesting components, this makes a tangible difference to how you architecture your CSS files.
- 6y ago
- tracker1 6y agoChrome on mobile absolutely has a text zoom, it's exposed as an OS function, but chrome respects it... my vision is not great, so in accessibility settings I have fonts set to largest. Chrome does a decent job (as most Android UI) of respecting this. The apps that don't, or don't do it well (Facebook) are the ones that are particularly annoying. It may not be exposed in the browser directly, but the functionality is definitely there. edit: and I'm frankly okay with using px/pt for the baseline font at the root level and using em/rem elsewhere. In the end, I understand that it should be 72pt/in and 96px/in as far as CSS goes... others may not... Devices that don't have their actual PPI set so browsers can properly calculate the CSS dimensions is slightly annoying though. But that's been a bit craptastic forever and a day. In the end, nothing will ever be close to perfect. I do find it annoying that different fonts with the same size and line-height will render far differently... a 12pt font should render (roughly) 6 lines per inch.
- kevin_thibedeau 6y ago> Nobody does that anymore. I use Ctrl+'+' all the time to zoom text.
- kalleboo 6y agoThe default behavior of Ctrl-+ (and the only behavior in Chrome, Safari, Edge) is different from Firefox's "Zoom Text Only". Just hitting Ctrl-+, it eventually switches to the mobile stylesheet https://i.imgur.com/E7rAR37.png https://i.imgur.com/E7rAR37.png With "Zoom Text Only", the layout partially breaks and you get columns of text with only one word per line https://i.imgur.com/C5NiyFA.png https://i.imgur.com/C5NiyFA.png
- ddingus 6y ago>Nobody does that anymore. It's used as an accessibility option for people with low visual acuity.
- mcguire 6y agoNobody does that anymore. /s
- runarberg 6y ago> now that it's generally recommended to use rem over em anyways. Whoa! Apparently I missed the note on that one. I very much favor using em over rem precisely because it is relative to the current font size. This is especially nice with SVG icons: <h1> <svg class="svg-icon"><use href="sprite.svg#my-icon" /></svg> Some Heading </h1> h1 { font-size: 1.5rem; color: rebeccapurple; } .svg-icon { fill: currentcolor; height: 1em; width: 1em; } Do you care to tell me why em units are not recommended anymore, and who it is recommending rem in favor of em?
- giantrobot 6y agoYour specific example is an exception to the "rule". The em measure is relative to the font size of the last containing element that specified an explicit font size. So with a heading, a 1em x 1em icon makes sense because it'll be the height of the container h1 element (which you set as 1.5rem). The rem unit is relative to the base document font size. Your icon in an h1 set to 1rem x 1rem would be sized relative to the body's base font size. In your example a 1rem icon would be .66 the size of your h1. When you use rem units consistently their size is more predictable throughout the document. If you've got a complicated stylesheet overriding sizes all over the place em units can end up inconsistently sized and tricky debug. I've seen rems recommended for probably the past ten years or so.
- runarberg 6y agoI think there are many of these “exceptions”. At the top of my head: * Make inline code (say: `0.85em`) relative to fit equally nicely in a big heading or in a smaller `<aside>`. * Margins and paddings so that larger font sizes have more spacing between them and more breathing room * Column width where you want to fit a certain amount of character at most in a single column (say `grid-template-columns: repeat(auto-fit, 30ch)`) * Max container width of a text heavy container is probably best specified in `ch` units (say `max-inline-size: 120ch` is a good one) as long tines are hard to read. If you later decide to use a larger font, you don’t need to change this value like you would have if you’d use `rem`. I could go on... But I really doubt this is a good rule. And I am skeptical that any serious front end developer is recommending against units that are relative to the current font size.