by somat · 3mo ago · 0 comments
Is there a way to use real pixels? My, admittedly quick, search says no. at least nothing jumps out at me from the spec.
if the user's operating system is configured to draw pixels at a 1:1 ratio, your pixels will be drawn at a 1:1 ratio. if the user's operating system is configured to draw pixels at a 2:1 or 3:1 ratio, you as a web developer don't get to override that, but you're still addressing pixels directly. if you want to write software that manages the user's hardware directly without giving them options to override it, the web is probably not the right platform for you.
https://drafts.csswg.org/css-values/#absolute-lengths
I guess theoretically a tv could say "this tv will be viewed at 12 feet away so our reference pixel is 1/16 inch" and still be in spec. Which sounds like it has messy implications, Does anyone do this?
Anyway the point being a pixel should fundamentally be a hardware measurement, and if they wanted a "visual angle unit" they should have introduced one.(the moa?) But the last thing we need is a pixel being defined as a hard 1/96 of a inch. which is what we got.
Screenshot: https://www.softacom.com/wp-content/uploads/2022/03/11111-10...
I guess you could use that setting on an old version of windows to set a screen to 16dpi, and now a CSS reference pixel is 1/3rd of a real pixel? But more realistically, what the spec is getting at is that a mobile device should set its dpi setting close to the real device setting, and a reference pixel is now something that looks about as big as a pixel on a 96dpi screen. That nobody actually sets their screen dpi on desktops is probably of secondary importance to them
pixels are pixels, and no browser implements them as a fractional-inch measurement. in every actual implementation i'm aware of, they're a hardware based unit.
Screens very rarely contain a matrix of individual squares.
For example - https://global.samsungdisplay.com/29043/
body { --resolution-scale: 1; }
@media (min-resolution: 2dppx) { body { --resolution-scale: 2; } }
@media (min-resolution: 3dppx) { body { --resolution-scale: 3; } }
.myPixelSizedElement { width: calc(96px * var(--resolution-scale)); }
But unfortunately there's no way to directly use the devicePixelRatio value you can read from Javascript directly in a CSS calculation to be able to get a precise scaling on any arbitrary pixel density.The indirect way is for the JS to post the metric to the server, then you run with server-generated CSS. Don’t ask me if it actually works well though.
You definitely can't get pure integers though it's always a float even if you use whole numbers. It does eventually get rounded before becoming pixels though.
As an aside, technically, yes, it may have been better to converge on some more clearly "fake" unit rather than calling it a pixel but for me that's a nit pick.
But even in CSS1 (1996), a "reference pixel" based on a typical 90 DPI monitor was recommended. You could argue its always been broken
The problem with different screens having different pixel densities was already present and obvious in 1996.
"Real" pixels are useless if you don't know anything about the screen you're going to render on.
Unfortunately, Retina gave us a nonsensical and hacky “scaling ratio” rather than separate and independent units of physical length, viewing angle, and interaction granularity. (I still can’t get an A4 PDF in GNOME to display at “100%” such that it would actually be 210mm wide on my screen. And Darktable is the only piece of software I know where you can configure ppi and ppd separately.)