-
Notifications
You must be signed in to change notification settings - Fork 27
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
Viewport Measurement (including new Viewport Units) #4
Comments
This is a great proposal, thanks @jensimmons! Frustration around this was also very prominent in the MDN browser compat survey and interview, see viewport findings for a summary. At the time I linked w3c/csswg-drafts#4329 and I'm happy to see the new units have been defined now. Here's something I noted in the report back then:
That was in early 2020. Judging by the State of CSS 2021 responses, it seems like the impression still persists that 100vh does something different across mobile browsers. Some of this is probably a lack of awareness, but I wonder if there are some differences around "filling the viewport" that are still causing frustration. @bokand researched Input/Scrolling Interop Investigation 2020 and back then there were differences in when resize events are fired, for example. Taking a close look together at differences in existing behavior would be great, so that if there's something many developers are running into, we can address that too and have a compelling message that we've made viewport units all around interoperable in 2022. |
+1 to this being a massive issue by talking to developers. Articles like The trick to viewport units on mobile (check the number of comments) are widely shared on Twitter and "solutions" like the |
I've now analyzed the "Are there any CSS features you have difficulties using because of differences between browsers?" questions from State of CSS 2021 in #7, and the Viewport category there is largely about this issue. Being up there close to Container Queries and |
Apologies, I just added an issue template for proposals, which I should have done much earlier. Would you be able to rewrite the issue description to match that template? |
I think it's a terrific idea to make this area be about nailing interoperability for the various ways web developers attempt to measure the Viewport — including JavaScript.
See examples of these at: http://smfr.org/misc/viewport-units.html The work to be done:
|
Does anyone have a good grasp on the testing situation around this? I've searched for svh, lvh and dvh in web-platform-tests but can't find any existing tests. Hopefully some of the tests in https://wpt.fyi/results/css/css-values are relevant, a bunch of them include "100vh" at least. https://wpt.fyi/results/css/css-env spontaneously looks like too few tests to be covering There seems to be just a single test using I think this proposal is on very solid ground when it comes to the rationale and would definitely be noticed by web developers, so I'd hate for a lack of tests today to rule it out. I'm not sure how realistic it is to flesh out the testing sufficiently in the remainder of 2021, but maybe that's doable. Alternatively, I hope we can find a structure for cross-vendor collaboration on solving this issue in 2022, even if doesn't form part of the Interop 2022 metric. |
The WebKit tests for the new viewport units are Obj-C++ so that they can configure the viewport appropriately. Certainly simply writing tests that assert the new viewport units are supported isn't too hard, nor that they are related to the UA-default viewport appropriately. Testing the dynamic behaviour isn't currently easily automatable in a cross-browser way (and regardless we aren't running tests for wpt.fyi on mobile presently which is where all the interesting dynamic functionality exists). |
For the new viewport units, I wonder if we could have shallow automated tests, but also write manual tests for things like the behavior when the address bar gets hidden on scroll. In parallel we could work out what automation would be required for these tests, and maybe automate them for an Interop 2023 metric. |
I might suggest we think of this project in distinct parts, some of which should be included & some of which should not:
|
Looking for some @jensimmons what kinds of tests would you be looking for when it comes to "percent lengths, eg: height: 100%"? In https://wpt.fyi/results/css/css-values there are a bunch of tests with "percent" in the name, but none of those contain "height: 100%". Plenty of other tests (in other directories, in particular css/CSS2/) include "height: 100%" but are any of those relevant? |
So I think the concrete suggestion here is:
I don't think any of these are particularly much work. |
So let me propose a clear, more narrow scope for Viewport Measurements:
|
The new viewport units were accepted as part of Interop 2022 in #39. We'll now need the simple automated tests for those units. @jensimmons @gsnedders is this something that Apple could work on? There was also support for the cross-browser investigation into other Viewport Measurements. @jensimmons given #4 (comment), is this something that you'd like to take charge of? Google would like to participate in this work. |
I volunteer at Apple's rep for a cross-browser investigation into the overall state of viewport measurements, as described above. I can help organize/facilitate/chair is that's desired. |
I think there's an open question whether we want to:
I've recently heard some people articulate an expectation that we are doing 1, and other people that we are doing 2. Perhaps this depends on whether such texts can return a length value and evaluate whether/not it's correct. Or if automated tests only test if the unit is supported by the browser. |
For my own part, I would strongly support including automated tests for all aspects of viewport measurement that we can find, so option 2. It's a fair amount of work to identify those tests, but this one at least has some failures: |
https://gist.github.com/07ca400d2e4dd01caa4a8f0c984be068 is all the existing list of files using viewport units in WPT; note there's no tests using the new viewport units. Most of the usage outside of css/css-values is rather incidental, so even if we do include the original viewport units we should probably exclude what's outside of that. This is the current status of those tests within css/css-values. |
In #44 we decided to only include tests for the new viewport units in the Interop 2022 metric, and work in #41 towards more tests for existing viewport measurement issues, as well as potentially testing the new units better than we can currently do in automation. The scope of the tests here are what @gsnedders suggested in #4 (comment):
The test haven't been written yet, and may not be in WPT when the RFC is updated, but this is clear enough so that we can all, as @jgraham said, imagine what those tests will look like. |
We could probably write a single manual test where the user hides the top controls and we simultaneously test many different things (e.g. all the various CSS units and the resize event). |
Current plan:
I don't know off-hand if we can actually test the interesting mobile cases using |
This issue mainly about viewport height, units, and so on, but I've experienced several other issues about viewport. Inconsistency in "zoom on input focus" behaviourSeveral years ago Safari introduced new feature: zoom the page on input focus, if font-size of it is too small (even on mobile-friendly sites) Safari: FF on android: Chrome on android: Inconsistency around viewport widthSometimes your site is not mobile-friendly, but you whant to provide better experience for tablet users, Also there is no value like "width=max(device-width, 980)" I cannot rembember it exactly, but I saw:
Problems in browsers with different approaches:
Moreover, Safari on iPad can behave differently, than Chrome on the same iPad As I said, I can't remember exactly all the nuances, and maybe there is a solution which I've missed, but I can do research, if someone interested in it |
Description
Web developers struggle to measure the viewport in a consistent and predictable manner — especially the viewport in the block dimension on mobile devices, when often the browser UI changes size or disappears/reappears. After years of hearing developer frustrations about VH in particular, the CSSWG has defined new units to cover all usecases and web developers would benefit greatly from rapid implementation by browsers.
-webkit-fill-available
,window.inner-height
, percent lengths, and environment variables (with & without fixed or sticky positioning) are also used to measure the viewport and size content/layout to fit. Ideally all of these would be as close to interoperable as possible, recognizing that browser UI is not something we standardize across browsers.Specification
Tests
TBD
Rationale
Looking at data from multiple surveys, and having talked to web developers for years (teaching about viewport units from stage), it's clear many web developers struggle to size content on mobile screens. They want to use viewport units instead of JavaScript to size elements, are often trying to create an app-like experience that fits the screen exactly, or are otherwise confounded by the browsers that have UI growing or shrinking at the top/bottom of a mobile screen.
The problem is a complex one, and developer often don't know how to express a solution. They instead describe the problem in a variety of ways. For example, from very early results of this year’s State of CSS survey alone:
and even more.
Developers often center their frustrations around iOS, but the same problem exists in mobile browsers on Android & other operating systems. The actual viewport size changes anytime a browser’s top/bottom UI changes state. And, it turns out, the vh/vw/vmin/vmax units alone do not solve everyone’s use cases at the same time.
The CSSWG did an in-depth analysis of this problem over the last several years, and came to the conclusion that the best solution to solve this is to create additional viewport units.
Let’s focus on viewport height.
SVH
unit will always return the height of the viewport if all of the UI was maximized (leaving the viewport the smallest possible size).LVH
will always return the height of the viewport if all of the UI was minimized (leaving the viewport the largest possible size.)DVH
stands for dynamic viewport height, a measurement that changes based on the current state of the UI, always returning the actual current value of the viewport height.There are similar units for width, max and min — and to cover logical layout, the new inline and block dimensions. Please read the CSS Values and Units Module Level 4 specification to read about all of the new units.
We would like to propose inclusion of all of these new units in Interop 2022. They will solve most of the frustrations web developers are having with sizing their content to the viewport.
Developers have been begging for a solution to this for years.
The text was updated successfully, but these errors were encountered: