-
Notifications
You must be signed in to change notification settings - Fork 791
Expand file tree
/
Copy pathOverview.html
More file actions
executable file
·1711 lines (1326 loc) · 68.1 KB
/
Overview.html
File metadata and controls
executable file
·1711 lines (1326 loc) · 68.1 KB
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
<!DOCTYPE html>
<html lang=en>
<head>
<meta content="text/html; charset=utf-8" http-equiv=Content-Type>
<title>Media Queries Level 4</title>
<!--
<link href="http://purl.org/dc/terms/" rel="schema.dcterms">
<link href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright" rel="dcterms.rights">
-->
<meta content="Media Queries Level 4" name=dcterms.title>
<meta content=text name=dcterms.type>
<meta content=2013-08-30 name=dcterms.date>
<meta content="Florian Rivoal" name=dcterms.creator>
<meta content=W3C name=dcterms.publisher>
<meta content="http://dev.w3.org/csswg/mediaqueries4/"
name=dcterms.identifier>
<link href="#contents" rel=contents>
<link href="#index" rel=index>
<link href="../default.css" rel=stylesheet type="text/css">
<link href="http://www.w3.org/StyleSheets/TR/W3C-ED.css" rel=stylesheet
type="text/css">
<style type="text/css">
/* delete this block when you've cleared out all the .replaceme elements */
.replaceme {
border: solid red;
padding: 0 0.5em;
margin: 0 0.1em;
background: yellow;
color: green;
}
.replaceme:before {
content: "FIXME(";
color: black;
}
.replaceme:after {
content: ")";
color: black;
}
blockquote {
background: #eef;
padding: 0.5em;
margin: 1em 0;
border: thin solid black; }
pre { font-family: courier, monospace; font-weight: bold; white-space: pre-wrap }
.example pre em { font-style: normal }
span.label { font-style: italic }
</style>
<body>
<div class=head> <!--begin-logo-->
<p><a href="http://www.w3.org/"><img alt=W3C height=48
src="http://www.w3.org/Icons/w3c_home" width=72></a> <!--end-logo-->
<h1 id=media-queries>Media Queries Level 4</h1>
<h2 class="no-num no-toc" id=longstatus-date>Editor's Draft 30 August 2013</h2>
<dl>
<dt>This version:
<!-- <dd><a href="http://dev.w3.org/csswg/mediaqueries4/">http://www.w3.org/TR/2013/ED-mediaqueries4-20130830/</a> -->
<dd><a
href="http://dev.w3.org/csswg/mediaqueries4/">http://dev.w3.org/csswg/mediaqueries4/</a>
<dt>Latest version:
<dd>N/A
<dt>Editor's draft:
<dd><a
href="http://dev.w3.org/csswg/mediaqueries4/">http://dev.w3.org/csswg/mediaqueries4/</a>
<dt>Previous Version:
<dd>N/A
<dt>Issue Tracking:
<dd><a
href="http://www.w3.org/Style/CSS/Tracker/products/7">http://www.w3.org/Style/CSS/Tracker/products/7</a>
<dt>Feedback:
<dd><a
href="mailto:www-style@w3.org?subject=%5Bmediaqueries4%5D%20feedback">www-style@w3.org</a>
with subject line “<kbd>[mediaqueries4] <var>… message topic
…</var></kbd>” (<a
href="http://lists.w3.org/Archives/Public/www-style/"
rel=discussion>archives</a>)
<dt>Editors:
<dd class=vcard><span class=given-name>Florian</span> <span
class=family-name>Rivoal</span> <<span
class=email>florian @rivoal.net</span>>
<dt>Previous Editors:
<dd class=vcard><a class="url fn n"
href="http://people.opera.com/howcome/" lang=no> <span
class=given-name>Håkon</span> <span class=additional-name>Wium</span>
<span class=family-name>Lie</span></a> <<span
class=email>howcome @opera.com</span>>
<dd class=vcard><a class="url fn" href="http://tantek.com/"
lang=tr>Tantek Çelik</a> <<span
class=email>tantek @cs.stanford.edu</span>>
<dd class=vcard><span class=given-name>Daniel</span> <span
class=family-name>Glazman</span> <<span
class=email>daniel.glazman @disruptive-innovations.com</span>>
<dd class=vcard><a class="url fn n" href="http://annevankesteren.nl/"
hreflang=en lang=nl>Anne van Kesteren</a> <<span
class=email>annevk@opera.com</span>>
</dl>
<!--begin-copyright-->
<p class=copyright><a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright"
rel=license>Copyright</a> © 2013 <a href="http://www.w3.org/"><abbr
title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup> (<a
href="http://www.csail.mit.edu/"><abbr
title="Massachusetts Institute of Technology">MIT</abbr></a>, <a
href="http://www.ercim.eu/"><abbr
title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>,
<a href="http://www.keio.ac.jp/">Keio</a>, <a
href="http://ev.buaa.edu.cn/">Beihang</a>), All Rights Reserved. W3C <a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>,
<a
href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a>
and <a
href="http://www.w3.org/Consortium/Legal/copyright-documents">document
use</a> rules apply.</p>
<!--end-copyright-->
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc" id=abstract>Abstract</h2>
<p><em>Media Queries</em> allow authors to adapt the style applied to a
document based on the environment the document is being rendered in. <a
href="#HTML401" rel=biblioentry>[HTML401]<!--{{HTML401}}--></a> and <a
href="#CSS21" rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a> introduced this
mechanism, by allowing detection of the <em>media type</em>. For example,
a document may use sans-serif fonts when displayed on a screen and serif
fonts when printed. ‘<code class=css>screen</code>’ and ‘<code
class=css>print</code>’ are two media types that have been defined.
Media Queries Level 3 <a href="#MEDIAQ"
rel=biblioentry>[MEDIAQ]<!--{{MEDIAQ}}--></a> refined this mechanism by
allowing detection of individual characteristics, or <em>media
features</em>. For example, a document may use a different style when
displayed in ‘<code class=css>portrait</code>’ and in ‘<code
class=css>landscape</code>’ mode, as detected by the ‘<code
class=css>orientation</code>’ media feature.
<p>Media Queries Level 4 describes the mechanism, media types and media
features that already existed in <a href="#MEDIAQ"
rel=biblioentry>[MEDIAQ]<!--{{MEDIAQ}}--></a>, and further introduces new
media features.
<h2 class="no-num no-toc" id=status>Status of this document</h2>
<!--begin-status-->
<p>This is a public copy of the editors' draft. It is provided for
discussion only and may change at any moment. Its publication here does
not imply endorsement of its contents by W3C. Don't cite this document
other than as work in progress.
<p>The (<a
href="http://lists.w3.org/Archives/Public/www-style/">archived</a>) public
mailing list <a
href="mailto:www-style@w3.org?Subject=%5Bmediaqueries4%5D%20PUT%20SUBJECT%20HERE">
www-style@w3.org</a> (see <a
href="http://www.w3.org/Mail/Request">instructions</a>) is preferred for
discussion of this specification. When sending e-mail, please put the text
“mediaqueries4” in the subject, preferably like this:
“[<!---->mediaqueries4<!---->] <em>…summary of comment…</em>”
<p>This document was produced by the <a
href="http://www.w3.org/Style/CSS/members">CSS Working Group</a> (part of
the <a href="http://www.w3.org/Style/">Style Activity</a>).
<p>This document was produced by a group operating under the <a
href="http://www.w3.org/Consortium/Patent-Policy-20040205/">5 February
2004 W3C Patent Policy</a>. W3C maintains a <a
href="http://www.w3.org/2004/01/pp-impl/32061/status"
rel=disclosure>public list of any patent disclosures</a> made in
connection with the deliverables of the group; that page also includes
instructions for disclosing a patent. An individual who has actual
knowledge of a patent which the individual believes contains <a
href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential
Claim(s)</a> must disclose the information in accordance with <a
href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">section
6 of the W3C Patent Policy</a>.</p>
<!--end-status-->
<h2 class="no-num no-toc" id=contents> Table of contents</h2>
<!--begin-toc-->
<ul class=toc>
<li><a href="#intro"><span class=secno>1. </span> Introduction</a>
<ul class=toc>
<li><a href="#placement"><span class=secno>1.1. </span> Module
interactions</a>
<li><a href="#values"><span class=secno>1.2. </span> Values</a>
<li><a href="#units"><span class=secno>1.3. </span> Units</a>
</ul>
<li><a href="#media0"><span class=secno>2. </span>Media Queries</a>
<li><a href="#syntax"><span class=secno>3. </span>Syntax</a>
<ul class=toc>
<li><a href="#error-handling"><span class=secno>3.1. </span>Error
Handling</a>
</ul>
<li><a href="#media1"><span class=secno>4. </span>Media features</a>
<ul class=toc>
<li><a href="#width"><span class=secno>4.1. </span>width</a>
<li><a href="#height"><span class=secno>4.2. </span>height</a>
<li><a href="#device-width"><span class=secno>4.3.
</span>device-width</a>
<li><a href="#device-height"><span class=secno>4.4.
</span>device-height</a>
<li><a href="#orientation"><span class=secno>4.5. </span>orientation</a>
<li><a href="#aspect-ratio"><span class=secno>4.6.
</span>aspect-ratio</a>
<li><a href="#device-aspect-ratio"><span class=secno>4.7.
</span>device-aspect-ratio</a>
<li><a href="#color"><span class=secno>4.8. </span>color</a>
<li><a href="#color-index"><span class=secno>4.9. </span>color-index</a>
<li><a href="#monochrome"><span class=secno>4.10. </span>monochrome</a>
<li><a href="#resolution"><span class=secno>4.11. </span>resolution</a>
<li><a href="#scan"><span class=secno>4.12. </span>scan</a>
<li><a href="#grid"><span class=secno>4.13. </span>grid</a>
<li><a href="#script"><span class=secno>4.14. </span>script</a>
<li><a href="#pointer"><span class=secno>4.15. </span>pointer</a>
<li><a href="#hover"><span class=secno>4.16. </span>hover</a>
<li><a href="#luminosity"><span class=secno>4.17. </span>luminosity</a>
</ul>
<li><a href="#changes"><span class=secno>5. </span>Changes</a>
<ul class=toc>
<li><a href="#changes-2012"><span class=secno>5.1. </span>Changes Since
the Media Queries Level 3</a>
</ul>
<li><a href="#conformance"><span class=secno>6. </span> Conformance</a>
<ul class=toc>
<li><a href="#conventions"><span class=secno>6.1. </span> Document
conventions</a>
<li><a href="#conformance-classes"><span class=secno>6.2. </span>
Conformance classes</a>
<li><a href="#partial"><span class=secno>6.3. </span> Partial
implementations</a>
<li><a href="#experimental"><span class=secno>6.4. </span> Experimental
implementations</a>
<li><a href="#testing"><span class=secno>6.5. </span> Non-experimental
implementations</a>
</ul>
<li class=no-num><a href="#acknowledgments"> Acknowledgments</a>
<li class=no-num><a href="#references"> References</a>
<ul class=toc>
<li class=no-num><a href="#normative-references"> Normative
references</a>
<li class=no-num><a href="#other-references"> Other references</a>
</ul>
<li class=no-num><a href="#index"> Index</a>
</ul>
<!--end-toc-->
<h2 id=intro><span class=secno>1. </span> Introduction</h2>
<p><em>This section is not normative.</em>
<p>HTML4 <a href="#HTML401" rel=biblioentry>[HTML401]<!--{{HTML401}}--></a>
and CSS2 <a href="#CSS21" rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>
currently support media-dependent style sheets tailored for different
media types. For example, a document may use different style sheets for
screen and print. In HTML4, this can be written as:
<div class=example>
<pre><code><link rel="stylesheet" type="text/css" media="screen" href="sans-serif.css">
<link rel="stylesheet" type="text/css" media="print" href="serif.css"><code></code></code></pre>
</div>
<p>Inside a CSS style sheet, one can declare that sections apply to certain
media types:
<div class=example>
<pre><code>@media screen {
* { font-family: sans-serif }
}</code></pre>
</div>
<p>The ‘<code class=css>print</code>’ and ‘<code
class=css>screen</code>’ media types are defined in HTML4. The complete
list of media types in HTML4 is: ‘<code class=css>aural</code>’,
‘<code class=css>braille</code>’, ‘<code
class=css>handheld</code>’, ‘<code class=css>print</code>’, ‘<code
class=css>projection</code>’, ‘<code class=css>screen</code>’,
‘<code class=css>tty</code>’, ‘<code class=css>tv</code>’. CSS2
defines the same list, deprecates ‘<code class=css>aural</code>’ and
adds ‘<code class=css>embossed</code>’ and ‘<code
class=css>speech</code>’. Also, ‘<code class=css>all</code>’ is used
to indicate that the style sheet applies to all media types.
<p>Media-specific style sheets are supported by several user agents. The
most commonly used feature is to distinguish between ‘<code
class=css>screen</code>’ and ‘<code class=css>print</code>’.
<p>There have been requests for ways to describe in more detail what type
of output devices a style sheet applies to. Fortunately HTML4 foresaw
these requests and defined a forward-compatible syntax for media types.
Here is a quote from <a
href="http://www.w3.org/TR/1999/REC-html401-19991224/types.html#h-6.13">HTML4,
section 6.13</a>:
<blockquote
cite="http://www.w3.org/TR/1999/REC-html401-19991224/types.html#h-6.13">
<p>Future versions of HTML may introduce new values and may allow
parameterized values. To facilitate the introduction of these extensions,
conforming user agents must be able to parse the <a
href="http://www.w3.org/TR/1999/REC-html401-19991224/present/styles.html#adef-media"><samp>media</samp></a>
attribute value as follows:
<ol>
<li>The value is a comma-separated list of entries. For example,
<pre><code>media="screen, 3d-glasses, print and resolution > 90dpi"</code></pre>
<p>is mapped to:
<pre><code>"screen"
"3d-glasses"
"print and resolution > 90dpi"</code></pre>
<li>Each entry is truncated just before the first character that isn't a
US ASCII letter [a-zA-Z] (Unicode decimal 65-90, 97-122), digit [0-9]
(Unicode hex 30-39), or hyphen (45). In the example, this gives:
<pre><code>"screen"
"3d-glasses"
"print"</code></pre>
</ol>
</blockquote>
<p>Media queries, as described in this specification, build on the
mechanism outlined in HTML4. The syntax of media queries fit into the
media type syntax reserved in HTML4. The <code class=html>media</code>
attribute of HTML4 also exists in XHTML and generic XML. The same syntax
can also be used inside in the ‘<code class=css>@media</code>’ and
‘<code class=css>@import</code>’ rules of CSS.
<p>However, the parsing rules for media queries are incompatible with those
of HTML4 so that they are consistent with those of media queries used in
CSS.
<p class=note>HTML5 <a href="#HTML5"
rel=biblioentry>[HTML5]<!--{{HTML5}}--></a> (at the moment of writing
still work in progress) references the Media Queries specification
directly and thus updates the rules for HTML.
<h3 id=placement><span class=secno>1.1. </span> Module interactions</h3>
<p>This module replaces and extends the Media Queries, Media Type and Media
Features defined in <a href="#CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a> sections 7 and in <a
href="#MEDIAQ" rel=biblioentry>[MEDIAQ]<!--{{!MEDIAQ}}--></a>.
<h3 id=values><span class=secno>1.2. </span> Values</h3>
<p><em>This section is normative</em>
<p>Value types not defined in this specification, such as <integer>,
<number> or <resolution>, are defined in <a href="#CSS3VAL"
rel=biblioentry>[CSS3VAL]<!--{{!CSS3VAL}}--></a>. Other CSS modules may
expand the definitions of these value types.
<p>This specification also introduces one new value type.
<p>The <ratio> value type is a positive (not zero or negative)
<integer> followed by optional whitespace, followed by a solidus
(‘<code class=css>/</code>’), followed by optional whitespace,
followed by a positive <integer>.
<h3 id=units><span class=secno>1.3. </span> Units</h3>
<p><em>This section is normative</em>
<p>The units used in media queries are the same as in other parts of CSS,
as defined in <a href="#CSS3VAL"
rel=biblioentry>[CSS3VAL]<!--{{!CSS3VAL}}--></a>. For example, the pixel
unit represents CSS pixels and not physical pixels.
<p>Relative units in media queries are based on the initial value, which
means that units are never based on results of declarations. For example,
in HTML, the ‘<code class=css>em</code>’ unit is relative to the
initial value of ‘<code class=property>font-size</code>’.
<h2 id=media0><span class=secno>2. </span>Media Queries</h2>
<p>A media query consists of an optional media type and zero or more <span
class=index id=expressions>expressions</span> that check for the
conditions of particular <span class=index id=media-features>media
features</span>.
<p>Statements regarding media queries in this section assume the <a
href="#syntax">syntax section</a> is followed. Media queries that do not
conform to the syntax are discussed in the <a href="#error-handling">error
handling section</a>. I.e. the syntax takes precedence over requirements
in this section.
<div class=example>
<p>Here is a simple example written in HTML:
<pre><code><link rel="stylesheet" media="screen and (color)" href="example.css" /></code></pre>
<p>This example expresses that a certain style sheet
(<code>example.css</code>) applies to devices of a certain media type
(‘<code class=css>screen</code>’) with certain feature (it must be a
color screen).
</div>
<div class=example>
<p>Here the same media query written in an @import-rule in CSS:
<pre><code>@import url(color.css) screen and (color);</code></pre>
</div>
<p>A media query is a logical expression that is either true or false. A
media query is true if the media type of the media query matches the media
type of the device where the user agent is running (as defined in the
"Applies to" line), and all expressions in the media query are true.
<p>A shorthand syntax is offered for media queries that apply to all media
types; the keyword ‘<code class=css>all</code>’ can be left out (along
with the trailing ‘<code class=css>and</code>’). I.e. if the media
type is not explicitly given it is ‘<code class=css>all</code>’.
<div class=example>
<p>I.e. these are identical:
<pre><code>@media all and (min-width:500px) { … }
@media (min-width:500px) { … }</code></pre>
<p>As are these:
<pre><code>@media (orientation: portrait) { … }
@media all and (orientation: portrait) { … }</code></pre>
</div>
<p>Several media queries can be combined in a media query list. A
comma-separated list of media queries. If one or more of the media queries
in the comma-separated list are true, the whole list is true, and
otherwise false. In the media queries syntax, the comma expresses a
logical OR, while the ‘<code class=css>and</code>’ keyword expresses a
logical AND.
<div class=example>
<p>Here is an example of several media queries in a comma-separated list
using the an @media-rule in CSS:
<pre><code>@media <em>screen and (color), projection and (color)</em> { … }</code></pre>
</div>
<p>If the media query list is empty (i.e. the declaration is the empty
string or consists solely of whitespace) it evaluates to true.
<div class=example>
<p>I.e. these are equivalent:
<pre><code>@media all { … }
@media { … }</code></pre>
</div>
<p>The logical NOT can be expressed through the ‘<code
class=css>not</code>’ keyword. The presence of the keyword ‘<code
class=css>not</code>’ at the beginning of the media query negates the
result. I.e., if the media query had been true without the ‘<code
class=css>not</code>’ keyword it will become false, and vice versa. User
agents that only support media types (as described in HTML4) will not
recognize the ‘<code class=css>not</code>’ keyword and the associated
style sheet is therefore not applied.
<div class=example>
<pre><code><link rel="stylesheet" media="<em>not screen and (color)</em>" href="example.css" /></code></pre>
</div>
<p>The keyword ‘<code class=css>only</code>’ can also be used to hide
style sheets from older user agents. User agents must process media
queries starting with ‘<code class=css>only</code>’ as if the ‘<code
class=css>only</code>’ keyword was not present.
<div class=example>
<pre><code><link rel="stylesheet" media="<em>only screen and (color)</em>" href="example.css" /></code></pre>
</div>
<p>The media queries syntax can be used with HTML, XHTML, XML <a
href="#XMLSTYLE" rel=biblioentry>[XMLSTYLE]<!--{{XMLSTYLE}}--></a> and the
@import and @media rules of CSS.
<div class=example>
<p>Here is the same example written in HTML, XHTML, XML, @import and
@media:
<pre><code><link rel="stylesheet" media="<em>screen and (color), projection and (color)</em>" rel="stylesheet" href="example.css"></code></pre>
<pre><code><link rel="stylesheet" media="<em>screen and (color), projection and (color)</em>" rel="stylesheet" href="example.css" /></code></pre>
<pre><code><?xml-stylesheet media="<em>screen and (color), projection and (color)</em>" rel="stylesheet" href="example.css" ?></code></pre>
<pre><code>@import url(example.css) <em>screen and (color), projection and (color)</em>;</code></pre>
<pre><code>@media <em>screen and (color), projection and (color)</em> { … }</code></pre>
<p class=note>The <a href="#XMLSTYLE"
rel=biblioentry>[XMLSTYLE]<!--{{XMLSTYLE}}--></a> specification has not
yet been updated to use media queries in the <code>media</code>
pseudo-attribute.
</div>
<p>If a media feature does not apply to the device where the UA is running,
expressions involving the media feature will be false.
<div class=example>
<p>The media feature ‘<code class=css>device-aspect-ratio</code>’ only
applies to visual devices. On an aural device, expressions involving
‘<code class=css>device-aspect-ratio</code>’ will therefore always be
false:
<pre><code><link rel="stylesheet" media="aural and (device-aspect-ratio: 16/9)" href="example.css" /></code></pre>
</div>
<p>Expressions will always be false if the unit of measurement does not
apply to the device.
<div class=example>
<p>The ‘<code class=css>px</code>’ unit does not apply to ‘<code
class=css>speech</code>’ devices so the following media query is always
false:
<pre><code><link rel="stylesheet" media="speech and (min-device-width: 800px)" href="example.css" /></code></pre>
<p>Note that the media queries in this example would have been true if the
keyword ‘<code class=css>not</code>’ had been added to the beginning
of the media query.
</div>
<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 ‘<code class=css>device-aspect-ratio</code>’ will be based
on the default aspect ratio of the user agent.
<p class=note>User agents are expected, but not required, to re-evaluate
and re-layout the page in response to changes in the user environment, for
example if the device is tilted from landscape to portrait mode.
<h2 id=syntax><span class=secno>3. </span>Syntax</h2>
<p>The media query syntax is described in terms of the <a
href="http://www.w3.org/TR/CSS21/grammar.html">CSS2 grammar</a>. As such,
rules not defined here are defined in CSS2. The
<code>media_query_list</code> production defined below replaces the
<code>media_list</code> production from CSS2. <a href="#CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>
<pre>media_query_list
: S* [media_query [ ',' S* media_query ]* ]?
;
media_query
: [ONLY S+ | NOT S+]? media_type [ S+ AND S+ expression ]* S*
| expression [ S+ AND S+ expression ]* S*
;
media_type
: IDENT
;
expression
: '(' S* media_feature S* [ ':' S* expr ]? ')'
;
media_feature
: IDENT
;</pre>
<p>COMMENT tokens, as defined by CSS2, do not occur in the grammar (to keep
it readable), but any number of these tokens may appear anywhere between
other tokens. <a href="#CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>
<p>The following new definitions are introduced:
<pre>L l|\\0{0,4}(4c|6c)(\r\n|[ \t\r\n\f])?|\\l
Y y|\\0{0,4}(59|79)(\r\n|[ \t\r\n\f])?|\\y</pre>
<p>The following new tokens are introduced:
<pre>{O}{N}{L}{Y} {return ONLY;}
{N}{O}{T} {return NOT;}
{A}{N}{D} {return AND;}
{num}{D}{P}{I} {return RESOLUTION;}
{num}{D}{P}{C}{M} {return RESOLUTION;}</pre>
<p><code>RESOLUTION</code> is to be added to the CSS2 <code>term</code>
production.
<p>CSS style sheets are generally case-insensitive, and this is also the
case for media queries.
<p>In addition to conforming to the syntax, each media query needs to use
media types and media features according to their respective specification
in order to be considered conforming.
<div class=example>
<p>Only the first media query is conforming in the example below because
the "example" media type does not exist.
<pre><code>@media all { body { background:lime } }
@media example { body { background:red } }</code></pre>
</div>
<h3 id=error-handling><span class=secno>3.1. </span>Error Handling</h3>
<p>For media queries that are not conforming user agents need to follow the
rules described in this section.
<ul>
<li>
<p><strong>Unknown media types.</strong> Unknown media types evaluate to
false. Effectively, they are treated identically to known media types
that do not match the media type of the device. However, an exception is
made for media types ‘<code class=css>not</code>’, ‘<code
class=css>and</code>’, ‘<code class=css>only</code>’ and ‘<code
class=css>or</code>’. Even though they do match the IDENT production,
they must not be treated as unknown media types, but rather trigger the
malformed query clause.
<div class=example>
<p>The media query "<code>unknown</code>" will evaluate to false, unless
<code>unknown</code> is actually a supported media type. Similarly,
"<code>not unknown</code>" will evaluate to true.
</div>
<p class=note>Unknown media types are distinct from media types that do
not actually match the IDENT production. Those fall under the malformed
media query clause.
<li>
<p><strong>Unknown media features.</strong> User agents are to represent
a media query as "<code>not all</code>" when one of the specified media
features is not known.
<div class=example>
<pre><code><link rel="stylesheet" media="screen and (max-weight: 3kg) and (color), (color)" href="example.css" /></code></pre>
<p>In this example, the first media query will be represented as
"<code>not all</code>" and evaluate to false and the second media query
is evaluated as if the first had not been specified, effectively.
</div>
<div class=example>
<pre><code>@media (min-orientation:portrait) { … }</code></pre>
<p>Is represented as "<code>not all</code>" because the ‘<code
class=css>orientation</code>’ feature does not accept the ‘<code
class=css>min-</code>’ prefix.
</div>
<li>
<p><strong>Unknown media feature values.</strong> As with unknown media
features, user agents are to represent a media query as "<code>not
all</code>" when one of the specified media feature values is not known.
<div class=example>
<p>The media query <code>(color:20example)</code> specifies an unknown
value for the ‘<code class=css>color</code>’ media feature and is
therefore represented as "<code>not all</code>".
</div>
<div class=example>
<p>This media query is represented as "<code>not all</code>" because
negative lengths are not allowed for the ‘<code
class=css>width</code>’ media feature:
<pre><code>@media (min-width: -100px) { … }</code></pre>
</div>
<li>
<p><strong>Malformed media query.</strong> User agents are to handle
unexpected tokens encountered while parsing a media query by reading
until the end of the media query, while observing <a
href="http://www.w3.org/TR/CSS21/syndata.html#block">the rules for
matching pairs</a> of (), [], {}, "", and '', and correctly handling
escapes. Media queries with unexpected tokens are represented as
"<code>not all</code>". <a href="#CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>
<div class=example>
<pre><code>@media (example, all,), speech { /* only applicable to speech devices */ }
@media &test, screen { /* only applicable to screen devices */ }</code></pre>
</div>
<div class=example>
<p>The following is an malformed media query because having no space
between ‘<code class=css>and</code>’ and the expression is not
allowed. (That is reserved for the functional notation syntax.)
<pre><code>@media all and(color) { … }</code></pre>
</div>
<div class=example>
<p>The following is a malformed media query because it uses ‘<code
class=css>only</code>’ and ‘<code class=property>or</code>’ as
media types.
<pre><code>@media only and or { … }</code></pre>
</div>
<p>Media queries are expected to follow the error handling rules of the
host language as well.
<div class=example>
<pre><code>@media test;,all { body { background:lime } }</code></pre>
<p>… will not apply because the semicolon terminates the
<code>@media</code> rule in CSS.
</div>
</ul>
<h2 id=media1><span class=secno>4. </span>Media features</h2>
<p>Syntactically, media features resemble CSS properties: they have names
and accept certain values. There are, however, several important
differences between properties and media features:
<ul>
<li>Properties are used in <em>declarations</em> to give information about
how to present a document. Media features are used in
<em>expressions</em> to describe requirements of the output device.
<li>Most media features accept optional ‘<code class=css>min-</code>’
or ‘<code class=css>max-</code>’ prefixes to express "greater or
equal to" and "smaller or equal to" constraints. This syntax is used to
avoid "<" and ">" characters which may conflict with HTML and XML.
Those media features that accept prefixes will most often be used with
prefixes, but can also be used alone.
<li>Properties always require a value to form a declaration. Media
features, on the other hand, can also be used without a value. For a
media feature <var>feature</var>, <code>(<var>feature</var>)</code> will
evaluate to true if <code>(<var>feature</var>:<var>x</var>)</code> will
evaluate to true for a value <var>x</var> other than zero or zero
followed by a unit identifier (i.e., other than <code>0</code>,
<code>0px</code>, <code>0em</code>, etc.) or the keyword ‘<code
class=property>none</code>’. Media features that are prefixed by
min/max cannot be used without a value. When a media feature prefixed
with min/max is used without a value it makes the media query malformed.
<li>Properties may accept more complex values, e.g., calculations that
involve several other values. Media features only accept single values:
one keyword, one number, or a number with a unit identifier. (The only
exceptions are the ‘<code class=css>aspect-ratio</code>’ and ‘<code
class=css>device-aspect-ratio</code>’ media features.)
</ul>
<div class=example>
<p>For example, the ‘<code class=css>color</code>’ media feature can
form expressions without a value (‘<code class=css>(color)</code>’),
or with a value (‘<code class=css>(min-color: 1)</code>’).
</div>
<p class=note>This specification defines media features usable with visual
and tactile devices. Similarly, media features can be defined for aural
media types.
<h3 id=width><span class=secno>4.1. </span>width</h3>
<div class=media-feature><span class=label>Value:</span> <length><br>
<span class=label>Applies to:</span> visual and tactile media types<br>
<span class=label>Accepts min/max prefixes:</span> yes<br>
</div>
<p>The ‘<code class=css>width</code>’ media feature describes the width
of the targeted display area of the output device. For continuous media,
this is the width of the viewport (as described by CSS2, section 9.1.1 <a
href="#CSS21" rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>) including the
size of a rendered scroll bar (if any). For paged media, this is the width
of the page box (as described by CSS2, section 13.2 <a href="#CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>).
<p>A specified <length> cannot be negative.
<div class=example>
<p>For example, this media query expresses that the style sheet is usable
on printed output wider than 25cm:
<pre><code><link rel="stylesheet" media="print and (min-width: 25cm)" href="http://…" /></code></pre>
</div>
<div class=example>
<p>This media query expresses that the style sheet is usable on devices
with viewport (the part of the screen/paper where the document is
rendered) widths between 400 and 700 pixels:
<pre><code>@media screen and (min-width: 400px) and (max-width: 700px) { … }</code></pre>
</div>
<div class=example>
<p>This media query expresses that style sheet is usable on screen and
handheld devices if the width of the viewport is greater than 20em.
<pre><code>@media handheld and (min-width: 20em),
screen and (min-width: 20em) { … }</code></pre>
<p>The ‘<code class=css>em</code>’ value is relative to the initial
value of ‘font-size’.
</div>
<h3 id=height><span class=secno>4.2. </span>height</h3>
<div class=media-feature><span class=label>Value:</span> <length><br>
<span class=label>Applies to:</span> visual and tactile media types<br>
<span class=label>Accepts min/max prefixes:</span> yes<br>
</div>
<p>The ‘<code class=css>height</code>’ media feature describes the
height of the targeted display area of the output device. For continuous
media, this is the height of the viewport including the size of a rendered
scroll bar (if any). For paged media, this is the height of the page box.
<p>A specified <length> cannot be negative.
<h3 id=device-width><span class=secno>4.3. </span>device-width</h3>
<div class=media-feature><span class=label>Value:</span> <length><br>
<span class=label>Applies to:</span> visual and tactile media types<br>
<span class=label>Accepts min/max prefixes:</span> yes<br>
</div>
<p>The ‘<code class=css>device-width</code>’ media feature describes
the width of the rendering surface of the output device. For continuous
media, this is the width of the screen. For paged media, this is the width
of the page sheet size.
<p>A specified <length> cannot be negative.
<div class=example>
<pre><code>@media screen and (device-width: 800px) { … }</code></pre>
<p>In the example above, the style sheet will apply only to screens that
currently displays exactly 800 horizontal pixels. The ‘<code
class=css>px</code>’ unit is of the logical kind, as described in the
<a href="#units">Units</a> section.
</div>
<h3 id=device-height><span class=secno>4.4. </span>device-height</h3>
<div class=media-feature><span class=label>Value:</span> <length><br>
<span class=label>Applies to:</span> visual and tactile media types<br>
<span class=label>Accepts min/max prefixes:</span> yes<br>
</div>
<p>The ‘<code class=css>device-height</code>’ media feature describes
the height of the rendering surface of the output device. For continuous
media, this is the height of the screen. For paged media, this is the
height of the page sheet size.
<p>A specified <length> cannot be negative.
<div class=example>
<pre><code><link rel="stylesheet" media="screen and (device-height: 600px)" /></code></pre>
<p>In the example above, the style sheet will apply only to screens that
have exactly 600 vertical pixels. Note that the definition of the
‘<code class=css>px</code>’ unit is the same as in other parts of
CSS.
</div>
<h3 id=orientation><span class=secno>4.5. </span>orientation</h3>
<div class=media-feature><span class=label>Value:</span> portrait |
landscape<br>
<span class=label>Applies to:</span> bitmap media types<br>
<span class=label>Accepts min/max prefixes:</span> no<br>
</div>
<p>The ‘<code class=css>orientation</code>’ media feature is ‘<code
class=css>portrait</code>’ when the value of the ‘<code
class=css>height</code>’ media feature is greater than or equal to the
value of the ‘<code class=css>width</code>’ media feature. Otherwise
‘<code class=css>orientation</code>’ is ‘<code
class=css>landscape</code>’.
<div class=example>
<pre><code>@media all and (orientation:portrait) { … }
@media all and (orientation:landscape) { … }</code></pre>
</div>
<h3 id=aspect-ratio><span class=secno>4.6. </span>aspect-ratio</h3>
<div class=media-feature><span class=label>Value:</span> <ratio><br>
<span class=label>Applies to:</span> bitmap media types<br>
<span class=label>Accepts min/max prefixes:</span> yes<br>
</div>
<p>The ‘<code class=css>aspect-ratio</code>’ media feature is defined
as the ratio of the value of the ‘<code class=css>width</code>’ media
feature to the value of the ‘<code class=css>height</code>’ media
feature.
<h3 id=device-aspect-ratio><span class=secno>4.7.
</span>device-aspect-ratio</h3>
<div class=media-feature><span class=label>Value:</span> <ratio><br>
<span class=label>Applies to:</span> bitmap media types<br>
<span class=label>Accepts min/max prefixes:</span> yes<br>
</div>
<p>The ‘<code class=css>device-aspect-ratio</code>’ media feature is
defined as the ratio of the value of the ‘<code
class=css>device-width</code>’ media feature to the value of the
‘<code class=css>device-height</code>’ media feature.
<div class=example>
<p>For example, if a screen device with square pixels has 1280 horizontal
pixels and 720 vertical pixels (commonly referred to as "16:9"), the
following Media Queries will all match the device:
<pre><code>@media screen and (device-aspect-ratio: 16/9) { … }
@media screen and (device-aspect-ratio: 32/18) { … }
@media screen and (device-aspect-ratio: 1280/720) { … }
@media screen and (device-aspect-ratio: 2560/1440) { … }</code></pre>
</div>
<h3 id=color><span class=secno>4.8. </span>color</h3>
<div class=media-feature><span class=label>Value:</span>
<integer><br>
<span class=label>Applies to:</span> visual media types<br>
<span class=label>Accept min/max prefixes:</span> yes<br>
</div>
<p>The ‘<code class=css>color</code>’ media feature describes the
number of bits per color component of the output device. If the device is
not a color device, the value is zero.
<p>A specified <integer> cannot be negative.
<div class=example>
<p>For example, these two media queries express that a style sheet applies
to all color devices:
<pre><code>@media all and (color) { … }
@media all and (min-color: 1) { … }</code></pre>
</div>
<div class=example>
<p>This media query expresses that a style sheet applies to color devices
with 2 or more bits per color component:
<pre><code>@media all and (min-color: 2) { … }</code></pre>
</div>
<p>If different color components are represented by different number of
bits, the smallest number is used.
<div class=example>
<p>For instance, if an 8-bit color system represents the red component
with 3 bits, the green component with 3 bits and the blue component with
2 bits, the ‘<code class=css>color</code>’ media feature will have a
value of 2.
</div>