News for hackers. Stuff that matters.
Re:User Interface Typography by arp242 on Monday December 11, 2023 @06:14AM (#38599553)
Browsers don't treat "px" as actual pixels the monitor renders.

em "relative sizing" is still "relative to some pixel value". The default is 16px so 1.1em is just the same as 17.6px.

"cm" is also defined to be a certain number of px.

The website has no idea if you're using a high DPI monitor or just zoomed out to 25%. To say "always appear as exactly 1cm to the user" would obviously not be desired as you would lose the ability to zoom.

Re:User Interface Typography by bruce343434 on Monday December 11, 2023 @07:14AM (#38599917)
I'd say absolute sizes would be desirable for e.g. displaying the true size of a real life object, like an A4 page or a coin.
Re:User Interface Typography by culi on Monday December 11, 2023 @08:36AM (#38600503)
then you would utilize the @print media selector and probably rely on `in`, `cm`, or `mm`. Not `px`, `em`, or `rem`
Re:User Interface Typography by TheFuzzball on Monday December 11, 2023 @01:22PM (#38603326)
Having tried to print a physically-accurate scale on a non-commercial printer I would be surprised if a 1x1inch box actually measures the same in real life.
Re:User Interface Typography by chrismorgan on Monday December 11, 2023 @02:16PM (#38604133)
I’m confused and not sure what you mean. The device knows what size it’s printing at (e.g. A4 which is 210×297mm). One some devices with bad feeders you might get local error up towards 1% in the feed direction (probably <1‰ in the perpendicular), but on decent printers it’ll always be well below 1%.

If what you printed wasn’t accurate, something else was at play.

Re:User Interface Typography by TheFuzzball on Monday December 11, 2023 @04:20PM (#38605637)
Yeah it knows it's printing A4, but it can't print edge-to-edge, if you print a black rectangle the white borders are not a uniform size.

If you created a document using an A4 template and measured objects within this document using millimetres, when printed the objects would not be printed at exactly that size.

I know this because I've tried to do exactly that, and tried various permutations - on my specific printer I found that the warping was sometimes non-linear along the vertical axis! Maybe I've just got a particularly crap printer... Oh, Brother!

Re:User Interface Typography by chrismorgan on Monday December 11, 2023 @07:35PM (#38607557)
Being able to print edge-to-edge is not necessary, and is mostly to do with practical feeding limitations. Alignment on the sheet is also allowed to suffer. But of what it does print, I’ve printed and observed printed a number of precise things on several different printers (mostly lasers, but at least one inkjet and a phaser, way back) with no visible warping. ¯\_(ツ)_/¯
Re:User Interface Typography by boxed on Monday December 11, 2023 @06:22AM (#38599595)
Or in other words: people have misused px so bad it now literally does not mean px anymore because then the web would be unusable.
Re:User Interface Typography by arp242 on Monday December 11, 2023 @06:51AM (#38599784)
No; it never really meant "exactly one screen pixel". Even the CSS1 specification from 1996 doesn't say that: "If the pixel density of the output device is very different from that of a typical computer display, the UA should rescale pixel values. The suggested reference pixel is the visual angle of one pixel on a device with a pixel density of 90dpi and a distance from the reader of an arm's length. For a nominal arm's length of 28 inches, the visual angle is about 0.0227 degrees."

Doing something like this is the only way a single website can work across a wide range of screen sizes, DPIs, zoom levels, and things like that.

Re:User Interface Typography by ryandrake on Monday December 11, 2023 @11:16AM (#38601881)
I think this entire thread demonstrates why designers should not even be specifying text size. We should make better use of user-defined preferences, and browsers should make setting them up more prominent. Designers sitting in offices 3000 miles away from me should not be deciding how my browser renders text for me to look at.
Re:User Interface Typography by arp242 on Monday December 11, 2023 @12:53PM (#38602909)
You can't make any design with purely "user defined preferences" because none of the metrics will be reliable and if the settings deviate too far from the average things get all wonky pretty quickly, even for fairly simple designs.
Re:User Interface Typography by TheFuzzball on Monday December 11, 2023 @09:38AM (#38601005)
Re:User Interface Typography by kevincox on Monday December 11, 2023 @11:53AM (#38602215)
> The default is 16px

The default is absolutely not 16px. 16px is a common default value but different browsers and devices will have different defaults and most browsers will let the user customize their font size. By assuming that 1em == 16px you are ignoring the user's preference and likely making the text hard for them to read.

https://nicolas-hoizey.com/articles/2016/03/02/people-don-t-...

1rem == the font size of :root and 1em == the font size of the current element. It is true that these have some equivalent in pixels and 1rem very often is 16px. But that isn't guaranteed and shouldn't be assumed. You should respect the user's preferred font size.

Re:User Interface Typography by arp242 on Monday December 11, 2023 @12:38PM (#38602652)
> You should respect the user's preferred font size.

This is impossible because what's desired depends on the font. Of course I can foresee the "we should respect the user's preferred font" response, but that's also impossible because you don't know the font metrics of that are and then it turns out that stuff breaks because the font is tons wider or whatnot. This is also the problem with "respecting the font size". Never mind the aesthetical reasons for choosing a different font of course.

This is why browsers have zoom, which solves the problem without tons of downsides. It's not always perfect, but much more manageable for everyone. Firefox can set a default zoom level too, and it remembers the zoom level per-site.

For all practical purposes the default is 16px. All browsers ship with that as a default, and those that don't should be doing that. This entire feature is fundamentally broken and a holdover from the past.

Re:User Interface Typography by dutchCourage on Monday December 11, 2023 @03:08PM (#38604831)
>> You should respect the user's preferred font size.

>This is impossible because what's desired depends on the font.

I'm confused by this statement. Let's say I'm using a font that looks smaller than average. To compensate for that I (the developer/designer) set the font-size of my body text to 20px instead of 16px. Using rem, it'll be 1.25rem.

Now when someone with bad eyesight comes on my website and they have their default font-size set to 18px instead of 16px, the body text is 18*1.25=22.5

They will still see a larger text (22.5px) than the average person (20px), regardless of the font I picked.

If I had set the font-size in px, everyone would get the same size regardless of their preference.

Re:User Interface Typography by kevincox on Monday December 11, 2023 @12:48PM (#38602834)
I think you have some good points, but others just don't make sense.

> you don't know the font metrics of that are and then it turns out that stuff breaks because the font is tons wider or whatnot

Your site breaks so you make the text too small for the user to read? Browsers also have accessibility options to override website's custom fonts. So your site is broken either way, best to fix it an let the user have their preferred experience than mitigate it for some users and leave other users broken.

> This is why browsers have zoom, which solves the problem without tons of downsides

Zoom is great as well. But what downsides does it avoid? If the user wants their text wider your layout that assumes a max width for text is still going to break. The main downside that it avoids is web developers assuming that 12px text is easy to read.

I could argue that zoom is a hack to mitigate websites that use px for things that need to be readable. It scales px, which fixes a problem that wouldn't exist in the first place if the developer just used em.

> All browsers

Not all browsers. But most common browsers.

But I think at the end is what is the point of all of this? You are dismissing an approach with clear upsides without arguing what advantages the px approach brings. Sure, maybe most browsers are 1rem == 16px and maybe zoom is a good enough mitigation. But what advantage do you get by relying on this? I think you are right that browsers have done lots of good work to mitigate sites that set the body text to 12px, but it still seems that doing that doesn't have any advantages over just using em.