-
Notifications
You must be signed in to change notification settings - Fork 707
/
Copy pathOverview.bs
1529 lines (1264 loc) · 55.3 KB
/
Overview.bs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<pre class="metadata">
Title: CSS Device Adaptation Module Level 1
Level: 1
Shortname: css-device-adapt
Group: CSSWG
Status: ED
Work Status: Exploring
TR: http://www.w3.org/TR/css-device-adapt-1/
ED: https://drafts.csswg.org/css-device-adapt/
Previous Version: http://www.w3.org/TR/2016/WD-css-device-adapt-1-20160329/
Editor: Florian Rivoal, Invited Expert, https://florian.rivoal.net, w3cid 43241
Editor: Matt Rakow, Microsoft, w3cid 62267
Former Editor: Rune Lillesveen, Opera Software, rune@opera.com
Former Editor: Ryan Betts, Adobe Systems, rbetts@adobe.com
Former Editor: Øyvind Stenhaug, Opera Software, oyvinds@opera.com
Abstract: This specification provides a way for an author to specify, in CSS, the size, zoom factor, and orientation of the viewport that is used as the base for the initial containing block.
Issue Tracking: Bugzilla https://www.w3.org/Bugs/Public/buglist.cgi?component=Device%20Adaptation&list_id=52675&product=CSS&resolution=---
Ignored Vars: <viewport-length>
</pre>
<h2 id="intro">
Introduction</h2>
<em>This section is not normative.</em>
CSS 2.1 [[!CSS21]] specifies an
<a href="https://www.w3.org/TR/CSS21/visudet.html#containing-block-details">
initial containing block</a> for continuous media that has the dimensions
of the <a href="https://www.w3.org/TR/CSS21/visuren.html#viewport">
viewport</a>. Since the viewport is generally no larger than the display,
devices with smaller displays such as phones or tablets typically present
a smaller viewport than larger devices like desktop or laptops.
Unfortunately, many documents have historically been designed against larger
viewports and exhibit a variety of bugs when viewed in smaller viewports.
These include unintended layout wrapping, clipped content, awkward scrollable
bounds, and script errors. To avoid these issues, mobile browsers generally
use a fixed initial containing block width that mimics common desktop browser
window size (typically 980-1024px). The resulting layout is then scaled down
to fit in the available screen space.
Although this approach mitigates the issues mentioned above, the downscaling
means the CSS pixel size will be smaller than
<a href="https://www.w3.org/TR/CSS21/syndata.html#length-units">recommended</a>
by CSS 2.1. Users will likely need to zoom on the content to view it
comfortably.
This mitigation is unnecessary for sites that have been designed to work
well on small viewports. This specification describes the CSS
<code class=css>@viewport</code> rule which allows authors to control and
opt-out of this behavior.
Issue: This specification is written from an implementation-centric point of view,
making it arguably difficult to read.
Significant editorial work may be needed
to make it more understandable to different audiences.
It also should clarify which viewport is referred to by various js APIs.
See <a href="http://www.quirksmode.org/blog/archives/2015/09/a_new_device_ad.html">this blog post by ppk</a>
for a good discussion of these issues.
Issue: Various issues about this specification and related specifications
are listed in <a href="https://www.w3.org/Graphics/SVG/WG/wiki/Proposals/Investigation_of_APIs_for_Level_of_detail#The_issues_on_existing_APIs">this report</a>.
<h2 id="scenarios">
Motivating Scenarios</h2>
<div class="example">
In this example, the document can be rendered without issue with any
size viewport. The author indicates this using the
<code class=css>@viewport</code> rule.
<pre class="lang-html">
<!doctype html>
<html>
<head>
<title>My Site</title>
<style>
@viewport { width: auto; }
</style>
</head>
<body>
Since this document is just some simple text, it can be rendered
at any width without issue. The text will just re-wrap as needed
when viewed in a smaller viewport.
</body>
</html>
</pre>
</div>
<div class="example">
In this example, the document can be rendered without issue for viewports
down to 384px, but smaller sizes would clip the diagram. The author
indicates this using the <code class=css>@viewport</code> rule in
combination with a media query. When the viewport would be smaller than
384px, the user agent will select 384px as the initial containing block
size and scale the resulting layout down to fit the available space.
<pre class="lang-html">
<!doctype html>
<html>
<head>
<style>
@viewport { width: auto; }
@media (max-width: 384px) {
@viewport { width: 384px; }
}
body {
margin: 0;
}
img {
min-width: 384px;
}
</style>
<title>My Other Site</title>
</head>
<body>
<img src="diagram.png">
</body>
</html>
</pre>
</div>
<h2 id="values">
Values</h2>
This specification follows
the <a href="https://www.w3.org/TR/css3-syntax/#property-defs">CSS
property definition conventions</a> from [[!CSS3SYN]].
Value types are defined in [[!CSS3VAL]].
<h2 id="the-viewport">
The viewport</h2>
In CSS 2.1 a <a href="https://www.w3.org/TR/CSS21/visuren.html#viewport">viewport</a>
is a feature of a user agent for continuous media and used to
establish the initial containing block for continuous media. For paged
media, the initial containing block is based on the page area. The
page area can be set through ''@page'' rules. Hence, ''@viewport''
applies to continuous media, and ''@page'' to paged media, and they
will not interact or conflict.
This specification introduces a way of overriding the size of the viewport
provided by the user agent (UA). Because of this, we need to introduce the
difference between the ''initial viewport'' and the ''actual viewport''.
<dl>
<dt><dfn>initial viewport</dfn></dt>
<dd>
This refers to the viewport before any UA or author styles have
overridden the viewport given by the window or viewing area of the UA.
Note that the ''initial viewport'' size will change with the
size of the window or viewing area.</dd>
<dt><dfn>actual viewport</dfn></dt>
<dd>
This is the viewport you get after the cascaded viewport descriptors,
and the following <a href="#constraining-procedure">constraining procedure</a>
have been applied.
</dd>
</dl>
When the ''actual viewport'' cannot fit inside the window or
viewing area, either because the ''actual viewport'' is
larger than the ''initial viewport'' or the zoom factor
causes only parts of the ''actual viewport'' to be visible,
the UA should offer a scrolling or panning mechanism.
It is recommended that initially the upper-left corners of the
''actual viewport'' and the window or viewing area are aligned if the
base direction of the document is ltr. Similarly, that the upper-right
corners are aligned when the base direction is rtl. The base direction
for a document is defined as the computed value of the 'direction'
property for the first <code class=html><BODY></code> element of
an HTML or XHTML document. For other document types, it is the
computed 'direction' for the root element.
<p class=issue>"dbaron: The question is, what does this do on the desktop
browser? (And what's a desktop browser)". Need to say that a "desktop"
browser typically have no UA styles, as opposed to the
<a href="#ua-stylesheet">UA stylesheet</a> outlined for current mobile
behaviour, and that no UA styles for ''@viewport'' will give "desktop"
behaviour per default (actual viewport is initial viewport).</p>
<h2 id="atviewport-rule">
The <dfn at-rule>@viewport</dfn> rule</h2>
<div class=note>
<strong class="advisement">UA vendors implementing this specification
are strongly encouraged to do so both for their mobile and desktop browsers.
The ''@viewport'' mechanism is designed to be usable and useful
on all browsers, not only mobile ones.
However, if support is only available on mobile browsers for a significant time,
there is a risk that authors would write ''@viewport'' rules that work on mobile
but do the wrong if applied by a desktop browser.
This would make it difficult to later add support for ''@viewport'' in desktop browsers.</strong>
<p>An example of such misguided use would be to write <code highlight="css">@viewport { width: 320px; }</code>
instead of <code highlight="css">@viewport { width: auto; }</code>
to make a document “mobile friendly”.
</div>
The ''@viewport'' <a href="https://www.w3.org/TR/CSS21/syndata.html#at-rules">at-rule</a>
consists of the @-keyword followed by a block of descriptors
describing the viewport.
The descriptors inside an ''@viewport'' rule are per document and
there is no inheritance involved. Hence declarations using the
''inherit'' keyword will be dropped. They work similarly
to ''@page'' descriptors and follow the cascading order of CSS. Hence,
descriptors in ''@viewport'' rules will override descriptors from
preceding rules. The declarations allow !important which will affect
cascading of descriptors accordingly.
''@viewport'' rules apply to top level documents only.
<div class=example>
This example sets the viewport to at least 320px, but otherwise match
window width if it is wider than 320px. Note that it is enough to set
the width as the height will be resolved from the width when auto.
<pre>
@viewport {
width: 320px auto;
}
</pre>
</div>
<h3 id="syntax">
Syntax</h3>
The syntax for the ''@viewport'' rule is as follows (using the
notation from
the <a href="https://www.w3.org/TR/CSS21/grammar.html">Grammar
appendix</a> of CSS 2.1 [[!CSS21]]):
<pre>
viewport
: VIEWPORT_SYM S* '{' S* declaration? [ ';' S* declaration? ]* '}' S*
;
</pre>
with the new token:
<pre>@{V}{I}{E}{W}{P}{O}{R}{T} {return VIEWPORT_SYM;}</pre>
where:
<pre>
V v|\\0{0,4}(56|76)(\r\n|[ \t\r\n\f])?|\\v
W w|\\0{0,4}(57|77)(\r\n|[ \t\r\n\f])?|\\w
</pre>
The <code>viewport</code> non-terminal is added to the
<code>stylesheet</code> production along with the
<code>ruleset</code>, <code>media</code>, and <code>page</code>
non-terminals:
<pre>
stylesheet
: [ CHARSET_SYM STRING ';' ]?
[S|CDO|CDC]* [ import [ CDO S* | CDC S* ]* ]*
[ [ ruleset | media | page | viewport ] [ CDO S* | CDC S* ]* ]*
;
</pre>
It is also added to the <a spec="css-conditional">nested_statement</a> production defined in [[!CSS3-CONDITIONAL]]
to allow ''@viewport'' rules nested inside <a spec="css-conditional">conditional group rules</a>
such as ''@media'' or ''@supports'':
<pre>
nested_statement
: ruleset | media | page | font_face_rule | keyframes_rule |
supports_rule | viewport
;
</pre>
<h2 id="viewport-desc">
Viewport descriptors</h2>
This section presents the descriptors that are allowed inside an
''@viewport'' rule. Other descriptors than those listed here will be
dropped.
Relative length values are resolved against initial values. For
instance 'em's are resolved against the initial value of the
'font-size' property. Viewport lengths (''vw'', ''vh'', ''vmin'',
''vmax'') are relative to the initial viewport.
<h3 id="min-max-width-desc">
The 'min-width' and 'max-width' descriptors</h3>
<p class="issue">min- and max- functionality can be achieved with media queries, should these be removed?</p>
<pre class=descdef>
Name: min-width
For: @viewport
Value: <<viewport-length>>
Initial: auto
Percentages: Refer to the width of the ''initial viewport''
Computed value: auto, an absolute length, or a percentage as specified
</pre>
<pre class=descdef>
Name: max-width
For: @viewport
Value: <<viewport-length>>
Initial: auto
Percentages: Refer to the width of the ''initial viewport''
Computed value: auto, an absolute length, or a percentage as specified
</pre>
Specifies the minimum and maximum width of
the <a href="https://www.w3.org/TR/CSS21/visuren.html#viewport">viewport</a>
that is used to set the size of
the <a href="https://www.w3.org/TR/CSS21/visudet.html#containing-block-details">
initial containing block</a> where
<pre class=prod><dfn><var><viewport-length></var></dfn> = auto | <length> | <percentage></pre>
and the values have the following meanings:
<dl dfn-type=value dfn-for="viewport-length">
<dt><dfn>auto</dfn></dt>
<dd>
The used value is calculated from the other descriptors'
values according to the
<a href="#constraining-procedure">constraining procedure</a>.
</dd>
<p class="issue">The user-agent stylesheets recommended in the informative section don't adequately represent current implementation behaviors. Should there be a more explicit mechanism for switching between UA default behavior and requesting the CSS pixel?</p>
<dt><dfn><<length>></dfn></dt>
<dd>
A non-negative absolute or relative length.
</dd>
<dt><dfn><<percentage>></dfn></dt>
<dd>
A percentage value relative to the width or height of the
''initial viewport'' at zoom factor 1.0, for horizontal
and vertical lengths respectively. Must be non-negative.
</dd>
</dl>
The 'min-width' and 'max-width' descriptors are inputs to the
<a href="#constraining-procedure">constraining procedure</a>. The
width will initially be set as close as possible to the ''initial
viewport'' width within the min/max constraints.
<h3 id="width-desc">
The 'width' shorthand descriptor</h3>
<pre class=descdef>
Name: width
For: @viewport
Value: <<viewport-length>>{1,2}
Initial: See individual descriptors
Percentages: See individual descriptors
Computed value: See individual descriptors
</pre>
This is a shorthand descriptor for setting both 'min-width' and
'max-width'. One <<viewport-length>> value will set both 'min-width'
and 'max-width' to that value. Two <<viewport-length>> values will
set 'min-width' to the first and 'max-width' to the second.
<h3 id="min-max-height-desc">
The 'min-height' and 'max-height' descriptors</h3>
<pre class=descdef>
Name: min-height
For: @viewport
Value: <<viewport-length>>
Initial: auto
Percentages: Refer to the height of the ''initial viewport''
Computed value: auto, an absolute length, or a percentage as specified
</pre>
<pre class=descdef>
Name: max-height
For: @viewport
Value: <<viewport-length>>
Initial: auto
Percentages: Refer to the height of the ''initial viewport''
Computed value: auto, an absolute length, or a percentage as specified
</pre>
Specifies the minimum and maximum height of the
<a href="https://www.w3.org/TR/CSS21/visuren.html#viewport">viewport</a>
that is used to set the size of the
<a href="https://www.w3.org/TR/CSS21/visudet.html#containing-block-details">
initial containing block</a>.
The min-height and max-height descriptors are inputs to
the <a href="#constraining-procedure">constraining procedure</a>.
The height will initially be set as close as possible to the ''initial
viewport'' height within the min/max constraints.
<h3 id="height-desc">
The 'height' shorthand descriptor</h3>
<pre class=descdef>
Name: height
For: @viewport
Value: <<viewport-length>>{1,2}
Initial: See individual descriptors
Percentages: See individual descriptors
Computed value: See individual descriptors
</pre>
This is a shorthand descriptor for setting both min-height and max-height.
One <<viewport-length>> value will set both min-height and max-height
to that value. Two <<viewport-length>> values will set min-height to
the first and max-height to the second.
<h3 id="zoom-desc">
The 'zoom' descriptor</h3>
<pre class=descdef>
Name: zoom
For: @viewport
Value: auto | <<number>> | <<percentage>>
Initial: auto
Percentages: The zoom factor itself
Computed value: auto, or a non-negative number or percentage as specified
</pre>
Specifies the initial zoom factor for the window or viewing area. This
is a magnifying glass type of zoom. Interactively changing the zoom
factor from the initial zoom factor does not affect the size of the
initial or the actual viewport.
Values have the following meanings:
<dl dfn-type=value dfn-for=zoom>
<dt><dfn>auto</dfn></dt>
<dd>
The zoom factor is UA-dependent. The UA may use the size of the area
of the canvas on which the document is rendered to find that initial
zoom factor. See <a href="#handling-auto-zoom">this section</a> for a
proposed way of handling ''zoom/auto'' values for 'zoom'.
</dd>
<dt><var><<number>></var></dt>
<dd>
A non-negative number used as a zoom factor. A factor of 1.0 means
that no zooming is done. Values larger than 1.0 gives a zoomed-in
effect and values smaller than 1.0 a zoomed-out effect.
</dd>
<dt><var><<percentage>></var></dt>
<dd>
A non-negative percentage value used as a zoom factor. A factor of
100% means that no zooming is done. Values larger than 100% gives a
zoomed-in effect and values smaller than 100% a zoomed-out effect.
</dd>
</dl>
<h3 id="min-zoom-desc">
The 'min-zoom' descriptor</h3>
<pre class=descdef>
Name: min-zoom
For: @viewport
Value: auto | <<number>> | <<percentage>>
Initial: auto
Percentages: The zoom factor itself
Computed value: auto, or a non-negative number or percentage as specified
</pre>
Specifies the smallest allowed zoom factor. It is used as input to the
<a href="#constraining-procedure">constraining procedure</a> to constrain
non-''zoom/auto'' 'zoom' values, but also to limit the allowed zoom factor
that can be set through user interaction. The UA should also use this
value as a constraint when choosing an actual zoom factor when the
used value of 'zoom' is ''zoom/auto''.
Values have the following meanings:
<dl dfn-type=value dfn-for=min-zoom>
<dt>auto</dt>
<dd>
The lower limit on zoom factor is UA dependent. There will be no minimum
value constraint on the 'zoom' descriptor used in
the <a href="#constraining-procedure">constraining
procedure</a>
</dd>
<dt><var><<number>></var></dt>
<dd>
A non-negative number limiting the minimum value of the zoom factor.
</dd>
<dt><var><<percentage>></var></dt>
<dd>
A non-negative percentage limiting the minimum value of the zoom factor.
</dd>
</dl>
<h3 id="max-zoom-desc">
The 'max-zoom' descriptor</h3>
<pre class=descdef>
Name: max-zoom
For: @viewport
Value: auto | <<number>> | <<percentage>>
Initial: auto
Percentages: The zoom factor itself
Computed value: auto, or a non-negative number or percentage as specified
</pre>
Specifies the largest allowed zoom factor. It is used as input to the
<a href="#constraining-procedure">constraining procedure</a> to constrain
non-''zoom/auto'' 'zoom' values, but also to limit the allowed zoom factor
that can be set through user interaction. The UA may choose to ignore
this limit for accessibility/usability reasons – see the relevant note in
the 'user-zoom' section. The UA should also use this
value as a constraint when choosing an actual zoom factor when the
used value of 'zoom' is ''zoom/auto''.
Values have the following meanings:
<dl dfn-type=value dfn-for=max-zoom>
<dt>auto</dt>
<dd>
The upper limit on zoom factor is UA dependent. There will be
no maximum value constraint on the 'zoom' descriptor used in
the <a href="#constraining-procedure">constraining
procedure</a>
</dd>
<dt><var><<number>></var></dt>
<dd>
A non-negative number limiting the maximum value of the zoom factor.
</dd>
<dt><var><<percentage>></var></dt>
<dd>
A non-negative percentage limiting the maximum value of the zoom factor.
</dd>
</dl>
<h3 id="user-zoom-desc">
The 'user-zoom' descriptor</h3>
<pre class=descdef>
Name: user-zoom
For: @viewport
Value: zoom | fixed
Initial: zoom
Percentages: N/A
Computed value: as specified
</pre>
Specifies if the zoom factor can be changed by user interaction or not.
Values have the following meanings:
<dl dfn-type=value dfn-for=user-zoom>
<dt><dfn>zoom</dfn></code></dt>
<dd>
The user can interactively change the zoom factor.
</dd>
<dt><dfn>fixed</dfn></dt>
<dd>
The user cannot interactively change the zoom factor.
</dd>
</dl>
<div class="note">
Authors should not suppress (with <code>user-zoom: fixed</code>)
or limit (with <code>max-zoom</code>) the ability of users to resize
a document, as this causes accessibility and usability issues.
There may be specific use cases where preventing users from zooming
may be appropriate, such as map applications – where custom zoom
functionality is handled via scripting. However, in general this
practice should be avoided.
Most user agents now allow users to always zoom, regardless
of any restrictions specified by web content – either by default, or
as a setting/option (which may however not be immediately apparent
to users).
</div>
<h3 id="orientation-desc">
The 'orientation' descriptor</h3>
<pre class=descdef>
Name: orientation
For: @viewport
Value: auto | portrait | landscape
Initial: auto
Percentages: N/A
Computed value: as specified
</pre>
This descriptor is used to request that a document is displayed in portrait
or landscape mode. For a UA/device where the orientation is changed upon
tilting the device, an author can use this descriptor to inhibit the
orientation change. The descriptor should be respected for
standalone web applications, and when the document is displayed
in fullscreen. It is recommended that it is ignored for normal
web navigation to avoid confusing the user.
Values have the following meanings:
<dl dfn-type=value dfn-for=orientation>
<dt><dfn>auto</dfn></dt>
<dd>
The UA automatically chooses the orientation based on the device's
normal mode of operation. The UA may choose to change the orientation
of the presentation when the device is tilted.
</dd>
<dt><dfn>portrait</dfn></dt>
<dd>
The document should be locked to portrait presentation.
</dd>
<dt><dfn>landscape</dfn></dt>
<dd>
The document should be locked to landscape presentation.
</dd>
</dl>
<h2 id="constraining">
Constraining viewport descriptor values</h2>
<h3 id="constraining-defs">
Definitions</h3>
For the procedure below:
Descriptors refer to the values resolved/constrained to at that point in
the procedure. They are initially resolved to their computed values.
<dfn><code>width</code></dfn> and <dfn><code>height</code></dfn> refer
to the resolved viewport size and not the shorthand descriptors. They
are both initially ''viewport-length/auto''.
<code>MIN/MAX</code> computations where one of the arguments is
''zoom/auto'' resolve to the other argument. For instance, <code>MIN(0.25,
''zoom/auto'') = 0.25</code>, and <code>MAX(5, ''zoom/auto'') = 5</code>.
<dfn><code>initial-width</code></dfn> is the width of the
''initial viewport'' in pixels at zoom factor 1.0.
<dfn><code>initial-height</code></dfn> is the height of the
''initial viewport'' in pixels at zoom factor 1.0.
<h3 id="constraining-procedure">
The procedure</h3>
The used values are resolved from the computed values going through
the steps below.
User agents are expected, but not required, to re-run this procedure
and re-layout the document, if necessary, in response to changes
in the user environment, for example if the device is tilted from
landscape to portrait mode or the window that forms the ''initial
viewport'' is resized.
However, Media Queries and Device Adaption are <dfn lt="Specifications
whose evaluations are both affected by the same changes to the user
environment, and so always must be evaluated together in order to
ensure proper rendering.">tethered specifications</dfn>. As a result,
UAs that also
support <a href="https://www.w3.org/TR/css3-mediaqueries/">Media Queries</a>
must re-run this procedure and re-layout the document in all cases
where changes in the user environment would cause them to re-evaluate
Media Queries.
<h4 id="constraining-min-max-zoom" class="no-num no-toc">
Resolve <code lt="min-zoom!!resolved">min-zoom</code>
and <code lt="max-zoom!!resolved">max-zoom</code> values</h4>
<ol>
<li>
If <code lt="min-zoom!!resolved">min-zoom</code> is not
''zoom/auto'' and <code lt="max-zoom!!resolved">max-zoom</code>
is not ''zoom/auto'', set <code>max-zoom = MAX(min-zoom,
max-zoom)</code>
</li>
</ol>
<h4 id="constraining-zoom" class="no-num no-toc">
Constrain <code lt="zoom!!resolved">zoom</code> value to
the <code>[min-zoom, max-zoom]</code> range</h4>
<ol id="ol2">
<li>
If <code lt="zoom!!resolved">zoom</code> is not ''zoom/auto'',
set <code>zoom = MAX(min-zoom, MIN(max-zoom,
zoom))</code>
</li>
</ol>
<h4 id="resolve-px" class="no-num no-toc">
Resolve non-''viewport-length/auto'' lengths to pixel lengths</h4>
<ol id="ol3">
<li>
Resolve absolute lengths and percentages to pixel values for the
'min-width', 'max-width', 'min-height', and 'max-height'
descriptors.
</li>
</ol>
<h4 id="resolve-initial-width-height" class="no-num no-toc">
Resolve initial <code lt="width!!resolved">width</code>
and <code lt="height!!resolved">height</code> from min/max
descriptors</h4>
<ol id="ol4">
<li>
If <code lt="min-width!!resolved">min-width</code> or
<code lt="max-width!!resolved">max-width</code> is not
''viewport-length/auto'', set <code>width = MAX(min-width, MIN(max-width,
initial-width))</code>
</li>
<li>
If <code lt="min-height!!resolved">min-height</code> or
<code lt="max-height!!resolved">max-height</code> is not
''viewport-length/auto'', set <code>height = MAX(min-height, MIN(max-height,
initial-height))</code>
</li>
</ol>
<h4 id="resolve-width" class="no-num no-toc">
Resolve <code lt="width!!resolved">width</code> value</h4>
<ol id="ol6">
<li>
If <code lt="width!!resolved">width</code> and
<code lt="height!!resolved">height</code> are both
''viewport-length/auto'', set <code>width = initial-width</code>
</li>
<li>
Otherwise, if <code lt="width!!resolved">width</code> is
''viewport-length/auto'', set <code>width = height * (initial-width /
initial-height)</code>, or <code>width = initial-width</code>
if <code class="index"
lt="height!!initial">initial-height</code> is 0.
</li>
</ol>
<h4 id="resolve-height" class="no-num no-toc">
Resolve <code lt="height!!resolved">height</code> value</h4>
<ol id="ol8">
<li>
If <code lt="height!!resolved">height</code> is ''viewport-length/auto'',
set <code>height = width * (initial-height /
initial-width)</code>, or <code>height = initial-height</code>
if <code class="index"
lt="width!!initial">initial-width</code> is 0.
</li>
</ol>
<h2 id="media-queries">
Media Queries</h2>
For several media features, the size of the initial containing block and
the orientation of the device affects the result of a media query
evaluation, which means that the effect of ''@viewport'' rules on
media queries needs extra attention.
From the Media Queries specification [[!MEDIAQ]]:
<blockquote>
<p>
“To avoid circular dependencies, it is never necessary
to apply the style sheet in order to evaluate expressions. For example,
the aspect ratio of a printed document may be influenced by a style sheet,
but expressions involving 'device-aspect-ratio' will be based
on the default aspect ratio of the user agent.”
</p>
</blockquote>
The UA must however cascade ''@viewport'' rules separately with the
''initial viewport'' size used for evaluating media feature
expressions and other values that depend on the viewport size to avoid
circular dependencies, but use the actual viewport size when cascading all other rules.
Procedure for applying CSS rules:
<ol>
<li>
Cascade all ''@viewport'' rules using the ''initial viewport''
size for values and evaluations which rely on viewport size
</li>
<li>
Compute the ''actual viewport'' from the cascaded viewport
descriptors
</li>
<li>
Cascade all other rules using the ''actual viewport'' size
</li>
</ol>
<p class="note">
The rationale for using the viewport descriptors obtained from applying
the ''@viewport'' rules for evaluating media queries for style
rules, is that media queries should match the ''actual viewport''
that the document will be laid out in and not the initial or the
one specified in the UA stylesheet. Consider the example below
given that the UA stylesheet has a viewport width of 980px, but an
''initial viewport'' width of 320px. The author has made separate
styles to make the document look good for initial containing block
widths above or below 400px. The ''actual viewport'' used will be
320px wide, and in order to match the styles with the ''actual
viewport'' width, the viewport resulting from applying the
''@viewport'' rules should be used to evaluate the media queries.
</p>
<div class="example">
Given an initial viewport width of 320px and a UA stylesheet viewport
width of 980px, the first media query will not match, but the second will.
<pre>
@viewport {
width: auto;
}
@media screen and (min-width: 400px) {
div { color: red; }
}
@media screen and (max-width: 400px) {
div { color: green; }
}
</pre>
</div>
Another example:
<div class="example">
The media query below should match because the ''@viewport'' rule
is applied before the media query is evaluated.
<pre>
@media screen and (width: 397px) {
div { color: green; }
}
@viewport {
width: 397px;
}
</pre>
</div>
Below is an example where an ''@viewport'' rule relies on a media
query affected by the viewport descriptors.
<div class="example">
The green color should be applied to a div because the
''initial viewport'' width is used to evaluate the media query
for the second ''@viewport'' rule, but the ''actual viewport''
is used for evaluating the media query when applying style rules.
<pre>
@viewport {
width: 397px;
}
@media screen and (width: 397px) {
@viewport {
width: 500px;
}
}
@media screen and (width: 397px) {
div { color: green; }
}
</pre>
</div>
It is recommended that authors do not write ''@viewport'' rules that
rely on media queries whose evaluation is affected by viewport
descriptors. Is is also recommended that the ''@viewport'' rule(s) is
placed as early in the document as possible to avoid unnecessary
re-evaluation of media queries or reflows.
<h2 id="cssom">
CSSOM</h2>
The ''@viewport'' rule is exposed to the CSSOM through a new CSSRule
interface.
<h3 id="css-rule-interface">
Interface <code>CSSRule</code></h3>
The following rule type is added to the <code>CSSRule</code>
interface. It provides identification for the new viewport rule.
<pre class=idl>
partial interface CSSRule {
const unsigned short VIEWPORT_RULE = 15;
};
</pre>
<h3 id="css-viewport-rule-interface">
Interface <code>CSSViewportRule</code></h3>
The <dfn interface>CSSViewportRule</dfn> interface represents the
style rule for an ''@viewport'' rule.
<pre class=idl>
[Exposed=Window]
interface CSSViewportRule : CSSRule {
readonly attribute CSSStyleDeclaration style;
};
</pre>
<dl dfn-type=attribute dfn-for=CSSViewportRule>
<dt><dfn>style</dfn> <span attribute-info for=style></span></dt>
<dd>
This attribute represents the viewport descriptors associated
with this ''@viewport'' rule.
</dd>
</dl>
<h2 id="viewport-meta">
Viewport <code class=html><META></code> element</h2>
<em>This section is not normative.</em>
This section describes a mapping from the content attribute of the
viewport <code class=html><META></code> element, first
implemented by Apple in the iPhone Safari browser, to the descriptors
of the ''@viewport'' rule described in this
specification.
In order to match the Safari implementation, the following parsing
algorithm and translation rules rely on the UA stylesheet below. See the
section on <a href="#ua-stylesheet">UA stylesheets</a> for an elaborate
description.
<pre>
@viewport {
width: extend-to-zoom 980px;
min-zoom: 0.25;
max-zoom: 5;
}
</pre>
<p class="note">
Note that these values might not fit well with all UAs. For
instance, with a min-zoom of 0.25 you will be able to fit the whole width
of the document inside the window for widths up to 1280px on a 320px wide
device like the original iPhone, but only 960px if you have a 240px
display (all widths being given in CSS pixel units).
</p>
<h3 id="meta-properties">
Properties</h3>
The recognized properties in the viewport
<code class=html><META></code> element are:
<ul>
<li><code class="index" lt="width!!viewport META">width</code></li>
<li><code class="index" lt="height!!viewport META">height</code></li>
<li><code class="index">initial-scale</code></li>
<li><code class="index">minimum-scale</code></li>
<li><code class="index">maximum-scale</code></li>
<li><code class="index">user-scalable</code></li>
</ul>
<h3 id="parsing-algorithm">
Parsing algorithm</h3>
Below is an algorithm for parsing the <code class=html>content</code>
attribute of the <code class=html><META></code> tag produced
from testing Safari on the iPhone. <span class="note"> The testing was
done on an iPod touch running iPhone OS 4. The UA string of the
browser: <code>"Mozilla/5.0 (iPod; U; CPU iPhone OS 4_0 like Mac OS X;
en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5
Mobile/8A293 Safari/6531.22.7"</code>.</span> The pseudo code notation
used is based on the notation used in [[Algorithms]].
The whitespace class contains the following characters (ascii):
<ul>
<li>Horizontal tab (0x09)</li>
<li>Line feed (0x0a)</li>
<li>Carriage return (0x0d)</li>
<li>Space (0x20)</li>
</ul>
The recognized separator between property/value pairs is comma for the