One inch is not an inch

I disagree. This is why we need to have access to pixel density and the screen size of the display so that we can make informed decisions. For example, if my app knows that the screen size is 30 inches by 40 inches and the pixel density is X, then my app would know it is running on a huge display, and it will adapt accordingly. My app therefore wouldn’t display a tiny 1-inch thing, but instead something bigger.

For those of us that wouldn’t want to take advantage of that luxury (you for example), the spec would need for browsers to behave as they do currently do by default. The only difference would be that someone like me (who does want this) would have the option to take advantage of such information.

In the current state of affairs, “1 inch” not being an inch is just plain wrong, IMHO.

Browsers would by default continue to behave like they currently do. This new feature I’m imagining would be opt-in, so that if people want to take advantage of it they can.

The “new problems” that you mention would only be there for people who opt-in, and I would be one of those people dealing with those new problems, but by default, you certainly wouldn’t have to.

Cheers and happy new year! :}

would only be there for people who opt-in

and those who just cargo-cult/copy paste from other projects without understanding the potential implications of this foot-gun

and I would be one of those people dealing with those new problems

as there’s no solution to it though (unless you make separate sites for mobile, desktop, TV and do browser/UA sniffing to try and redirect people to the correct one), it still sounds dangerous to me to add this particular component while the ways to deal with it correctly in different scenarios aren’t available.

That applies for anything in any programming language, so isn’t a good argument against this feature. It’s not the best idea to just paste anything all the time without knowing what it does.

As I mentioned, the default behavior would be the current behavior, and there’d need to be a way to opt-in. I personally don’t care if people who go pasting things blindly accidentally opt themselves in. That’s what they get for pasting blindly.

Idea: What about a set of new units like rin, rcm, etc, where the letter r prefixed in front of them stand for “real”, so “real inch”, “real centimeter”, etc. Those units would be real when the hardware supports, otherwise they fall back to current behavior. Simple!

After having that unit, it’d become possible to do all sorts of things like make an invisible box of 1x1 rin, calculate it’s pixel size, and then use that info to get screen density, etc. It would then be possible to pass numerical pixel values to other JavaScript libraries (for example canvas 2d or webgl drawing libraries) that work in pixels (assuming the pixel ratio of the canvas to the document is 1).

Please don’t use other threads to continue to push for your “get the hardware pixel density” proposal.

1 Like

Instead of having us calculate real pixel density or physical screen dimensions based on a hidden DOM element, we could also be given some simple global to look at, containing float values:

window.screen.pixelDensity // in dots per inch? Different windows could have different densities depending on which display they are placed on.
window.screen.verticalPixelDensity // yes, the vertical density
window.screen.horizontalPixelDensity // could be different from the horizontal density.

The value of window.devicePixelRatio could also be configurable, using the viewport <meta> tag in the <head>.

// somewhere in the head
<meta viewport="name" content="device-pixel-ratio=1"/>

This would happen in the meta tag in the head so that it applies before rendering takes place. Now the content of the window would be rendered using the pixels of the device (in most cases, this matches one-to-one with the actual pixels of the device).

Additionally, there may be situation when a device pixel ratio of 1 doesn’t necessarily mean that the content is actually rendered one-to-one with the hardware pixels. It would be important to let these cases be more important, so that for example someone who tweaks defaults and wants everything scaled bigger or smaller on purpose won’t be disappointed. There should be a way to detect if this is the case or not, for example

if (window.devicePixelRatio == 1 && window.screen.matchesHardware) {
  // We know we have one-to-one drawing abilities with the display pixels.
else {
  // We know we don't.
  // Perhaps in this case there are other properties exposed like `permanentRatio` that can be used to handle certain cases.
  // Many developers will probably not have code here, but some of us would love to.

Alternatively, perhaps the spec could require window.devicePixelRatio to always be correct, even if the user zooms, or has some other OS-dependeny scaling, etc. This is totally possible to implement.

Those are just ideas, and would probably need to be refined, but essentially, I think have that control would be great. I can do it in native frameworks (Qt for example).

So, why not in the web?

I’d like to add that in Mozilla’s document describing the <meta> tag, in the section called A Pixel is not a Pixel, they mention themselves that

Peter-Paul Koch wrote about this problem in A pixel is not a pixel.

Acknowledging in general that this whole thing with pixels not being pixels… is a problem!

This is about CSS physical units not always perfectly corresponding to the real physical units. It has nothing to do with physical pixels, and getting access to physical pixels will not help any use-case presented here in any way.

Seriously, stop.

1 Like

@tabatkins I don’t feel I’m doing anything wrong by expressing the features that I’d like to have and/or opinions about those wanted features. Your attitude is not appreciated.

Since you’re a moderator, I’d expect you to be one of the last people here to have such an attitude, especially if you wish to welcome new discussion and ideas to the forum in general.

You don’t like the idea, but that’s not reason to tell me “Seriously, stop”. What do these forums exist for then?

Tab, haven’t you confused these (supposed to be) community-driven forums with a W3C mailing list? Have you read WICG best practices?

Substantively, physical inch is univocally related to physical pixel through physical PPI (pixels per inch) resolution.

“Hardward pixels” is unrelated to the OP. Threads exist for a reason, to segment topics. You’re right that I don’t like that particular idea, but that’s not why I’m objecting, it’s because it’s off-topic - in your first reply you attempt to shift the topic to pixel density, with a scenario that has nothing to do with the discrepancy between 1in and 1 inch; in a later reply you’re more explicit about proposing some API for pixel density, with the original topic nowhere to be seen.

If you’d like to continue discussing hardware pixel density, you already started a thread on it; that’s an appropriate place to continue, or you can start a new thread if you feel like it’s sufficiently different to justify that. But please stop injecting this topic into unrelated threads.


Mobile Safari could do this easily since it’s run on so few different devices. It’s kind of telling that it doesn’t.

Aren’t CSS units officially defined in terms of fractions of the user’s expected view angle?

Anyway, as I put it a while back on Twitter, the nomenclature of CSS units is like the naming of the units in the US Imperial system: there’s about as much point in complaining about px or cm not being an actual pixel or centimeter on your screen as there is in complaining that the feet in your shoes are shorter than twelve inches.

There is nothing wrong with current px not being equal to physical pixels. There should just be a way to use physical pixels when needed — be it with a CSS property that changes meaning of the px unit for specific element or a separate dedicated unit like dvpx (DeVice PiXel) or rpx (Real PiXel). = 'scale(' + (1/devicePixelRatio) + ')'

That’s a dirty pure-script (i. e. unavailable in CSS) workaround that is not even enough under Android that has an extra pinch-zoom factor that we are forced to unreliably calculate with something like window.outerWidth / window.innerWidth (fwiw, like in my SmartUpscale extension for Firefox that needs to deal with physical pixels according to its very purpose).

There are workarounds to using native pixels (which I can live with), but there is not any workaround to using actual physical units (inches, centimeters) because there’s currently no way to get the device’s physical dimensions.

“Native” programs all have this luxury, and it would be simple to add to the web!

Maybe we just needs to PR a spec change?

I would like this feature. I’d like to try to make UIs based on physical measurements without guess work.

Do you all like the idea of new units like rin, rcm, etc, where the r is for “real”? Or maybe w for “world”, win, wcm, etc?

I have recently argued for using the full US English names of the units instead of symbols or abbreviations, i. e. centimeter and millimeter or just meter, quarter (for q), inch, pica and point, perhaps also pixel.

My rejected proposal for absolute units that depend on the user but fall back to nice metric values is here:

Unit Alternative Definition Fallback Similar
nail rim finger nail thickness 0.25 mm q, pt (dd)
nib pen top of pen or stylus 1 mm mm
tip tip of index finger 5 mm pc (cc)
tap index finger print 1 cm cm
mark push, thumb, toe thumb print 2.5 cm in
pad paw, palm, ball, hand palm without fingers 10 cm (dm)
span open hand with splayed fingers 20 cm
sole foot, shoe foot print (with shoe) 30 cm (ft)