-
Notifications
You must be signed in to change notification settings - Fork 662
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-values] Ability to address actual physical size #614
Comments
This comes up fairly often, gets pushed back every time. Let me try to give you a little gist of why. As you said, it is two late to change the definitions of what
On screens though, the px is defined to be (an approximation of) an angular measurement. The article you linked to is brushing that aside, but that does it a great disservice: if the pixel you're claiming is insufficient isn't the one defined in CSS, then it is difficult to make sense of the criticism. As you say, it matters to typography whether something is small or large. You want different font design and different typography based on that. But small or large is mostly not a question of physical size, but rather a question of the percentage of the field of vision, which combines physical size and viewing distance. The CSS pixel is often (but not always) rounded to a integer number of physical pixels by implementations, but it is fundamentally designed so that if you know the size of something in pixels, you know how big it looks. You mention low sighted readers as an example of why you need to know how large something physically is, but that wouldn't not work. Making each letter 2cm tall, which would seem gigantic if you're thinking of text on a phone, would result in small and unreadable text when seen on the projector of a large conference room. The CSS pixel already accounts for that. So your pizza slice analogy doesn't work. To turn it around, 1 “CSS pizza slice“ is defined so that it is always equally filling, regardless what kind of topping it has, whether it has a thin Italian crust or is an inch thick deep-dish Chicago style one. Knowing the diameter of the pizza alone wouldn't give you a better results, and if you had all the parameters, you'd need to boil them down to the same result a we already gave you. Sometimes, you also want to know about the resolution in order to know if you can use a font with fine serifs or other small features, or if they are going to be all mashed up due to a lack of physical pixels. But what's relevant here is the density of pixels with regards to the size of the font. And since that is not in physical units, but in CSS units, the resolution media query does the right thing. Another argument against absolute physical measurements is that they would mess with zooming. With the way things are currently defined, when the user zooms in, everything gets larger. If we respect that, the absolute physical units would no longer by absolute and physical, and we're back to square 1. If we don't, we're preventing users from zooming, which is a terrible disservice to do. We could distinguish between page zoom and pinch zoom, but that wouldn't really solve the problem. Yet another argument is that the browsers are not typically aware of the physical measurements of the display. Sometimes they may be, but in the general case they are not. And without that information, they cannot know how to correctly display something at 3 physical inches. This is not merely a temporary limitation of current software: if you move a projector closer to or further away from the wall it is projecting on, you would need to change the relative size of things on the web page to preserve the absolute measurements. But even the OS or the graphical drivers have no idea how far the wall is. |
Interestingly, MDN mentions the experimental |
Not entirely clear how that works though. On my mac, it seems to be the right size as long as you don't zoom (because then its size changes, just like any other unit). On my phone, if I use the meta viewport, it is larger than the requested size and larger than the same size in standard css mm, this works out to a different proportion between mm and mozmm compared to my mac. If I do not use the meta viewport, it is smaller than the requested size (no doubt due to the initial state being zoomed out). So the result is not reliably matching the physical measurement nor not reliably proportional to other css units. Doesn't sound terribly useful to me. |
@frivoal See responses to specific comments below …
The current definitions were not the original intention of the spec. As the spec itself explains: “Note that this definition of the pixel unit and the physical units differs from previous versions of CSS. In particular, in previous versions of CSS the pixel unit and the physical units were not related by a fixed ratio: the physical units were always tied to their physical measurements while the pixel unit would vary to most closely match the reference pixel. (This change was made because too much existing content relies on the assumption of 96dpi, and breaking that assumption breaks the content.)”
Like screens, printers also have physical resolution and an equivalent of a physical pixel unit (they are just much smaller than most screen pixels, and unrelated to the current concept of a CSS “pixel”).
The angular measurement ascribed to I am a huge proponent of the ability to address size in relation to perception and angle of vision, but the concept is not mutually exclusive to the ability to address physical size either.
I am very aware of this. See my Size Calculator project which is intended for calculating these relationships.
One of the biggest values of addressing physical size is not in specifying how large something is rendered but in knowing the size of a display on which it is rendered. If I know the physical size of a display, I have a MUCH better idea of how far away the viewer will be from it than I would from a relatively arbitrary pixel count.
Zooming for physical units could easily work the same as any other units. Zooming a 1-inch element to 200% would make it 2 inches. But you're also incorrectly assuming that I'm only talking about screen-based media, and that I think the size of most elements should be spec'd in physical units. In fact, I'd say fixed physical sizes wouldn’t make sense for many things. But that doesn't mean they shouldn't be an option for the times when they do make sense.
Again, you are assuming I'm only talking about screen-based media. And even if some software environments don't currently access physical display info from the device, that isn’t a reason that none of them ever should. Windows 10 is already providing access to physical measurements for native apps via the RawDpi property. Why shouldn’t websites be able to leverage the same info? Perhaps these comments are all beside the point though. If nothing else, the ability to address physical size is fundamental to using CSS for any fixed media like print. If designers can’t render an element at a specific physical size on a piece of paper, the whole notion of CSS being a truly universal language for presenting a document in a variety of media (including print) is moot. |
and
Ok, sure, there is of course some part of the current definition that can be explained by history. The fact that we use an angular measurement called pixel rather than degrees or arcminutes is certainly due to the fact that we started with a pixel unit. You are right, it initially did not have that behavior, and was simply a physical pixel. But as time went by, that definition was found to be problematic, and the newer system was used to redefine it. What is particularly useful about the angular definition of the pixel and other length units is that they enable robust designs. By that I mean that it enables authors to write a web page that works in environments they know about, and be confident that it will do the right thing even in environments they haven't tested in or are not even aware of. For instance, when then first iphone came out, it had small physical pixels, but since they were to be viewed from a close distance, it was still OK to have 1px to be 1 physical pixel. That meant that inches on the iphone were small, since they kept the 96 to 1 ratio. This in turn meant that sites that had not anticipated the iphone ended up working just fine. Further down, when retina iphones came out, pixels were now “too” small, so we got multiple device pixel per css pixel, inches stayed the same size, and again everything worked fine. And not everybody thinks of a projector or a nintendo wii when they design their site, but again, it just works. I am not claiming that there is no possible use for physical measurements. Authors are infinitely creative, so I am sure something could be made of them. On the other hand, I am sure that valid uses of physical measurements are many orders of magnitude more rare than the ones we have now. This gives a double challenge to people asking for physical measurements:
With regards to (1), I would say that introducing new units that give access to physical distances would not be acceptable. There's just too much a chance that authors who haven't thought deeply about this would pick the physical ones instead of the angle based ones, and make brittle designs because of that. So if this is to be exposed, it has to be some other way. As for (2), I suggest trying to build a corpus of concrete examples. Not abstract declarations of reasons why it should be useful, actual specific examples of designs that you cannot do today, but could if you had the feature. Down to the actual code, with mock ups of the rendering (ascii art will do, but the point is to be concrete), reasons why you cannot achieve this without the feature you're asking for, and (if it is not painfuly obvious) reasons why there is merit to this design.
From the spec:
So that's solved already. Using CSS for print is not theoretical, and I am not just talking about pressing the print button in your browser. Commercial books are made with CSS all the time (I just typeset this one). |
For what it's worth, I think this was added primarily because it was needed to make things that are touch targets an appropriate size. (See Jonathan Kew's original proposal and roc's later post on use cases and the bug in which the unit refactoring was done.) |
Touch screens are the reason why I still think that |
Right. Matching the size of a physical object seems valid in theory if there are relevant use cases, and correctly sizing touch targets seems like one. As such, a On the other hand, the difference between finger and stylus may be something we leave up to media queries (pointer:coarse vs pointer:fine), and for the rest maybe we can just deal with this with existing units: the distance range in which touch UIs can be used is necessarily limited by human anatomy, and something like |
Coming in late here, but: @nicksherman
You'd still end up inferring things. What if you find out that a display is physically large. It doesn't tell you if it's a TV type device (with a viewing distance of 10' ~ 3m) or a large touchscreen device meant to be stood in front and manipulated. I've long argued that the problem is potentially already solved if devices chose a sensible ideal viewport size https://patrickhlauke.github.io/web-tv/ideal-viewport/index.html |
I agree with @patrickhlauke, and believe at least a large part, and probably all, of the CSSWG does agree as well. |
@patrickhlauke I like some of your thinking with the viewport tool, but it also seems to put a lot of faith in how closely CSS pixels on most devices tend to match the spec’s reverse-justified definition of 0.0213 degrees. In most cases, devices do not render CSS pixels at the spec-accurate size when their displays are viewed from the intended viewing distance. But this is a bit of a digression. There will always be some amount of inferring unless there is a specific viewing distance that can be detected/reported. In the mean time, regardless of if physical size is used for inferring viewing distance, there are still all the other previously-mentioned situations where physical size would still be just as useful/necessary. One very basic example that @frivoal brushed aside is the issue of what happens when you hit the print button in your browser. Currently, even if you have a print-specific stylesheet with sizes set in “absolute” units like inches, almost all print output that is initiated in a browser will send something off to the printer that doesn’t match the specified sizing, instead utilizing CSS pixel sizing logic, usually in unpredictable ways. Unless there is a way to explicitly address physical units, there will likely not be any support for accurate print formatting within the output flow that most of the general public will ever use to print a web document (i.e. hitting the print button in a browser). |
Solve the use cases with media queries then?
|
@Crissov All media formatting is physical, even when it’s screen-based :) But I understand what you’re getting at. I think that is making it more complicated than it needs to be though. The simplest way to solve this issue would be to just introduce a new set of bona fide physical units that correspond to actual physical size, and specify very clearly in the spec that they must be interpreted as such. |
There are extra complications to take into account, mind. For instance, what if a user has set their OS resolution to something other than factory settings? Should physical units ignore that (e.g. 1cm always means 1cm, regardless of however the user set up their environment)? What about zoom factors? What about set-top boxes which may have no direct way of knowing physical size of the TV/screen they're connected to? |
of course they don't. but they strive to come close (with exception of TVs which stubbornly seem to refuse to implement anything close to a sane ideal viewport, and instead insist on desktop-like 1080p type resolutions with pixel density of 1 plus lots of fudging/upscaling, which is my personal bugbear). there's no guarantee of absolute accuracy, and the spec https://drafts.csswg.org/css-values/#absolute-lengths aknowledges that
|
related, i admittedly didn't do extensive testing, but when i last looked at this, the combination of browser/printer driver/printer seem to try to get it right to an extent (there's probably further fudging caused by printer settings involved here). using http://codepen.io/patrickhlauke/full/zqabMR/ and printing it out (I believe I tried only in Chrome at the time, admittedly) I get the below (where 72pt in CSS come...close-ish to a physical 1in on paper) |
@patrickhlauke Yes there are several interesting questions related to this. Some of them are more complex than others, and while I personally have opinions in many cases (perhaps better elaborated elsewhere if we want to keep this thread on topic), I can’t claim to be an authority on all of them. Nevertheless, I don’t think questions like these should be the reason that physical units are entirely ignored. I’ve done a few rounds of tests using the existing “absolute” units with typical consumer-level software and hardware, and every time I’ve had inaccurate results like the ones you showed. What’s worse is that the results vary widely depending on factors that are very hard if not impossible to pin down with certainty. The sizing error you showed seems small at the target size of 1 inch, but that’s already enough to be unusable for many production purposes. And if you multiply that scaling error up to a target size of 10+ inches, it literally becomes a big problem. Most of this conversation has been focused around the idea of sizing elements with physical units, which is great, but I feel inclined to also point out the less-obvious benefit of being able to query again physical sizes. For example, I'd love to be able to specify separate layouts for 8.5×11″ and 11×17″ paper formats, etc. |
my contention is that this level of inaccuracy won't be solved by simply decreeing in the spec that the whole pipeline of browser/OS/printer driver/printer/etc must be accurate. but happy to be proven wrong :) |
@patrickhlauke If not start in the spec, then where else? Can we at least agree that dependable and accurate physical units are a good thing that should ultimately exist? |
random idea: similar to |
That’s an interesting thought … Would that allow for a fixed physical unit to be specified for one dimension of an element and a relative/reference unit for the other? Or – maybe more importantly – would that be less complicated than simply introducing entirely new units? |
I agree. Current mis-sizing is not due to trying to do some different kind of sizing, but to failing at making 1in be 1in on paper, due to a bunch of intermediates, some (or many) of which may be sloppy. TV are refusing to do what the spec says they should do, and I don't really look favorably upon defining "You must do XYZ. If you'd rather not pay attention and keep on violating this spec, here's another one you could have a look at." Until TV vendors come back with an explanation for why doing the viewport the way the spec says cannot work for them, my assumption is that not that they have found such a reason and remain silent about it, but that they haven't bothered to try. I may very well be wrong about this, but I did spend two years as porting browsers to TVs, and two other years working for a TV vendor, so my guess is not a totally uninformed one. |
Though it's an aside to the main conversation, my take on TV vendors' reluctance (having worked with the same browser/vendor as @frivoal on that) is a combination of:
I am still hopeful that with the more current crop of devices (and particularly now in light of 4K / 8K displays, which absolutely demand some form of upscaling or at least reassessment on what resolution is being pushed out) the idea that TVs should behave more like a tablet/large phone with high-resolution display (as that gels with a viewing distance of 10' or so) will catch on (from memory, the FirefoxOS enabled LG models do at least run at desktop-like resolution, but advertise a device pixel density of 1.5 or 2). |
As argued very ably by several people in this thread, "real physical units" are (a) impossible in general, due to needing every part of a hardware chain to reliably tell the truth about its scaling, which they don't do, and (b) very, very rarely, if ever, what you actually want. The one use-case that kinda makes sense (making sure touch targets are sufficiently large in real terms) is better served by addressing that directly with a 'touch' unit or similar. As such, I'm going to go ahead and close this issue. |
In addition to the considerations above as to whether this is even possible, another point is that while there are some use cases for physical units, and it would be nice to measure the correct amount of chemicals in your pipette using a css-made scale, these are vastly outnumbered by the number of developers who use units rather interchangeably without thinking too much, and don't test on a very broad range of devices. And if anyone uses the physically-accurate-on-any-device physical units for anything other than making a physically accurate measuring instrument, they'll make sites which are badly broken and unusable on a wide variety of devices. In general, the ability to use a feature wrong should not necessarily mean that we should ban that feature, but when a feature is overwhelmingly likely to be used wrong and to result in broken sites, then it's a bad feature. It be nice to be able to make accurate lab equipment in CSS, but that is of much lower importance than keeping the ability of the web to robustly work across devices, including those the author doesn't test on (which includes those that those that haven't been released yet).
Fixing the ratio between
You don't have to make your own rendering engine, you just need to set the default zoom level on your browser to make a 1 But the whole world is not going to write a rendering engine that sacrifices cross-device interoperability just so that a few people can make rulers more easily. |
Notably, this would basically be:
This is a robust and minimal calibration scheme that will "fail open" - if the user hasn't calibrated, or clears local data, or has JS turned off, it'll just use standard CSS units (due to the |
It also requires zero spec changes, right? And, if that non-spec-changing technique is really a solution, then isn't there a plain case for a |
but your |
If the info isn't available (which would often be true in the first few years of a physical-size feature being added) there would just need to be a fallback of some kind. Let the browser itself make its best guess, or even let the user manually enter their screen dimensions. It's definitely not going to be an easy process, but a lot of the things that this project relies on won't get done until the project itself is actually implemented. For example, there's no reason for devices and OSes to report their physical size to the browser unless there are features in the browser that can take advantage of that info. In that case, we just need to forge ahead and get the CSS piece implemented, then pressure MS, Google, Apple, and device manufacturers to get on board. |
Yes.
Not really. The use-case here is not "scale every single length in the page to match physical dimensions", it's "scale these particular lengths to match physical dimensions, so users can measure real-world things against the screen". So it's absolutely a targeted operation, on particular lengths that only the page author can identify.
No, they were talking about just adapting my variable-based suggestion into an official property; it would default to |
Another use case: We are creating web application, and we know the intended viewing distances. For example in our system, we created:
We want to create system, that will calculate best font size from expected viewing distance (known to author in our case) and ideal viewing angle (user configurable, based on sight quality). We can calculate optimal size in real centimeters, but we don't have methods to set size in css pixels. |
I see little downside to adding something like mentioned above with the experimental
Just my opinion here; I understand this isn't something fundamentally necessary, but it's definitely a useful building block that we couldn't have without making this change, and there really is no reason to not implement it. |
Justin Golden composed on 2021-01-09 11:53 (UTC-0800):
I see little downside to adding something like mentioned above with the experimental `mozmm` unit suggested.
* It won't break any existing code
* It acknowledges and maintains all benefits of the normal `mm`, `cm`, and `in` units, and for people not even aware of the existence of `mozmm` and similar, they go about programming the same
* It provides the functionality people here are suggesting, and have good reason to suggest
* Adding it has virtually no downsides in terms of: complexity, processing time, code size, etc. I really see no downsides aside from the clutter of adding another (entirely optional) unit
Just my opinion here; I understand this isn't something fundamentally necessary, but it's definitely a useful building block that we couldn't have without making this change, and there really is no reason to *not* implement it.
+++
A huge selection of my web pages irrecoverably broken when mozmm units were
expunged from Mozilla browsers. Luckily, there's still Palemoon.
|
Saying this at the bottom of a thread where multiple people have went to quite some length to explain the what the downsides are seems unlikely to move the discussion forward. |
How can this move forwards? |
I do not have strong expectations that this can move forward. Numerous explanations have been provided as to why this won't happen, and the issue is closed, very deliberately so. It is far from the first time that this gets raised, and the conclusion is always the same, for the same reasons. So most likely, nothing will happen. At the same time, those who believe that closing the issue is a mistake are welcome to try and convince others of that, but repeating arguments that have already been refuted, or acting as if the downsides that have been pointed out don't exist is unlikely to convince anyone. It is possible that most members of the CSSWG and most browser engineers are wrong, that there's a big flaw in the collective reasoning, and that one way or another, this is actually a good idea. If you think so, start by understanding the arguments against, then build a strong case debunking them, and explain why you're right. Merely stating that there's no downside isn't going to be convincing. |
I'm sorry I was too terse, I was talking about the thing @tabatkins and I had discussed which seems to have merit. |
Note that, when asked if there was a use-case for the "adjust all length on the page by this factor" property, I replied "Not really". ^_^ As I said in the linked comment, the use-case is not "adjust every length on the page" - calibrating your ruler shouldn't also scale the UI. It's "adjust these particular lengths that I want to be physically accurate", and with variables there's an easy and robust way to do this by asking the user to calibrate the length, which is guaranteed to be correct in all cases rather than relying on a possibly-faulty browser-provided scaling factor. |
I've gone ahead and added this to the FAQ, since it's come up multiple times. |
This comment has been minimized.
This comment has been minimized.
Hey all, based on this discussion, I wrote an article about this topic: Calibrate CSS
I hope this is a constructive contribution to the debate and I'm looking forward to evolve this. We need a community to further establish Level 0. |
It is a well known standard. There may be others. Exposing physical pixel APIs in the web will encourage hardware makers to follow along, considering the web browsers are the most stable and widely tested pieces of software humans may have ever made. It seriously can not be more difficult than managing OpenGL compatibility behind WebGL. That must be many times more complex. Yet we still did it. A simple fallback for certain cases when information is not available is totally a must. Well known native frameworks like Qt have been giving developers physical pixel sizing for a long time. It is time for web to be as good. It takes a visionary to be able to see this future. |
hi, this is a very interesting, although seemingly hopeless conversation about this rather confusing topic (at least it is/was for me). i too came here originally because of the hit target problem, but generally i expect "physical units" to work as expected/promised/suggested by their name. in my opinion and experience, it is extremely misleading and irritating to borrow the names of "real" units like inch or cm and use them for "fake" units that lead to different/unexpected results. i really cannot think of why they were introduced in the first place, if there was never a chance to achieve exact/expected results with them. i can only guess it has some historic reasons ("simpler times") and it can not be undone now without breaking some exotic code (which is i would do in a second), but wouldn't it be better to let them go or at least clearly warn developers/designers about these inconsistencies? it probably would help people like me a lot to prominently warn of that mix-up, to expect inaccurate results and probably avoid these units at all. yes, in the specs there is a note, but is very subtle and most people don't find the time or interest to dig into such details. there should be a big red warning sign to avoid misuse. i too would really like to use the real deal or avoid it at all, but it seems that has already been discussed in great lengths. the suggested alternative/compromise of being able to at least set a new property on specific elements or even the html element itself sounds great too! it reminds me of applications like acrobat that supports setting a global custom dpi in the preferences to manually adjust/calibrate the display of documents on one specific monitor. of course, it would even be better to automatically support reliable actual 1:1 physical view/scale like indesign or illustrator. if that is not possible (for whatever reason), why not give up on these otherwise unnecessary units... they seem to cause more harm than good. i find it funny that the same discussions happened when desktop publishing software introduced the pixel unit to attract web designers and suggested it is an actual physical unit while the software works completely independent of density/resolution until export... to me it seems like the same issue, just the other way around. anyway, the concept of css pixel as an angle is really fascinating! sadly, i cannot find out when this concept was introduced first and how well it is adopted across current devices and browsers. can designers already rely on it? is it at least a good enough approximation of consistent size across devices with different densities/sizes/distances? |
I don't see why this can't be added. In many cases, the API will be useful (most apps run on a single display, with EDID information readily available). It seems like real unit ( Additionally, a capability for On multi-monitor setups, unless the pixel sizes match, either
For mobile phones and tables, this isn't even an issue. These devices have a single display the vast majority of the time. The vast majority of people with multi-monitor setups I've seen tend to have windows on one monitor or another, not spread across multiple. Seems rather simple from an implementation perspective. I've used (actually valid) physical units in Qt since many many years ago... |
There are some really good use cases for this too. No everyone is designing standard apps. For example, if someone is designing a physical experience inside a physical space, decorating that space by wrapping flexible monitors around a tube (etc), then being able to code the design that is supposed to wrap around that physical object simply using the units as designed, is a very simple dev experience. Or someone makes a ruler app. Or someone makes a huge wall out of multiple monitors, to display human-sized objects. They just use the actual size of humans (in inches for example) and it simply works. Etc. |
The lack of ability to address physical size in any meaningful way is one of the most glaring issues with CSS today. I wrote an article a few years ago explaining why:
http://alistapart.com/column/responsive-typography-is-a-physical-discipline
Especially if there is any expectation that CSS will ever be used beyond the world of web design, the ability to specify and query physical size is crucial.
I realize it may now be too late to change the definition of what
in
,cm
,px
, etc refer to in CSS without breaking a lot of things. But that doesn’t mean there can’t be new units introduced to refer specifically to real physical values.The text was updated successfully, but these errors were encountered: