Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[css-env] Device Pixel Ratio #5986

Open
Crissov opened this issue Feb 12, 2021 · 5 comments
Open

[css-env] Device Pixel Ratio #5986

Crissov opened this issue Feb 12, 2021 · 5 comments

Comments

@Crissov
Copy link
Contributor

Crissov commented Feb 12, 2021

As a result of #614, please add environment variables:

  • env(device-pixel-ratio)
  • env(device-pixel-ratio-x)
  • env(device-pixel-ratio-y)

This is a <number> constant, which can be used verbatim as a multiplier or divisor with a <length>, e.g. calc(1mm * env(device-pixel-ratio, 1)), to get from nominal, CSS millimeters to actual, SI millimeters etc.

On media and devices where px depends on physical units and not the other way around (as on screens), this should always be set to 1.0. Elsewhere, it should not deviate a lot from this.

I included horizontal and vertical variants, because not all pixels are square.

@tabatkins
Copy link
Member

d-p-r, as the term is currently used, is not about the ratio of px to physical sizes, but rather the ratio of CSS px to device pixels.

As I just laid out in a new FAQ entry, having user agents provide real-world lengths is a failed experiment that we're not interested in trying again.


As a side note, pixels are always square enough on the web that lengths are identical in both dimensions; a 100px by 100px square is always square.

@Crissov
Copy link
Contributor Author

Crissov commented Feb 28, 2021

The Workaround section in that FAQ entry uses a custom --unit-scale property. This issue is asking to provide the same thing with some standardized name and a sound default value where available. Browsers or OSs could offer a system-wide calibration to their users, so authors would not have to provide a site-specific one.

Authors, who believe they could increase reliability with calibration done by their users, could still do it, but with better fallback: var(--unit-scale, env(unit-scale, 1)).

The separate horizontal and vertical values are less important, perhaps unnecessary indeed.

@tabatkins
Copy link
Member

As I explain in the FAQ, getting accurate values for this out of arbitrary display devices is, as far as I know, a failed experiment.

This is one of those cases where worse is better - giving authors a way to sometimes get a value that is correct (but othertimes is still slightly or extremely wrong) is worse than just telling them to calibrate when they need accurate answers, because it suggests that the scale value is something worthwhile when actually it's sole use is as a hopefully better fallback value than 1.

@Crissov
Copy link
Contributor Author

Crissov commented Mar 2, 2021

For arbitrary display devices, this may well be a failed experiment. However, for mobile devices that integrate a touchscreen, i.e. phones, watches and tablets, the system usually knows such physical dimensions and may expose them to native apps, e.g. rulers. I believe that PWAs should be able to do something equivalent, and not just in JS.

@Crissov
Copy link
Contributor Author

Crissov commented Mar 15, 2021

JFTR, env(unit-scale-physical) has been suggested in the original issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants