While the <meta name="viewport">
tag is unstandardized, it "is respected by most mobile browsers due to de-facto dominance."
One downside of it not being a true web standard is detailed documentation is not as available as other standards. The CSS Working Group has a specification for this, so that is what I am mainly using as an authoritative work.
My main question is:
What would the perceived difference be between the following declarations?
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="viewport" content="initial-scale=1.0">
Alternatively asked, what are the differences between these two @viewport CSS at-rules:
/* Translated from <meta name="viewport" content="width=device-width, initial-scale=1.0"> */
@viewport {
zoom: 1.0;
min-width: extend-to-zoom;
max-width: 100vw;
}
/* Translated from <meta name="viewport" content="initial-scale=1.0"> */
@viewport {
zoom: 1.0;
min-width: extend-to-zoom;
max-width: extend-to-zoom;
}
How I arrived at those @viewport
translations:
width=device-width
to min-width: extend-to-zoom; max-width: 100vw;
The CSS Device Adaptation Module Level 1 document states:
The
width
andheight
viewport<META>
properties are translated intowidth
andheight
descriptors, setting themin-width
/min-height
value toextend-to-zoom
and themax-width
/max-height
value to the length from the viewport.
They additionally give an example:
This
<META>
element:<meta name="viewport" content="width=500, height=600">
translates into:
@viewport { width: extend-to-zoom 500px; height: extend-to-zoom 600px; }
The width
shorthand descriptor is described as:
This is a shorthand descriptor for setting both
min-width
andmax-width
. One<viewport-length>
value will set bothmin-width
andmax-width
to that value. Two<viewport-length>
values will setmin-width
to the first andmax-width
to the second.
So it stands to reason that width: extend-to-zoom 500px;
is equivalent to min-width: extend-to-zoom; max-width: 500px;
.
That only leaves the 100vw
part. Within section 10.4, they explain:
device-width
anddevice-height
translate to 100vw and 100vh respectively
So we can finally see how width=device-width
is translated to min-width: extend-to-zoom; max-width: 100vw;
.
initial-scale=1.0
to zoom: 1.0; width: extend-to-zoom;
This one is a verbatim example:
This
<META>
element:<meta name="viewport" content="initial-scale=1.0">
translates into:
@viewport { zoom: 1.0; width: extend-to-zoom; }
The other question I have here is, what exactly is the extend-to-zoom
value?
The documentation on it and its resolution procedure are difficult to grasp. If anyone can point me toward some further examples on this that'd be greatly appreciated.
In addition to everything above, I've put together a quick site - https://romellem.github.io/temp-site/viewport/ - to test some viewport configurations.
Namely:
This may help with testing.
1.0
, but I'm unsure on this. Anyways, great answer, thanks! – Appalachia