forked from w3c/csswg-drafts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverview.html
More file actions
executable file
·2529 lines (2088 loc) · 172 KB
/
Overview.html
File metadata and controls
executable file
·2529 lines (2088 loc) · 172 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=../default.css rel=stylesheet type=text/css>
<link href=../csslogo.ico rel="shortcut icon" type=image/x-icon>
<style>
body {
background: url("https://www.w3.org/StyleSheets/TR/logo-ED") top left no-repeat white;
background-attachment: fixed;
color: black;
font-family: sans-serif;
margin: 0 auto;
max-width: 50em;
padding: 2em 1em 2em 70px;
}
:link { color: #00C; background: transparent }
:visited { color: #609; background: transparent }
a[href]:active { color: #C00; background: transparent }
a[href]:hover { background: #ffa }
a[href] img { border-style: none }
h1, h2, h3, h4, h5, h6 { text-align: left }
h1, h2, h3 { color: #005A9C; }
h1 { font: 170% sans-serif }
h2 { font: 140% sans-serif }
h3 { font: 120% sans-serif }
h4 { font: bold 100% sans-serif }
h5 { font: italic 100% sans-serif }
h6 { font: small-caps 100% sans-serif }
.hide { display: none }
div.head { margin-bottom: 1em }
div.head h1 { margin-top: 2em; clear: both }
div.head table { margin-left: 2em; margin-top: 2em }
p.copyright { font-size: small }
p.copyright small { font-size: small }
pre { margin-left: 2em }
dt { font-weight: bold }
ul.toc, ol.toc {
list-style: none;
}
</style>
<style>svg.railroad-diagram{background-color:hsl(30,20%,95%);}svg.railroad-diagram path{stroke-width:3;stroke:black;fill:rgba(0,0,0,0);}svg.railroad-diagram text{font:bold 14px monospace;text-anchor:middle;}svg.railroad-diagram text.label{text-anchor:start;}svg.railroad-diagram text.comment{font:italic 12px monospace;}svg.railroad-diagram rect{stroke-width:3;stroke:black;fill:hsl(120,100%,90%);}</style><style>svg.railroad-diagram{background-color:hsl(30,20%,95%);}svg.railroad-diagram path{stroke-width:3;stroke:black;fill:rgba(0,0,0,0);}svg.railroad-diagram text{font:bold 14px monospace;text-anchor:middle;}svg.railroad-diagram text.label{text-anchor:start;}svg.railroad-diagram text.comment{font:italic 12px monospace;}svg.railroad-diagram rect{stroke-width:3;stroke:black;fill:hsl(120,100%,90%);}</style><style>svg.railroad-diagram{background-color:hsl(30,20%,95%);}svg.railroad-diagram path{stroke-width:3;stroke:black;fill:rgba(0,0,0,0);}svg.railroad-diagram text{font:bold 14px monospace;text-anchor:middle;}svg.railroad-diagram text.label{text-anchor:start;}svg.railroad-diagram text.comment{font:italic 12px monospace;}svg.railroad-diagram rect{stroke-width:3;stroke:black;fill:hsl(120,100%,90%);}</style><style>svg.railroad-diagram{background-color:hsl(30,20%,95%);}svg.railroad-diagram path{stroke-width:3;stroke:black;fill:rgba(0,0,0,0);}svg.railroad-diagram text{font:bold 14px monospace;text-anchor:middle;}svg.railroad-diagram text.label{text-anchor:start;}svg.railroad-diagram text.comment{font:italic 12px monospace;}svg.railroad-diagram rect{stroke-width:3;stroke:black;fill:hsl(120,100%,90%);}</style><style>
#pointer-hover-table { margin: 1em auto; text-align: center; border-collapse: collapse; max-width: 40em; }
#pointer-hover-table td, #pointer-hover-table th { padding: .5em; }
#pointer-hover-table thead tr+tr th { border-bottom: 1px solid silver; }
#pointer-hover-table tbody td:first-of-type { border-left: 1px solid silver; }
</style>
</head>
<body class=h-entry>
<div class=head>
<p data-fill-with=logo><a class=logo href=http://www.w3.org/>
<img alt=W3C height=48 src=http://www.w3.org/Icons/w3c_home width=72>
</a>
</p>
<h1 class="p-name no-ref" id=title>Media Queries Level 4</h1>
<h2 class="no-num no-toc no-ref heading settled heading" id=subtitle><span class=content>Editor’s Draft,
<span class=dt-updated><span class=value-title title=20140414>14 April 2014</span></span></span></h2>
<div data-fill-with=spec-metadata><dl><dt>This version:<dd><a class=u-url href=http://dev.w3.org/csswg/mediaqueries4/>http://dev.w3.org/csswg/mediaqueries4/</a><dt>Editor’s Draft:<dd><a href=http://dev.w3.org/csswg/mediaqueries4/>http://dev.w3.org/csswg/mediaqueries4/</a>
<dt>Feedback:</dt>
<dd><a href="mailto:www-style@w3.org?subject=%5Bmediaqueries%5D%20feedback">www-style@w3.org</a>
with subject line
“<kbd>[mediaqueries] <var>… message topic …</var></kbd>”(<a href=http://lists.w3.org/Archives/Public/www-style/ rel=discussion>archives</a>)<dt>Test Suite:<dd>None Yet<dt>Editors:
<dd class="p-author h-card vcard"><a class="p-name fn u-email email" href=mailto:florian@rivoal.net>Florian Rivoal</a> (<span class="p-org org">Invited Expert</span>)<dd class="p-author h-card vcard"><a class="p-name fn u-url url" href=http://xanthir.com/contact/>Tab Atkins Jr.</a> (<span class="p-org org">Google</span>)<dt>Former Editors:
<dd class="p-author h-card vcard"><a class="p-name fn u-email email" href=mailto:howcome@opera.com>Håkon Wium Lie</a> (<span class="p-org org">Opera</span>)<dd class="p-author h-card vcard"><a class="p-name fn u-email email" href=mailto:tantek@cs.standard.edu>Tantek Çelik</a> (<span class="p-org org">Mozilla</span>)<dd class="p-author h-card vcard"><a class="p-name fn u-email email" href=mailto:daniel@glazman.org>Daniel Glazman</a> (<span class="p-org org">Disruptive Innovations</span>)<dd class="p-author h-card vcard"><a class="p-name fn u-email email" href=mailto:annevk@annevk.nl>Anne van Kesteren</a> (<span class="p-org org">Mozilla</span>)<dt>Issue Tracking:<dd>Inline, and <a href=http://www.w3.org/Style/CSS/Tracker/products/7>http://www.w3.org/Style/CSS/Tracker/products/7</a></dl></div>
<div data-fill-with=warning></div>
<p class=copyright data-fill-with=copyright><a href=http://www.w3.org/Consortium/Legal/ipr-notice#Copyright>Copyright</a> © 2014 <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>
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc no-ref heading settled heading" id=abstract><span class=content>Abstract</span></h2>
<p class=p-summary data-fill-with=abstract><a data-link-type=dfn href=#media-query title="media queries">Media Queries</a> allow authors to test and query values or features of the user agent or display device, independent of the document being rendered. They are used in the CSS @media rule to conditionally apply styles to a document, and in various other contexts and languages, such as HTML and Javascript.<p>Media Queries Level 4 describes the mechanism and syntax of media queries, media types, and media features. It extends and supersedes the features defined in Media Queries Level 3.
<a href=http://www.w3.org/TR/CSS/>CSS</a> is a language for describing the rendering of structured documents
(such as HTML and XML)
on screen, on paper, in speech, etc.</p>
<h2 class="no-num no-toc no-ref heading settled heading" id=status><span class=content>Status of this document</span></h2>
<div data-fill-with=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=%5Bmediaqueries%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 “mediaqueries” in the subject,
preferably like this:
“[mediaqueries] <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>.</div>
<div data-fill-with=at-risk></div>
<h2 class="no-num no-toc no-ref heading settled heading" id=contents><span class=content>Table of Contents</span></h2>
<div data-fill-with=table-of-contents><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=#media><span class=secno>2</span> Media Queries</a>
<ul class=toc>
<li><a href=#mq-list><span class=secno>2.1</span> Combining Media Queries</a>
<li><a href=#mq-prefix><span class=secno>2.2</span> Media Query Modifiers</a>
<ul class=toc>
<li><a href=#mq-not><span class=secno>2.2.1</span> Negating a Media Query: the <a class=css data-link-type=maybe href=#valuedef-not title=not>not</a> keyword</a>
<li><a href=#mq-only><span class=secno>2.2.2</span> Hiding a Media Query From Legacy User Agents: the <a class=css data-link-type=maybe href=#valuedef-only title=only>only</a> keyword</a></ul>
<li><a href=#media-types><span class=secno>2.3</span> Media Types</a>
<li><a href=#mq-features><span class=secno>2.4</span> Media Features</a>
<ul class=toc>
<li><a href=#mq-ranges><span class=secno>2.4.1</span> Media Feature Types: “range” and “discrete”</a>
<li><a href=#mq-boolean-context><span class=secno>2.4.2</span> Evaluating Media Features in a Boolean Context</a>
<li><a href=#mq-range-context><span class=secno>2.4.3</span> Evaluating Media Features in a Range Context</a>
<li><a href=#mq-min-max><span class=secno>2.4.4</span> Using “min-” and “max-” Prefixes On Range Features</a></ul></ul>
<li><a href=#mq-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=#mf-dimensions><span class=secno>4</span> Screen/Device Dimensions 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=#aspect-ratio><span class=secno>4.3</span> aspect-ratio</a>
<li><a href=#orientation><span class=secno>4.4</span> orientation</a>
<li><a href=#device-width><span class=secno>4.5</span> device-width</a>
<li><a href=#device-height><span class=secno>4.6</span> device-height</a>
<li><a href=#device-aspect-ratio><span class=secno>4.7</span> device-aspect-ratio</a></ul>
<li><a href=#mf-display-quality><span class=secno>5</span> Display Quality Media Features</a>
<ul class=toc>
<li><a href=#resolution><span class=secno>5.1</span> resolution</a>
<li><a href=#scan><span class=secno>5.2</span> scan</a>
<li><a href=#grid><span class=secno>5.3</span> grid</a>
<li><a href=#update-frequency><span class=secno>5.4</span> update-frequency</a>
<li><a href=#mf-overflow-block><span class=secno>5.5</span> overflow-block</a>
<li><a href=#mf-overflow-inline><span class=secno>5.6</span> overflow-inline</a></ul>
<li><a href=#mf-colors><span class=secno>6</span> Color Media Features</a>
<ul class=toc>
<li><a href=#color><span class=secno>6.1</span> color</a>
<li><a href=#color-index><span class=secno>6.2</span> color-index</a>
<li><a href=#monochrome><span class=secno>6.3</span> monochrome</a></ul>
<li><a href=#mf-interaction><span class=secno>7</span> Interaction Media Features</a>
<ul class=toc>
<li><a href=#pointer><span class=secno>7.1</span> pointer</a>
<li><a href=#hover><span class=secno>7.2</span> hover</a></ul>
<li><a href=#mf-environment><span class=secno>8</span> Environment Media Features</a>
<ul class=toc>
<li><a href=#light-level><span class=secno>8.1</span> light-level</a></ul>
<li><a href=#mf-scripting><span class=secno>9</span> Scripting Media Features</a>
<ul class=toc>
<li><a href=#scripting><span class=secno>9.1</span> scripting</a></ul>
<li><a href=#assorted-issues><span class=secno>10</span> Assorted Issues</a>
<li><a href=#custom-mq><span class=secno>11</span> Custom Media Queries</a>
<ul class=toc>
<li><a href=#script-custom-mq><span class=secno>11.1</span> Script-based Custom Media Queries</a>
<li><a href=#custom-mq-cssom><span class=secno>11.2</span> CSSOM</a></ul>
<li><a href=#changes><span class=secno></span> Changes</a>
<ul class=toc>
<li><a href=#changes-2012><span class=secno></span> Changes Since the Media Queries Level 3</a></ul>
<li><a href=#acknowledgments><span class=secno></span> Acknowledgments</a>
<li><a href=#conformance><span class=secno></span> Conformance</a>
<ul class=toc>
<li><a href=#conventions><span class=secno></span> Document conventions</a>
<li><a href=#conformance-classes><span class=secno></span> Conformance classes</a>
<li><a href=#partial><span class=secno></span> Partial implementations</a>
<li><a href=#experimental><span class=secno></span> Experimental implementations</a>
<li><a href=#testing><span class=secno></span> Non-experimental implementations</a></ul>
<li><a href=#references><span class=secno></span> References</a>
<ul class=toc>
<li><a href=#normative><span class=secno></span> Normative References</a>
<li><a href=#informative><span class=secno></span> Informative References</a></ul>
<li><a href=#index><span class=secno></span> Index</a>
<li><a href=#property-index><span class=secno></span> Property index</a>
<ul class=toc>
<li><a href=#media-descriptor-table><span class=secno></span><span data-link-type=at-rule>@media</span> Descriptors</a></ul>
<li><a href=#issues-index><span class=secno></span>Issues Index</a></ul></div>
<h2 class="heading settled heading" data-level=1 id=intro><span class=secno>1 </span><span class=content>
Introduction</span><a class=self-link href=#intro></a></h2>
<p> <em>This section is not normative.</em>
<p> HTML4 <a data-biblio-type=informative data-link-type=biblio href=#html401 title=html401>[HTML401]</a> defined a mechanism to support media-dependent style sheets,
tailored for different <a data-link-type=dfn href=#media-type title="media types">media types</a>.
For example, a document may use different style sheets for screen and for print.
In HTML, this can be written as:
<div class=example>
<pre> <link rel="stylesheet" type="text/css" media="screen" href="style.css">
<link rel="stylesheet" type="text/css" media="print" href="print.css">
</pre> </div>
<p> CSS adapted and extended this functionality with its <a class=css data-link-type=maybe href=http://dev.w3.org/csswg/css-conditional-3/#at-ruledef-media title=@media>@media</a> and <a class=css data-link-type=maybe href=http://dev.w3.org/csswg/css-cascade-3/#at-ruledef-import title=@import>@import</a> rules,
adding the ability to query the value of individual features:
<div class=example>
Inside a CSS style sheet,
one can declare that sections apply to certain <a data-link-type=dfn href=#media-type title="media types">media types</a>:
<pre> @media screen {
* { font-family: sans-serif }
}
</pre>
<p> Similarly, stylesheets can be conditionally imported based on media queries:
<pre>@import "print-styles.css" print;</pre> </div>
<p> <a data-link-type=dfn href=#media-query title="media queries">Media queries</a> can be used with HTML, XHTML, XML <a data-biblio-type=informative data-link-type=biblio href=#xmlstyle title=xmlstyle>[XMLSTYLE]</a> and the @import and @media rules of CSS.
<div class=example>
Here is the same example written in HTML, XHTML, XML, @import and @media:
<pre> <link media="screen and (color), projection and (color)"
rel="stylesheet" href="example.css">
<link media="screen and (color), projection and (color)"
rel="stylesheet" href="example.css" />
<?xml-stylesheet media="screen and (color), projection and (color)"
rel="stylesheet" href="example.css" ?>
@import url(example.css) screen and (color), projection and (color);
@media screen and (color), projection and (color) { … }
</pre>
<p class=note> Note: The <a data-biblio-type=informative data-link-type=biblio href=#xmlstyle title=xmlstyle>[XMLSTYLE]</a> specification has not yet been updated to
use media queries in the <code>media</code> pseudo-attribute.
</div>
<h3 class="heading settled heading" data-level=1.1 id=placement><span class=secno>1.1 </span><span class=content>
Module interactions</span><a class=self-link href=#placement></a></h3>
<p> This module replaces and extends the Media Queries, Media Type and Media Features
defined in <a data-biblio-type=normative data-link-type=biblio href=#css21 title=css21>[CSS21]</a> sections 7 and in <a data-biblio-type=normative data-link-type=biblio href=#mediaq title=mediaq>[MEDIAQ]</a>.
<h3 class="heading settled heading" data-level=1.2 id=values><span class=secno>1.2 </span><span class=content>
Values</span><a class=self-link href=#values></a></h3>
<p> Value types not defined in this specification, such as <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-syntax-3/#typedef-integer title="<integer>"><integer></a>,
<a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#number-value title="<number>"><number></a> or <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#resolution-value title="<resolution>"><resolution></a>, are defined in <a data-biblio-type=normative data-link-type=biblio href=#css3val title=css3val>[CSS3VAL]</a>. Other CSS
modules may expand the definitions of these value types.
<p> This specification also introduces some new value types.
<p> The <dfn class=css-code data-dfn-type=type data-export="" id=typedef-ratio><ratio><a class=self-link href=#typedef-ratio></a></dfn> value type is a positive (not zero or negative)
<a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-syntax-3/#typedef-integer title="<integer>"><integer></a> followed by optional whitespace, followed by a solidus ('/'),
followed by optional whitespace, followed by a positive <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-syntax-3/#typedef-integer title="<integer>"><integer></a>.
<a class="production css-code" data-link-type=type href=#typedef-ratio title="<ratio>"><ratio></a>s can be ordered or compared by transforming them into the number
obtained by dividing their first <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-syntax-3/#typedef-integer title="<integer>"><integer></a> by their second <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-syntax-3/#typedef-integer title="<integer>"><integer></a>.
<p class=issue id=issue-2ae5b8ca><a class=self-link href=#issue-2ae5b8ca></a>
Reasonable to restrict <a class="production css-code" data-link-type=type href=#typedef-ratio title="<ratio>"><ratio></a> to <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-syntax-3/#typedef-integer title="<integer>"><integer></a>s?
I’ve seen aspect ratios written with decimal points in real life.
<p> The <dfn class=css-code data-dfn-type=type data-export="" id=typedef-mq-boolean><mq-boolean><a class=self-link href=#typedef-mq-boolean></a></dfn> value type is an <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-syntax-3/#typedef-integer title="<integer>"><integer></a>
with the value <span class=css data-link-type=maybe title=0>0</span> or <span class=css data-link-type=maybe title=1>1</span>.
Any other integer value is invalid.
<span class=note>Note that <span class=css data-link-type=maybe title=-0>-0</span> is always equivalent to <span class=css data-link-type=maybe title=0>0</span> in CSS,
and so is also accepted as a valid <a class="production css-code" data-link-type=type href=#typedef-mq-boolean title="<mq-boolean>"><mq-boolean></a> value.</span>
<h3 class="heading settled heading" data-level=1.3 id=units><span class=secno>1.3 </span><span class=content>
Units</span><a class=self-link href=#units></a></h3>
<p> The units used in media queries are the same as in other parts of CSS, as
defined in <a data-biblio-type=normative data-link-type=biblio href=#css3val title=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 <a class=css data-link-type=maybe href=http://dev.w3.org/csswg/css-values-3/#em title=em>em</a> unit is relative to the initial value of <a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-fonts-3/#propdef-font-size title=font-size>font-size</a>,
defined by the user agent or the user’s preferences,
not any styling on the page.
<h2 class="heading settled heading" data-level=2 id=media><span class=secno>2 </span><span class=content>
Media Queries</span><a class=self-link href=#media></a></h2>
<p> A <dfn data-dfn-type=dfn data-export="" id=media-query>media query<a class=self-link href=#media-query></a></dfn> is a method of testing certain aspects of the user agent
or device that the document is being displayed in.
<a data-link-type=dfn href=#media-query title="media queries">Media queries</a> are (almost) always independent of the contents of the document,
its styling,
or any other internal aspect;
they’re only dependent on “external” information
unless another feature explicitly specifies that it affects the resolution of Media Queries,
such as the <span class=css data-link-type=maybe title=@viewport>@viewport</span> rule.
<p> The syntax of a <a data-link-type=dfn href=#media-query title="media query">media query</a> consists of
an optional <a data-link-type=dfn href=#media-query-modifier title="media query modifier">media query modifier</a>,
an optional <a data-link-type=dfn href=#media-type title="media type">media type</a>,
and zero or more <a data-link-type=dfn href=#media-feature title="media features">media features</a>:
<div class=railroad><svg class=railroad-diagram height=191 viewBox="0 0 517 191" width=517>
<g transform="translate(.5 .5)">
<path d="M 20 31 v 20 m 10 -20 v 20 m -10 -10 h 20.5">
</path><g>
<path d="M40 41h0.0">
</path><path d="M476.0 41h0.0">
</path><path d="M40.0 41a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10">
</path><g>
<path d="M60.0 21h396">
</path></g><path d="M456.0 21a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10">
</path><path d="M40.0 41h20">
</path><g>
<path d="M60.0 41h74.0">
</path><path d="M382.0 41h74.0">
</path><g>
<path d="M134.0 41h0.0">
</path><path d="M218.0 41h0.0">
</path><path d="M134.0 41h20">
</path><g>
<path d="M154.0 41h44">
</path></g><path d="M198.0 41h20">
</path><path d="M134.0 41a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10">
</path><g>
<path d="M154.0 61h0.0">
</path><path d="M198.0 61h0.0">
</path><rect height=22 rx=10 ry=10 width=44 x=154.0 y=50>
</rect><text x=176.0 y=65>
not</text></g><path d="M198.0 61a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10">
</path></g><path d="M218.0 41h10">
</path><g>
<path d="M228.0 41h0.0">
</path><path d="M372.0 41h0.0">
</path><path d="M228.0 41h10">
</path><g>
<path d="M238.0 41h0.0">
</path><path d="M362.0 41h0.0">
</path><rect height=22 width=124 x=238.0 y=30>
</rect><text x=300.0 y=45>
media feature</text></g><path d="M362.0 41h10">
</path><path d="M238.0 41a10 10 0 0 0 -10 10v10a10 10 0 0 0 10 10">
</path><g>
<path d="M238.0 71h40.0">
</path><path d="M322.0 71h40.0">
</path><rect height=22 rx=10 ry=10 width=44 x=278.0 y=60>
</rect><text x=300.0 y=75>
and</text></g><path d="M362.0 71a10 10 0 0 0 10 -10v-10a10 10 0 0 0 -10 -10">
</path></g><path d="M372.0 41h10">
</path></g><path d="M456.0 41h20">
</path><path d="M40.0 41a10 10 0 0 1 10 10v69a10 10 0 0 0 10 10">
</path><g>
<path d="M60.0 130h0.0">
</path><path d="M456.0 130h0.0">
</path><g>
<path d="M60.0 130h0.0">
</path><path d="M152.0 130h0.0">
</path><path d="M60.0 130a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10">
</path><g>
<path d="M80.0 110h0.0">
</path><path d="M132.0 110h0.0">
</path><rect height=22 rx=10 ry=10 width=52 x=80.0 y=99>
</rect><text x=106.0 y=114>
only</text></g><path d="M132.0 110a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10">
</path><path d="M60.0 130h20">
</path><g>
<path d="M80.0 130h52">
</path></g><path d="M132.0 130h20">
</path><path d="M60.0 130a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10">
</path><g>
<path d="M80.0 150h4.0">
</path><path d="M128.0 150h4.0">
</path><rect height=22 rx=10 ry=10 width=44 x=84.0 y=139>
</rect><text x=106.0 y=154>
not</text></g><path d="M132.0 150a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10">
</path></g><path d="M152.0 130h10">
</path><g>
<path d="M162.0 130h0.0">
</path><path d="M262.0 130h0.0">
</path><rect height=22 width=100 x=162.0 y=119>
</rect><text x=212.0 y=134>
media type</text></g><path d="M262.0 130h10">
</path><g>
<path d="M272.0 130h0.0">
</path><path d="M456.0 130h0.0">
</path><path d="M272.0 130a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10">
</path><g>
<path d="M292.0 110h144">
</path></g><path d="M436.0 110a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10">
</path><path d="M272.0 130h20">
</path><g>
<path d="M292.0 130h0.0">
</path><path d="M436.0 130h0.0">
</path><path d="M292.0 130h10">
</path><g>
<path d="M302.0 130h0.0">
</path><path d="M426.0 130h0.0">
</path><rect height=22 width=124 x=302.0 y=119>
</rect><text x=364.0 y=134>
media feature</text></g><path d="M426.0 130h10">
</path><path d="M302.0 130a10 10 0 0 0 -10 10v10a10 10 0 0 0 10 10">
</path><g>
<path d="M302.0 160h40.0">
</path><path d="M386.0 160h40.0">
</path><rect height=22 rx=10 ry=10 width=44 x=342.0 y=149>
</rect><text x=364.0 y=164>
and</text></g><path d="M426.0 160a10 10 0 0 0 10 -10v-10a10 10 0 0 0 -10 -10">
</path></g><path d="M436.0 130h20">
</path></g></g><path d="M456.0 130a10 10 0 0 0 10 -10v-69a10 10 0 0 1 10 -10">
</path></g><path d="M 476 41 h 20 m -10 -10 v 20 m 10 -20 v 20">
</path></g></svg></div>
<p> A <a data-link-type=dfn href=#media-query title="media query">media query</a> is a logical expression that is either true or false.
A media query is true if:
<p> <ul>
<li>
the <a data-link-type=dfn href=#media-type title="media type">media type</a>,
if specified,
matches the media type of the device where the user agent is running, and
<li>
all specified <a data-link-type=dfn href=#media-feature title="media features">media features</a> are true.
</ul>
<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>
Here is a simple example written in HTML:
<pre><link rel="stylesheet" media="screen and (color)" href="example.css" /></pre>
<p> This example expresses that a certain style sheet
(<code>example.css</code>) applies to devices of a certain media type
(<a class=css data-link-type=maybe href=#valuedef-screen title=screen>screen</a>) with certain feature (it must be a color screen).
<p> Here is the same media query written in an @import-rule in CSS:
<pre>@import url(example.css) screen and (color);</pre> </div>
<p> User agents should re-evaluate <a data-link-type=dfn href=#media-query title="media queries">media queries</a> in response to changes in the user environment,
for example if the device is tiled from landscape to portrait orientation,
and change the behavior of any constructs dependent on those <a data-link-type=dfn href=#media-query title="media queries">media queries</a> accordingly.
<p> Unless another feature explicitly specifies that it affects the resolution of Media Queries, it is never necessary to apply a style sheet in order to evaluate expressions.
<p class=note> Note: CSS Device Adaptation <a data-biblio-type=informative data-link-type=biblio href=#css-device-adapt title=css-device-adapt>[CSS-DEVICE-ADAPT]</a>]
defines how <span class=css data-link-type=maybe title=@viewport>@viewport</span> rules interact with Media Queries.
<h3 class="heading settled heading" data-level=2.1 id=mq-list><span class=secno>2.1 </span><span class=content>
Combining Media Queries</span><a class=self-link href=#mq-list></a></h3>
<p> Several <a data-link-type=dfn href=#media-query title="media queries">media queries</a> can be combined into a comma-separated <dfn data-dfn-type=dfn data-export="" id=media-query-list>media query list<a class=self-link href=#media-query-list></a></dfn>.
<div class=railroad><svg class=railroad-diagram height=102 viewBox="0 0 249 102" width=249>
<g transform="translate(.5 .5)">
<path d="M 20 31 v 20 m 10 -20 v 20 m -10 -10 h 20.5">
</path><g>
<path d="M40 41h0.0">
</path><path d="M208.0 41h0.0">
</path><path d="M40.0 41a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10">
</path><g>
<path d="M60.0 21h128">
</path></g><path d="M188.0 21a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10">
</path><path d="M40.0 41h20">
</path><g>
<path d="M60.0 41h0.0">
</path><path d="M188.0 41h0.0">
</path><path d="M60.0 41h10">
</path><g>
<path d="M70.0 41h0.0">
</path><path d="M178.0 41h0.0">
</path><rect height=22 width=108 x=70.0 y=30>
</rect><text x=124.0 y=45>
media query</text></g><path d="M178.0 41h10">
</path><path d="M70.0 41a10 10 0 0 0 -10 10v10a10 10 0 0 0 10 10">
</path><g>
<path d="M70.0 71h40.0">
</path><path d="M138.0 71h40.0">
</path><rect height=22 rx=10 ry=10 width=28 x=110.0 y=60>
</rect><text x=124.0 y=75>
,</text></g><path d="M178.0 71a10 10 0 0 0 10 -10v-10a10 10 0 0 0 -10 -10">
</path></g><path d="M188.0 41h20">
</path></g><path d="M 208 41 h 20 m -10 -10 v 20 m 10 -20 v 20">
</path></g></svg></div>
<p> A <a data-link-type=dfn href=#media-query-list title="media query list">media query list</a> is true if <em>any</em> of its component <a data-link-type=dfn href=#media-query title="media queries">media queries</a> are true,
and false only if <em>all</em> of its component <a data-link-type=dfn href=#media-query title="media queries">media queries</a> are false.
<div class=example>
For example, the following <a data-link-type=dfn href=#media-query-list title="media query list">media query list</a> is true if either
the <a data-link-type=dfn href=#media-type title="media type">media type</a> is <a class=css data-link-type=maybe href=#valuedef-screen title=screen>screen</a> and it’s a color device,
<strong>or</strong> the <a data-link-type=dfn href=#media-type title="media type">media type</a> is <a class=css data-link-type=maybe href=#valuedef-projection title=projection>projection</a> and it’s a color device:
<pre>@media screen and (color), projection and (color) { … }
</pre> </div>
<p> An empty <a data-link-type=dfn href=#media-query-list title="media query list">media query list</a> evaluates to true.
<div class=example>
For example, these are equivalent:
<pre>@media all { … }
@media { … }
</pre> </div>
<h3 class="heading settled heading" data-level=2.2 id=mq-prefix><span class=secno>2.2 </span><span class=content>
Media Query Modifiers</span><a class=self-link href=#mq-prefix></a></h3>
<p> A <a data-link-type=dfn href=#media-query title="media query">media query</a> may optionally be prefixed by a single <dfn data-dfn-type=dfn data-export="" id=media-query-modifier>media query modifier<a class=self-link href=#media-query-modifier></a></dfn>,
which is a single keyword which alters the meaning of the following <a data-link-type=dfn href=#media-query title="media query">media query</a>.
<h4 class="heading settled heading" data-level=2.2.1 id=mq-not><span class=secno>2.2.1 </span><span class=content>
Negating a Media Query: the <a class=css data-link-type=maybe href=#valuedef-not title=not>not</a> keyword</span><a class=self-link href=#mq-not></a></h4>
<p> An individual <a data-link-type=dfn href=#media-query title="media query">media query</a> can have its result negated
by prefixing it with the keyword <dfn class=css-code data-dfn-for=@media data-dfn-type=value data-export="" id=valuedef-not>not<a class=self-link href=#valuedef-not></a></dfn>.
If the <a data-link-type=dfn href=#media-query title="media query">media query</a> would normally evaluate to true,
prefixing it with <a class=css data-link-type=maybe href=#valuedef-not title=not>not</a> makes it evaluate to false,
and vice versa.
<div class=example>
For example, the following will apply to everything except color-capable screens.
Note that the entire media query is negated,
not just the <a data-link-type=dfn href=#media-type title="media type">media type</a>.
<pre><link rel="stylesheet" media="not screen and (color)" href="example.css" /></pre> </div>
<h4 class="heading settled heading" data-level=2.2.2 id=mq-only><span class=secno>2.2.2 </span><span class=content>
Hiding a Media Query From Legacy User Agents: the <a class=css data-link-type=maybe href=#valuedef-only title=only>only</a> keyword</span><a class=self-link href=#mq-only></a></h4>
<p> The concept of <a data-link-type=dfn href=#media-query title="media queries">media queries</a> originates from HTML4 <a data-biblio-type=informative data-link-type=biblio href=#html401 title=html401>[HTML401]</a>.
That specification only defined <a data-link-type=dfn href=#media-type title="media types">media types</a>,
but had a forward-compatible syntax that accommodated the addition of future concepts like <a data-link-type=dfn href=#media-feature title="media features">media features</a>:
it would consume the characters of a <a data-link-type=dfn href=#media-query title="media query">media query</a> up to the first non-alphanumeric character,
and interpret that as a <a data-link-type=dfn href=#media-type title="media type">media type</a>,
ignoring the rest.
For example, the <a data-link-type=dfn href=#media-query title="media query">media query</a> <span class=css data-link-type=maybe title="screen and (color)">screen and (color)</span>
would be truncated to just <a class=css data-link-type=maybe href=#valuedef-screen title=screen>screen</a>.
<p> Unfortunately, this means that legacy user agents using this error-handling behavior
will ignore any <a data-link-type=dfn href=#media-feature title="media features">media features</a> in a <a data-link-type=dfn href=#media-query title="media query">media query</a>,
even if they’re far more important than the <a data-link-type=dfn href=#media-type title="media type">media type</a> in the query.
This can result in styles accidentally being applied in inappropriate situations.
<p> To hide these <a data-link-type=dfn href=#media-query title="media queries">media queries</a> from legacy user agents,
the <a data-link-type=dfn href=#media-query title="media query">media query</a> can be prefixed with the keyword <dfn class=css-code data-dfn-for=@media data-dfn-type=value data-export="" id=valuedef-only>only<a class=self-link href=#valuedef-only></a></dfn>.
The <a class=css data-link-type=maybe href=#valuedef-only title=only>only</a> keyword <strong>has no effect</strong> on the <a data-link-type=dfn href=#media-query title="media query">media query</a>’s result,
but will cause the <a data-link-type=dfn href=#media-query title="media query">media query</a> to be parsed by legacy user agents
as specifying the unknown <a data-link-type=dfn href=#media-type title="media type">media type</a> “only”,
and thus be ignored.
<div class=example>
In this example, the stylesheet specified by the <code><link></code> element
will not be used by legacy user agents,
even if they would normally match the <a class=css data-link-type=maybe href=#valuedef-screen title=screen>screen</a> <a data-link-type=dfn href=#media-type title="media type">media type</a>.
<pre><link rel="stylesheet" media="only screen and (color)" href="example.css" /></pre> </div>
<p class=note> Note: Note that the <a class=css data-link-type=maybe href=#valuedef-only title=only>only</a> keyword can only be used before a <a data-link-type=dfn href=#media-type title="media type">media type</a>.
A <a data-link-type=dfn href=#media-query title="media query">media query</a> consisting only of <a data-link-type=dfn href=#media-feature title="media features">media features</a>,
or one with another <a data-link-type=dfn href=#media-query-modifier title="media query modifier">media query modifier</a> like <a class=css data-link-type=maybe href=#valuedef-not title=not>not</a>,
will be treated as false by legacy user agents automatically.
<p class=note> Note: At the time of publishing this specification,
such legacy user agents are extremely rare,
and so using the <a class=css data-link-type=maybe href=#valuedef-only title=only>only</a> modifier is rarely, if ever, necessary.
<h3 class="heading settled heading" data-level=2.3 id=media-types><span class=secno>2.3 </span><span class=content>
Media Types</span><a class=self-link href=#media-types></a></h3>
<p> A <dfn data-dfn-type=dfn data-export="" id=media-type>media type<a class=self-link href=#media-type></a></dfn> is a broad category of user-agent devices
on which a document may be displayed.
The original set of <a data-link-type=dfn href=#media-type title="media types">media types</a> were defined in HTML4,
for the <code>media</code> attribute on <code><link></code> elements.
<p> Unfortunately, <a data-link-type=dfn href=#media-type title="media types">media types</a> have proven insufficient as a way of discriminating between devices with different styling needs.
Some categories which were originally quite distinct,
such as <a class=css data-link-type=maybe href=#valuedef-screen title=screen>screen</a> and <a class=css data-link-type=maybe href=#valuedef-handheld title=handheld>handheld</a>,
have blended significantly in the years since their invention.
Others, such as <a class=css data-link-type=maybe href=#valuedef-tty title=tty>tty</a> or <a class=css data-link-type=maybe href=#valuedef-tv title=tv>tv</a>,
expose useful differences from the norm of a full-featured computer monitor,
and so are potentially useful to target with different styling,
but the definition of <a data-link-type=dfn href=#media-type title="media types">media types</a> as mutually exclusive
makes it difficult to use them in a reasonable manner;
instead, their exclusive aspects are better expressed as <a data-link-type=dfn href=#media-feature title="media features">media features</a>
such as <a class=property data-link-type=propdesc href=#descdef-grid title=grid>grid</a> or <a class=property data-link-type=propdesc href=#descdef-scan title=scan>scan</a>.
<p> As such, the following <a data-link-type=dfn href=#media-type title="media types">media types</a> are defined for use in <a data-link-type=dfn href=#media-query title="media queries">media queries</a>:
<dl data-dfn-for=@media data-dfn-type=value>
<dt><dfn class=css-code data-dfn-for=@media data-dfn-type=value data-export="" id=valuedef-all>all<a class=self-link href=#valuedef-all></a></dfn>
<dd>Matches all devices.
<dt><dfn class=css-code data-dfn-for=@media data-dfn-type=value data-export="" id=valuedef-print>print<a class=self-link href=#valuedef-print></a></dfn>
<dd>Matches printers, and devices intended to reproduce a printed display,
such as a web browser showing a document in “Print Preview”.
<dt><dfn class=css-code data-dfn-for=@media data-dfn-type=value data-export="" id=valuedef-screen>screen<a class=self-link href=#valuedef-screen></a></dfn>
<dd>Matches all devices that aren’t matched by <a class=css data-link-type=maybe href=#valuedef-print title=print>print</a> or <a class=css data-link-type=maybe href=#valuedef-speech title=speech>speech</a>.
<dt><dfn class=css-code data-dfn-for=@media data-dfn-type=value data-export="" id=valuedef-speech>speech<a class=self-link href=#valuedef-speech></a></dfn>
<dd>Matches screenreaders and similar devices that “read out” a page.
</dl>
<p> In addition, the following <strong>deprecated</strong> <a data-link-type=dfn href=#media-type title="media types">media types</a> are defined.
Authors must not use these <a data-link-type=dfn href=#media-type title="media types">media types</a>;
instead, it is recommended that they select appropriate <a data-link-type=dfn href=#media-feature title="media features">media features</a>
that better represent the aspect of the device that they are attempting to style against.
<p> User agents must recognize the following <a data-link-type=dfn href=#media-type title="media types">media types</a> as valid,
but must make them match nothing.
<p> <ul data-dfn-for=@media data-dfn-type=value>
<li><dfn class=css-code data-dfn-for=@media data-dfn-type=value data-export="" id=valuedef-tty>tty<a class=self-link href=#valuedef-tty></a></dfn>
<li><dfn class=css-code data-dfn-for=@media data-dfn-type=value data-export="" id=valuedef-tv>tv<a class=self-link href=#valuedef-tv></a></dfn>
<li><dfn class=css-code data-dfn-for=@media data-dfn-type=value data-export="" id=valuedef-projection>projection<a class=self-link href=#valuedef-projection></a></dfn>
<li><dfn class=css-code data-dfn-for=@media data-dfn-type=value data-export="" id=valuedef-handheld>handheld<a class=self-link href=#valuedef-handheld></a></dfn>
<li><dfn class=css-code data-dfn-for=@media data-dfn-type=value data-export="" id=valuedef-braille>braille<a class=self-link href=#valuedef-braille></a></dfn>
<li><dfn class=css-code data-dfn-for=@media data-dfn-type=value data-export="" id=valuedef-embossed>embossed<a class=self-link href=#valuedef-embossed></a></dfn>
<li><dfn class=css-code data-dfn-for=@media data-dfn-type=value data-export="" id=valuedef-aural>aural<a class=self-link href=#valuedef-aural></a></dfn>
</ul>
<p class=note> Note: It is expected that all of the media types will also be deprecated in time,
as appropriate <a data-link-type=dfn href=#media-feature title="media features">media features</a> are defined which capture their important differences.
<h3 class="heading settled heading" data-level=2.4 id=mq-features><span class=secno>2.4 </span><span class=content>
Media Features</span><a class=self-link href=#mq-features></a></h3>
<p> A <dfn data-dfn-type=dfn data-export="" id=media-feature>media feature<a class=self-link href=#media-feature></a></dfn> is a more fine-grained test than <a data-link-type=dfn href=#media-type title="media types">media types</a>,
testing a single, specific feature of the user agent or display device.
<p> Syntactically, <a data-link-type=dfn href=#media-feature title="media features">media features</a> resemble CSS properties:
they consist of a feature name, a colon, and a value to test for.
They may also be written in boolean form as just a feature name,
or in range form with a comparison operator.
<div class=railroad><svg class=railroad-diagram height=122 viewBox="0 0 545 122" width=545>
<g transform="translate(.5 .5)">
<path d="M 20 21 v 20 m 10 -20 v 20 m -10 -10 h 20.5">
</path><path d="M40 31h10">
</path><g>
<path d="M50 31h0.0">
</path><path d="M78.0 31h0.0">
</path><rect height=22 rx=10 ry=10 width=28 x=50.0 y=20>
</rect><text x=64.0 y=35>
(</text></g><path d="M78 31h10">
</path><g>
<path d="M88 31h0.0">
</path><path d="M456.0 31h0.0">
</path><path d="M88.0 31h20">
</path><g>
<path d="M108.0 31h0.0">
</path><path d="M436.0 31h0.0">
</path><path d="M108.0 31h10">
</path><g>
<path d="M118.0 31h0.0">
</path><path d="M234.0 31h0.0">
</path><rect height=22 width=116 x=118.0 y=20>
</rect><text x=176.0 y=35>
feature name</text></g><path d="M234.0 31h10">
</path><path d="M244.0 31h10">
</path><g>
<path d="M254.0 31h0.0">
</path><path d="M282.0 31h0.0">
</path><rect height=22 rx=10 ry=10 width=28 x=254.0 y=20>
</rect><text x=268.0 y=35>
:</text></g><path d="M282.0 31h10">
</path><path d="M292.0 31h10">
</path><g>
<path d="M302.0 31h0.0">
</path><path d="M426.0 31h0.0">
</path><rect height=22 width=124 x=302.0 y=20>
</rect><text x=364.0 y=35>
feature value</text></g><path d="M426.0 31h10">
</path></g><path d="M436.0 31h20">
</path><path d="M88.0 31a10 10 0 0 1 10 10v10a10 10 0 0 0 10 10">
</path><g>
<path d="M108.0 61h106.0">
</path><path d="M330.0 61h106.0">
</path><rect height=22 width=116 x=214.0 y=50>
</rect><text x=272.0 y=65>
feature name</text></g><path d="M436.0 61a10 10 0 0 0 10 -10v-10a10 10 0 0 1 10 -10">
</path><path d="M88.0 31a10 10 0 0 1 10 10v40a10 10 0 0 0 10 10">
</path><g>
<path d="M108.0 91h50.5">
</path><path d="M385.5 91h50.5">
</path><path d="M158.5 91h10">
</path><g>
<path d="M168.5 91h0.0">
</path><path d="M268.5 91h0.0">
</path><rect height=22 width=100 x=168.5 y=80>
</rect><text x=218.5 y=95>
range form</text></g><path d="M268.5 91h10">
</path><path d="M278.5 91h10">
</path><g>
<path d="M288.5 91h0.0">
</path><path d="M375.5 91h0.0">
</path><text class=comment x=332.0 y=96>
(see below)</text></g><path d="M375.5 91h10">
</path></g><path d="M436.0 91a10 10 0 0 0 10 -10v-40a10 10 0 0 1 10 -10">
</path></g><path d="M456 31h10">
</path><g>
<path d="M466 31h0.0">
</path><path d="M494.0 31h0.0">
</path><rect height=22 rx=10 ry=10 width=28 x=466.0 y=20>
</rect><text x=480.0 y=35>
)</text></g><path d="M494 31h10">
</path><path d="M 504 31 h 20 m -10 -10 v 20 m 10 -20 v 20">
</path></g></svg></div>
<p> There are, however, several important differences between properties and media features:
<p> <ul>
<li>
Properties are used to give information about how to present a document.
Media features are used to describe requirements of the output device.
<li>
Media features are always wrapped in parentheses
and combined with the <span class=css data-link-type=maybe title=and>and</span> keyword,
like <span class=css data-link-type=maybe title="(color) and (min-width: 600px)">(color) and (min-width: 600px)</span>,
rather than being separated with semicolons.
<li>
A media feature may be given with <em>only</em> its name
(omitting the colon and value)
to evaluate the feature in a <a data-link-type=dfn href=#boolean-context title="boolean context">boolean context</a>.
This is a convenient shorthand for features that have a reasonable value representing 0 or “none”.
For example, <span class=css data-link-type=maybe title=(color)>(color)</span> is true is the <a class=property data-link-type=propdesc href=#descdef-color title=color>color</a> <a data-link-type=dfn href=#media-feature title="media feature">media feature</a> is non-zero.
<li>
<a data-link-type=dfn href=#media-feature title="media features">Media features</a> with “range” type can be written in a <a data-link-type=dfn href=#range-context title="range context">range context</a>,
which uses standard mathematical comparison operators rather than a colon,
or have their feature names <a href=#mq-min-max>prefixed with “min-” or “max-”</a>.
<li>
Properties sometimes accept complex values,
e.g., calculations that involve several other values.
<a data-link-type=dfn href=#media-feature title="media features">Media features</a> only accept single values: one keyword, one number, etc.
</ul>
<p> If a media feature does not apply to the device where the UA is running,
that <a data-link-type=dfn href=#media-feature title="media feature">media feature</a> will always be false.
<div class=example>
The media feature <span class=css data-link-type=maybe title=device-aspect-ratio>device-aspect-ratio</span> only applies to
visual devices. On an <a class=css data-link-type=maybe href=#valuedef-speech title=speech>speech</a> device, expressions involving
<span class=css data-link-type=maybe title=device-aspect-ratio>device-aspect-ratio</span> will therefore always be false:
<pre> <link media="speech and (device-aspect-ratio: 16/9)"
rel="stylesheet" href="example.css">
</pre> </div>
<h4 class="heading settled heading" data-level=2.4.1 id=mq-ranges><span class=secno>2.4.1 </span><span class=content>
Media Feature Types: “range” and “discrete”</span><a class=self-link href=#mq-ranges></a></h4>
<p> Every media feature defines its “type” as either “range” or “discrete” in its definition table.
<p> “Discrete” media features,
like <a class=property data-link-type=propdesc href=#descdef-light-level title=light-level>light-level</a> or <a class=property data-link-type=propdesc href=#descdef-scripting title=scripting>scripting</a>,
take their values from a set.
The values may be keywords
or boolean numbers (0 and 1),
but the common factor is that there’s no intrinsic “order” to them—<wbr>none of the values are “less than” or “greater than” each other.
<p> “Range” media features like <a class=property data-link-type=propdesc href=#descdef-width title=width>width</a>, on the other hand,
take their values from a range.
Any two values can be compared to see which is lesser and which is greater.
<p> The only significant difference between the two types is that “range” <a data-link-type=dfn href=#media-feature title="media features">media features</a>
can be evaluated in a <a data-link-type=dfn href=#range-context title="range context">range context</a>
and accept “min-” and “max-” prefixes on their name.
Doing either of these changes the meaning of the feature—<wbr>rather than the <a data-link-type=dfn href=#media-feature title="media feature">media feature</a> being true when the feature exactly matches the given value,
it matches when the feature is greater than/less than/equal to the given value.
<div class=example>
A <span class=css data-link-type=maybe title="(width >= 600px)">(width >= 600px)</span> <a data-link-type=dfn href=#media-feature title="media feature">media feature</a> is true
when the viewport’s width is <span class=css data-link-type=maybe title=600px>600px</span> <em>or more</em>.
<p> On the other hand, <span class=css data-link-type=maybe title="(width: 600px)">(width: 600px)</span> by itself is only true
when the viewport’s width is <em>exactly</em> <span class=css data-link-type=maybe title=600px>600px</span>.
If it’s less or greater than <span class=css data-link-type=maybe title=600px>600px</span>, it’ll be false.
</div>
<h4 class="heading settled heading" data-level=2.4.2 id=mq-boolean-context><span class=secno>2.4.2 </span><span class=content>
Evaluating Media Features in a Boolean Context</span><a class=self-link href=#mq-boolean-context></a></h4>
<p> While <a data-link-type=dfn href=#media-feature title="media features">media features</a> normally have a syntax similar to CSS properties,
they can also be written more simply as just the feature name,
like <span class=css data-link-type=maybe title=(color)>(color)</span>.
<p> When written like this, the <a data-link-type=dfn href=#media-feature title="media feature">media feature</a> is evaluated in a <dfn data-dfn-type=dfn data-export="" id=boolean-context>boolean context<a class=self-link href=#boolean-context></a></dfn>.
If the feature would be true for the number <span class=css data-link-type=maybe title=0>0</span>,
a dimension with the value <span class=css data-link-type=maybe title=0>0</span>,
or the keyword <a class=css data-link-type=maybe href=#valuedef-none0 title=none>none</a>,
the <a data-link-type=dfn href=#media-feature title="media feature">media feature</a> evaluates to false.
If it would be true for any values <strong>other than</strong> the above,
it evaluates to true.
Otherwise, it evaluates to false.
<p class=note> Note: The “trichotomy” above allows for correct handling of MQs as false when on devices where they don’t apply at all,
such as <a class=property data-link-type=propdesc href=#descdef-scan title=scan>scan</a> on a speech device.
<div class=example>
Some <a data-link-type=dfn href=#media-feature title="media features">media features</a> are designed to be written like this.
<p> For example, <a class=property data-link-type=propdesc href=#descdef-scripting title=scripting>scripting</a> is typically written as <span class=css data-link-type=maybe title=(scripting)>(scripting)</span> to test if scripting is enabled,
or <span class=css data-link-type=maybe title="not (scripting)">not (scripting)</span> to see if it’s disabled.
<p> It can still be given an explicit value as well,
with <span class=css data-link-type=maybe title="(scripting: enabled)">(scripting: enabled)</span> equal to <span class=css data-link-type=maybe title=(scripting)>(scripting)</span>,
and <span class=css data-link-type=maybe title="(scripting: none)">(scripting: none)</span> equal to <span class=css data-link-type=maybe title="not (scripting)">not (scripting)</span>.
</div>
<div class=example>
Some numeric <a data-link-type=dfn href=#media-feature title="media features">media features</a>, like <a class=property data-link-type=propdesc href=#descdef-width title=width>width</a>,
are rarely if ever useful to evaluate in a <a data-link-type=dfn href=#boolean-context title="boolean context">boolean context</a>,
as their values are almost always greater than zero.
Others, like <a class=property data-link-type=propdesc href=#descdef-color title=color>color</a>, have meaningful zero values:
<span class=css data-link-type=maybe title=(color)>(color)</span> is identical to <span class=css data-link-type=maybe title="(color > 0)">(color > 0)</span>,
indicating that the device is capable of displaying color at all.
</div>
<div class=example>
Only some of the <a data-link-type=dfn href=#media-feature title="media features">media features</a> that accept keywords are meaningful in a <a data-link-type=dfn href=#boolean-context title="boolean context">boolean context</a>.
<p> For example, <span class=css data-link-type=maybe title=(pointer)>(pointer)</span> is useful,
as <a class=property data-link-type=propdesc href=#descdef-pointer title=pointer>pointer</a> has a <a class=css data-link-for=pointer data-link-type=maybe href=#valuedef-none3 title=none>none</a> value to indicate there’s no pointing device at all on the device.
On the other hand, <span class=css data-link-type=maybe title=(scan)>(scan)</span> is just always true or always false
(depending on whether it applies at all to the device),
as there’s no value that means “false”.
</div>
<h4 class="heading settled heading" data-level=2.4.3 id=mq-range-context><span class=secno>2.4.3 </span><span class=content>
Evaluating Media Features in a Range Context</span><a class=self-link href=#mq-range-context></a></h4>
<p> <a data-link-type=dfn href=#media-feature title="media features">Media features</a> with a “range” type can be alternately written in a <dfn data-dfn-type=dfn data-export="" id=range-context>range context<a class=self-link href=#range-context></a></dfn>
that takes advantage of the fact that their values are ordered,
using ordinary mathematical comparison operators:
<div class=railroad><svg class=railroad-diagram height=302 viewBox="0 0 665 302" width=665>
<g transform="translate(.5 .5)">
<path d="M 20 141 v 20 m 10 -20 v 20 m -10 -10 h 20.5">
</path><path d="M40 151h10">
</path><g>
<path d="M50 151h0.0">
</path><path d="M78.0 151h0.0">
</path><rect height=22 rx=10 ry=10 width=28 x=50.0 y=140>
</rect><text x=64.0 y=155>
(</text></g><path d="M78 151h10">
</path><g>
<path d="M88 151h0.0">
</path><path d="M576.0 151h0.0">
</path><path d="M88.0 151h20">
</path><g>
<path d="M108.0 151h2.0">
</path><path d="M554.0 151h2.0">
</path><path d="M110.0 151h10">
</path><g>
<path d="M120.0 151h0.0">
</path><path d="M284.0 151h0.0">
</path><rect height=22 width=164 x=120.0 y=140>
</rect><text x=202.0 y=155>
feature name/value</text></g><path d="M284.0 151h10">
</path><g>
<path d="M294.0 151h0.0">
</path><path d="M370.0 151h0.0">
</path><path d="M294.0 151a10 10 0 0 0 10 -10v-10a10 10 0 0 1 10 -10">
</path><g>
<path d="M314.0 121h4.0">
</path><path d="M346.0 121h4.0">
</path><rect height=22 rx=10 ry=10 width=28 x=318.0 y=110>
</rect><text x=332.0 y=125>
></text></g><path d="M350.0 121a10 10 0 0 1 10 10v10a10 10 0 0 0 10 10">
</path><path d="M294.0 151a10 10 0 0 0 10 -10v-40a10 10 0 0 1 10 -10">
</path><g>
<path d="M314.0 91h0.0">
</path><path d="M350.0 91h0.0">
</path><rect height=22 rx=10 ry=10 width=36 x=314.0 y=80>
</rect><text x=332.0 y=95>
<=</text></g><path d="M350.0 91a10 10 0 0 1 10 10v40a10 10 0 0 0 10 10">
</path><path d="M294.0 151a10 10 0 0 0 10 -10v-70a10 10 0 0 1 10 -10">
</path><g>
<path d="M314.0 61h4.0">
</path><path d="M346.0 61h4.0">
</path><rect height=22 rx=10 ry=10 width=28 x=318.0 y=50>
</rect><text x=332.0 y=65>
<</text></g><path d="M350.0 61a10 10 0 0 1 10 10v70a10 10 0 0 0 10 10">
</path><path d="M294.0 151a10 10 0 0 0 10 -10v-100a10 10 0 0 1 10 -10">
</path><g>
<path d="M314.0 31h4.0">
</path><path d="M346.0 31h4.0">
</path><rect height=22 rx=10 ry=10 width=28 x=318.0 y=20>
</rect><text x=332.0 y=35>
=</text></g><path d="M350.0 31a10 10 0 0 1 10 10v100a10 10 0 0 0 10 10">
</path><path d="M294.0 151h20">
</path><g>
<path d="M314.0 151h0.0">
</path><path d="M350.0 151h0.0">
</path><rect height=22 rx=10 ry=10 width=36 x=314.0 y=140>
</rect><text x=332.0 y=155>
>=</text></g><path d="M350.0 151h20">
</path></g><path d="M370.0 151h10">
</path><g>
<path d="M380.0 151h0.0">
</path><path d="M544.0 151h0.0">
</path><rect height=22 width=164 x=380.0 y=140>
</rect><text x=462.0 y=155>
feature value/name</text></g><path d="M544.0 151h10">
</path></g><path d="M556.0 151h20">
</path><path d="M88.0 151a10 10 0 0 1 10 10v10a10 10 0 0 0 10 10">
</path><g>
<path d="M108.0 181h0.0">
</path><path d="M556.0 181h0.0">
</path><path d="M108.0 181h10">
</path><g>
<path d="M118.0 181h0.0">
</path><path d="M178.0 181h0.0">
</path><rect height=22 width=60 x=118.0 y=170>
</rect><text x=148.0 y=185>
value</text></g><path d="M178.0 181h10">
</path><g>
<path d="M188.0 181h0.0">
</path><path d="M264.0 181h0.0">
</path><path d="M188.0 181h20">
</path><g>
<path d="M208.0 181h4.0">
</path><path d="M240.0 181h4.0">
</path><rect height=22 rx=10 ry=10 width=28 x=212.0 y=170>
</rect><text x=226.0 y=185>
<</text></g><path d="M244.0 181h20">
</path><path d="M188.0 181a10 10 0 0 1 10 10v10a10 10 0 0 0 10 10">
</path><g>
<path d="M208.0 211h0.0">
</path><path d="M244.0 211h0.0">
</path><rect height=22 rx=10 ry=10 width=36 x=208.0 y=200>
</rect><text x=226.0 y=215>
<=</text></g><path d="M244.0 211a10 10 0 0 0 10 -10v-10a10 10 0 0 1 10 -10">
</path></g><path d="M264.0 181h10">
</path><g>
<path d="M274.0 181h0.0">
</path><path d="M390.0 181h0.0">
</path><rect height=22 width=116 x=274.0 y=170>
</rect><text x=332.0 y=185>
feature name</text></g><path d="M390.0 181h10">
</path><g>
<path d="M400.0 181h0.0">
</path><path d="M476.0 181h0.0">
</path><path d="M400.0 181h20">
</path><g>
<path d="M420.0 181h4.0">
</path><path d="M452.0 181h4.0">
</path><rect height=22 rx=10 ry=10 width=28 x=424.0 y=170>
</rect><text x=438.0 y=185>
<</text></g><path d="M456.0 181h20">
</path><path d="M400.0 181a10 10 0 0 1 10 10v10a10 10 0 0 0 10 10">
</path><g>
<path d="M420.0 211h0.0">
</path><path d="M456.0 211h0.0">
</path><rect height=22 rx=10 ry=10 width=36 x=420.0 y=200>
</rect><text x=438.0 y=215>
<=</text></g><path d="M456.0 211a10 10 0 0 0 10 -10v-10a10 10 0 0 1 10 -10">
</path></g><path d="M476.0 181h10">
</path><g>
<path d="M486.0 181h0.0">
</path><path d="M546.0 181h0.0">
</path><rect height=22 width=60 x=486.0 y=170>
</rect><text x=516.0 y=185>
value</text></g><path d="M546.0 181h10">
</path></g><path d="M556.0 181a10 10 0 0 0 10 -10v-10a10 10 0 0 1 10 -10">
</path><path d="M88.0 151a10 10 0 0 1 10 10v70a10 10 0 0 0 10 10">
</path><g>
<path d="M108.0 241h0.0">
</path><path d="M556.0 241h0.0">
</path><path d="M108.0 241h10">
</path><g>
<path d="M118.0 241h0.0">
</path><path d="M178.0 241h0.0">
</path><rect height=22 width=60 x=118.0 y=230>
</rect><text x=148.0 y=245>
value</text></g><path d="M178.0 241h10">
</path><g>
<path d="M188.0 241h0.0">
</path><path d="M264.0 241h0.0">
</path><path d="M188.0 241h20">
</path><g>