-
Notifications
You must be signed in to change notification settings - Fork 708
/
Copy pathOverview.html
1759 lines (1422 loc) · 72.8 KB
/
Overview.html
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 PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang=en>
<head
profile="http://dublincore.org/documents/2008/08/04/dc-html/ http://www.w3.org/2006/03/hcard">
<meta content="text/html; charset=utf-8" http-equiv=Content-Type>
<title>CSS Conditional Rules Module Level 3</title>
<link href="http://purl.org/dc/terms/" rel=schema.dc>
<link href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright"
rel=dc.rights>
<meta content="CSS Conditional Rules Module Level 3" name=dc.title>
<meta content=text name=dc.type>
<meta content=2013-04-04 name=dc.date>
<meta content="L. David Baron" name=dc.creator>
<meta content=W3C name=dc.publisher>
<meta content="http://dev.w3.org/csswg/css3-conditional/"
name=dc.identifier>
<link href="../default.css" rel=stylesheet type="text/css">
<link href="../csslogo.ico" rel="shortcut icon" type="image/x-icon">
<link href="http://www.w3.org/StyleSheets/TR/W3C-ED.css" rel=stylesheet
type="text/css"><!--
<script src="http://test.csswg.org/harness/annotate.js#CSS3-CONDITIONAL_DEV"
type="text/javascript" defer></script
-->
<body class=h-entry>
<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 class=p-name>CSS Conditional Rules Module Level 3</h1>
<h2 class="no-num no-toc" id=longstatus-date>Editor's Draft <span
class=dt-updated><span class=value-title title=20130404>4 April
2013</span></span></h2>
<dl>
<dt>This version:
<dd><a class=u-url href="http://dev.w3.org/csswg/css3-conditional/">
http://www.w3.org/TR/2013/ED-css3-conditional-20130404/</a>
<dt>Latest version:
<dd><a
href="http://www.w3.org/TR/css3-conditional/">http://www.w3.org/TR/css3-conditional/</a>
<dt>Editor's draft:
<dd><a
href="http://dev.w3.org/csswg/css3-conditional/">http://dev.w3.org/csswg/css3-conditional/</a>
(<a
href="https://dvcs.w3.org/hg/csswg/log/tip/css-conditional/Overview.src.html">change
log</a>, <a
href="https://dvcs.w3.org/hg/csswg/log/tip/css3-conditional/Overview.src.html">older
change log</a>)
<dt>Previous version:
<dd><a href="http://www.w3.org/TR/2012/WD-css3-conditional-20121213/"
rel=previous>http://www.w3.org/TR/2012/WD-css3-conditional-20121213/</a>
<dt>Editors:
<dd class="p-author h-card vcard"><a class="p-name fn u-url url"
href="http://dbaron.org/" rel=author>L. David Baron</a>, <a
class="p-org org h-org" href="http://www.mozilla.org/">Mozilla</a>
<dt>Issues list:
<dd>Maintained in document (only editor's draft is current)
<dt>Feedback:
<dd><a
href="mailto:www-style@w3.org?subject=%5Bcss3-conditional%5D%20feedback">www-style@w3.org</a>
with subject line “<kbd>[css3-conditional] <var>… message topic
…</var></kbd>” (<a
href="http://lists.w3.org/Archives/Public/www-style/"
rel=discussion>archives</a>)
<dt>Test suite:
<dd><a
href="https://test.csswg.org/shepherd/search/spec/css3-conditional/">submitted
tests</a>, <a
href="https://test.csswg.org/harness/suite/CSS3-CONDITIONAL_DEV/">nightly
test suite</a>
</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>CSS is a language for describing the rendering of structured documents
(such as HTML and XML) on screen, on paper, in speech, etc. <span
class=p-summary> This module contains the features of CSS for conditional
processing of parts of style sheets, conditioned on capabilities of the
processor or the document the style sheet is being applied to. It includes
and extends the functionality of CSS level 2 <a href="#CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>, which builds on CSS level 1
<a href="#CSS1" rel=biblioentry>[CSS1]<!--{{CSS1}}--></a>. The main
extensions compared to level 2 are allowing nesting of certain at-rules
inside ‘<code class=css>@media</code>’, and the addition of the
‘<code class=css>@supports</code>’ rule for conditional processing.
</span>
<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=%5Bcss3-conditional%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
“css3-conditional” in the subject, preferably like this:
“[<!---->css3-conditional<!---->] <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-->
<p>See the section <a href="#cr-exit-criteria">“CR Exit Criteria”</a>
for details on advancing this specification to W3C Recommendation. The
specification will remain Candidate Recommendation at least until 2
October 2013. A <a
href="http://test.csswg.org/suites/css3-conditional/nightly-unstable/report/">test
suite and implementation report</a> are under development.
<p>See the section <a href="#changes">“Changes”</a> for changes since
the last Working Draft.
<p>The following features are at risk:
<ul>
<li>The inclusion of ‘<code class=css>@font-face</code>’ rules and
‘<code class=css>@keyframes</code>’ rules as allowed within all of
the @-rules in this specification is at risk, though only because of the
relative rates of advancement of specifications. If this specification is
able to advance faster than one or both of the specifications defining
those rules, then the inclusion of those rules will move from this
specification to the specification defining those rules.
<li>The addition of support for @-rules inside of conditional grouping
rules is at risk; if interoperable implementations are not found, it may
be removed to advance the other features in this specification to
Proposed Recommendation.
<li>The ‘<code class=css>@supports</code>’ rule is at risk; if
interoperable implementations are not found, it may be removed to advance
the other features in this specification to Proposed Recommendation.
</ul>
<!--
Things to go in level 4:
* Create some way to put these new conditional things on an @import.
* The @document rule (commented out, down below).
-->
<h2 class="no-num no-toc" id=contents>Table of contents</h2>
<!--begin-toc-->
<ul class=toc>
<li><a href="#introduction"><span class=secno>1. </span>Introduction</a>
<ul class=toc>
<li><a href="#context"><span class=secno>1.1. </span>Background</a>
<li><a href="#placement"><span class=secno>1.2. </span>Module
Interactions</a>
<li><a href="#conventions"><span class=secno>1.3. </span>Document
Conventions</a>
</ul>
<li><a href="#processing"><span class=secno>2. </span>Processing of
conditional group rules</a>
<li><a href="#contents-of"><span class=secno>3. </span>Contents of
conditional group rules</a>
<li><a href="#use"><span class=secno>4. </span>Placement of conditional
group rules</a>
<li><a href="#at-media"><span class=secno>5. </span>Media-specific style
sheets: the ‘<code class=css>@media</code>’ rule</a>
<li><a href="#at-supports"><span class=secno>6. </span>Feature queries:
the ‘<code class=css>@supports</code>’ rule</a>
<ul class=toc>
<li><a href="#support-definition"><span class=secno>6.1.
</span>Definition of support</a>
</ul>
<li><a href="#apis"><span class=secno>7. </span>APIs</a>
<ul class=toc>
<li><a href="#extentions-to-cssrule-interface"><span class=secno>7.1.
</span> Extensions to the <code>CSSRule</code> interface</a>
<li><a href="#the-cssgroupingrule-interface"><span class=secno>7.2.
</span> The <code>CSSGroupingRule</code> interface</a>
<li><a href="#the-cssconditionrule-interface"><span class=secno>7.3.
</span> The <code>CSSConditionRule</code> interface</a>
<li><a href="#the-cssmediarule-interface"><span class=secno>7.4. </span>
The <code>CSSMediaRule</code> interface</a>
<li><a href="#the-csssupportsrule-interface"><span class=secno>7.5.
</span> The <code>CSSSupportsRule</code> interface</a>
<li><a href="#the-css-interface"><span class=secno>7.6. </span> The
<code>CSS</code> interface, and the <code title="">supports()</code>
function</a>
</ul>
<li class=no-num><a href="#grammar">Grammar</a>
<li><a href="#conformance"><span class=secno>8. </span>Conformance</a>
<ul class=toc>
<li><a href="#base-modules"><span class=secno>8.1. </span>Base
Modules</a>
<li><a href="#conformance-classes"><span class=secno>8.2.
</span>Conformance Classes</a>
<li><a href="#partial"><span class=secno>8.3. </span> Partial
Implementations</a>
<li><a href="#experimental"><span class=secno>8.4. </span>Experimental
Implementations</a>
<li><a href="#cr-exit-criteria"><span class=secno>8.5. </span>CR Exit
Criteria</a>
</ul>
<li><a href="#changes"><span class=secno>9. </span> Changes</a>
<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=introduction><span class=secno>1. </span>Introduction</h2>
<h3 id=context><span class=secno>1.1. </span>Background</h3>
<p><em>This section is not normative.</em>
<p><a href="#CSS21" rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a> defines
one type of conditional group rule, the ‘<code
class=css>@media</code>’ rule, and allows only rulesets (not other
@-rules) inside of it. The ‘<code class=css>@media</code>’ rule
provides the ability to have media-specific style sheets, which is also
provided by style sheet linking features such as ‘<code
class=css>@import</code>’ and <code class=html><link></code>. The
restrictions on the contents of ‘<code class=css>@media</code>’ rules
made them less useful; they have forced authors using CSS features
involving @-rules in media-specific style sheets to use separate style
sheets for each medium.
<p>This specification extends the rules for the contents of conditional
group rules to allow other @-rules, which enables authors to combine CSS
features involving @-rules with media specific style sheets within a
single style sheet.
<p>This specification also defines an additional type of conditional group
rule, ‘<code class=css>@supports</code>’, to address author and user
requirements.
<p>The ‘<code class=css>@supports</code>’ rule allows CSS to be
conditioned on implementation support for CSS properties and values. This
rule makes it much easier for authors to use new CSS features and provide
good fallback for implementations that do not support those features. This
is particularly important for CSS features that provide new layout
mechanisms, and for other cases where a set of related styles needs to be
conditioned on property support.
<h3 id=placement><span class=secno>1.2. </span>Module Interactions</h3>
<p>This module replaces and extends the ‘<code class=css>@media</code>’
rule feature defined in <a href="#CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a> section <var>7.2.1</var> and
incorporates the modifications previously made non-normatively by <a
href="#MEDIAQ" rel=biblioentry>[MEDIAQ]<!--{{!MEDIAQ}}--></a> section
<var>1</var>.
<p>Its current definition depends on @-rules defined in <a
href="#CSS3-FONTS" rel=biblioentry>[CSS3-FONTS]<!--{{!CSS3-FONTS}}--></a>
and <a href="#CSS3-ANIMATIONS"
rel=biblioentry>[CSS3-ANIMATIONS]<!--{{!CSS3-ANIMATIONS}}--></a>, but that
dependency is only on the assumption that those modules will advance ahead
of this one. If this module advances faster, then the dependency will be
reversed.
<h3 id=conventions><span class=secno>1.3. </span>Document Conventions</h3>
<p>Conformance requirements are expressed with a combination of descriptive
assertions and RFC 2119 terminology. The key words “MUST”, “MUST
NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”,
“SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in the
normative parts of this document are to be interpreted as described in RFC
2119. However, for readability, these words do not appear in all uppercase
letters in this specification.
<p>All of the text of this specification is normative except sections
explicitly marked as non-normative, examples, and notes. <a
href="#RFC2119" rel=biblioentry>[RFC2119]<!--{{!RFC2119}}--></a>
<p>Examples in this specification are introduced with the words “for
example” or are set apart from the normative text with <code
class=html>class="example"</code>, like this:
<div class=example>
<p>This is an example of an informative example.
</div>
<p>Informative notes begin with the word “Note” and are set apart from
the normative text with <code class=html>class="note"</code>, like this:
<p class=note>Note, this is an informative note.
<h2 id=processing><span class=secno>2. </span>Processing of conditional
group rules</h2>
<p>This specification defines some CSS @-rules, called <dfn
id=conditional-group-rules>conditional group rules</dfn>, that associate a
condition with a group of other CSS rules. These different rules allow
testing different types of conditions, but share common behavior for how
their contents are used when the condition is true and when the condition
is false.
<div class=example>
<p>For example, this rule:
<pre>@media print {
/* hide navigation controls when printing */
#navigation { display: none }
}</pre>
<p>causes a particular CSS rule (making elements with ID "navigation" be
display:none) apply only when the style sheet is used for a print medium.
</div>
<p>Each conditional group rule has a condition, which at any time evaluates
to true or false. When the condition is true, CSS processors
<strong>must</strong> apply the rules inside the group rule as though they
were at the group rule's location; when the condition is false, CSS
processors <strong>must not</strong> apply any of rules inside the group
rule. The current state of the condition does not affect the CSS object
model, in which the contents of the group rule always remain within the
group rule.
<p>This means that when multiple conditional group rules are nested, a rule
inside of both of them applies only when all of the rules' conditions are
true.
<div class=example>For example, with this set of nested rules:
<pre>@media print { // rule (1)
/* hide navigation controls when printing */
#navigation { display: none }
@media (max-width: 12cm) { // rule (2)
/* keep notes in flow when printing to narrow pages */
.note { float: none }
}
}</pre>
the condition of the rule marked (1) is true for print media, and the
condition of the rule marked (2) is true when the width of the display
area (which for print media is the page box) is less than or equal to
12cm. Thus the rule ‘<code class=css>#navigation { display: none
}</code>’ applies whenever this style sheet is applied to print media,
and the rule ‘<code class=css>.note { float: none }</code>’ is applied
only when the style sheet is applied to print media <em>and</em> the width
of the page box is less than or equal to 12 centimeters.</div>
<p>When the condition for a conditional group rule changes, CSS processors
<strong>must</strong> reflect that the rules now apply or no longer apply,
except for properties whose definitions define effects of computed values
that persist past the lifetime of that value (such as for some properties
in <a href="#CSS3-TRANSITIONS"
rel=biblioentry>[CSS3-TRANSITIONS]<!--{{CSS3-TRANSITIONS}}--></a> and <a
href="#CSS3-ANIMATIONS"
rel=biblioentry>[CSS3-ANIMATIONS]<!--{{!CSS3-ANIMATIONS}}--></a>).
<h2 id=contents-of><span class=secno>3. </span>Contents of conditional
group rules</h2>
<p>The syntax of each conditional group rule consists of some syntax
specific to the type of rule followed by a <dfn id=group-rule-body>group
rule body</dfn>, which is a block (pair of braces) containing a sequence
of rules.
<p>A group rule body is allowed to contain rulesets and any @-rules that
are allowed at the top level of a style sheet before and after a ruleset.
This means that @-rules that must occur at the beginning of the style
sheet (such as ‘<code class=css>@charset</code>’, ‘<code
class=css>@import</code>’, and ‘<code class=css>@namespace</code>’
rules) are not allowed inside of conditional group rules. Conditional
group rules can be nested.
<p>In terms of the grammar, this specification defines the following
productions for use in the grammar of conditional group rules:
<pre><dfn id="nested_statement">nested_statement</dfn>
: ruleset | <a
href="#media"><i>media</i></a> | page | font_face_rule | keyframes_rule |
<a
href="#supports_rule"><i>supports_rule</i></a>
;
<dfn
id="group_rule_body">group_rule_body</dfn>
: '{' S* <a
href="#nested_statement"><i>nested_statement</i></a>* '}' S*
;</pre>
<p> in which all the productions are defined in that grammar with the
exception of <code>font_face_rule</code> defined in <a href="#CSS3-FONTS"
rel=biblioentry>[CSS3-FONTS]<!--{{!CSS3-FONTS}}--></a>,
<code>keyframes_rule</code> defined in <a href="#CSS3-ANIMATIONS"
rel=biblioentry>[CSS3-ANIMATIONS]<!--{{!CSS3-ANIMATIONS}}--></a>, and <a
href="#media"><code>media</code></a> and <a
href="#supports_rule"><code>supports_rule</code></a> defined in this
specification.
<p>In general, future CSS specifications that add new @-rules that are not
forbidden to occur after some other types of rules should modify this <a
href="#nested_statement"><code>nested_statement</code></a> production to
keep the grammar accurate.
<p>Style sheets <strong>must not</strong> use rules other than the allowed
ones inside conditional group rules.
<p>CSS processors <strong>must</strong> ignore rules that are not allowed
within a group rule, and <strong>must</strong> handle invalid rules inside
of group rules as described in <a
href="http://www.w3.org/TR/CSS21/syndata.html#parsing-errors">section 4.2
(Rules for handling parsing errors)</a>, <a
href="http://www.w3.org/TR/CSS21/syndata.html#at-rules">section 4.1.5
(At-rules)</a>, and <a
href="http://www.w3.org/TR/CSS21/syndata.html#rule-sets">section 4.1.7
(Rule sets, declaration blocks, and selectors)</a> of <a href="#CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>.
<h2 id=use><span class=secno>4. </span>Placement of conditional group rules</h2>
<p>Conditional group rules are allowed at the top-level of a style sheet,
and inside other conditional group rules. CSS processors
<strong>must</strong> process such rules as <a
href="#processing">described above</a>.
<p>Any rules that are not allowed after a ruleset (e.g., ‘<code
class=css>@charset</code>’, ‘<code class=css>@import</code>’, or
‘<code class=css>@namespace</code>’ rules) are also not allowed after
a conditional group rule. Therefore, style sheets <strong>must
not</strong> place such rules after a conditional group rules, and CSS
processors <strong>must</strong> ignore such rules.
<h2 id=at-media><span class=secno>5. </span>Media-specific style sheets:
the ‘<code class=css>@media</code>’ rule</h2>
<p>The <dfn id=atmedia-rule>‘<code class=css>@media</code>’ rule</dfn>
is a conditional group rule whose condition is a media query. It consists
of the at-keyword ‘<code class=css>@media</code>’ followed by a
(possibly empty) media query list (as defined in <a href="#MEDIAQ"
rel=biblioentry>[MEDIAQ]<!--{{!MEDIAQ}}--></a>), followed by a group rule
body. The condition of the rule is the result of the media query.
<div class=example>
<p>This ‘<code class=css>@media</code>’ rule:
<pre>@media screen and (min-width: 35em),
print and (min-width: 40em) {
#section_navigation { float: left; width: 10em; }
}</pre>
<p>has the condition ‘<code class=css>screen and (min-width: 35em),
print and (min-width: 40em)</code>’, which is true for screen displays
whose viewport is at least 35 times the initial font size and for print
displays whose viewport is at least 40 times the initial font size. When
either of these is true, the condition of the rule is true, and the rule
‘<code class=css>#section_navigation { float: left; width: 10em;
}</code>’ is applied.
</div>
<p>In terms of the grammar, this specification extends the <a
href="#media"><code>media</code></a> production in the <a
href="http://www.w3.org/TR/CSS21/grammar.html">Grammar of CSS 2.1</a> (<a
href="#CSS21" rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>, Appendix G)
into:
<pre><dfn id=media>media</dfn>
: MEDIA_SYM S* media_query_list <a
href="#group_rule_body"><i>group_rule_body</i></a>
;</pre>
<p>where the <a href="#group_rule_body"><code>group_rule_body</code></a>
production is defined in this specification, the
<code>media_query_list</code> production is defined in <a href="#MEDIAQ"
rel=biblioentry>[MEDIAQ]<!--{{!MEDIAQ}}--></a>, and the others are defined
in the <a href="http://www.w3.org/TR/CSS21/grammar.html">Grammar of CSS
2.1</a> (<a href="#CSS21" rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>,
Appendix G).
<h2 id=at-supports><span class=secno>6. </span>Feature queries: the
‘<code class=css>@supports</code>’ rule</h2>
<p>The <dfn id=atsupports-rule>‘<code class=css>@supports</code>’
rule</dfn> is a conditional group rule whose condition tests whether the
user agent supports CSS property:value pairs. Authors can use it to write
style sheets that use new features when available but degrade gracefully
when those features are not supported. CSS has existing mechanisms for
graceful degradation, such as ignoring unsupported properties or values,
but these are not always sufficient when large groups of styles need to be
tied to the support for certain features, as is the case for use of new
layout system features.
<p>The syntax of the condition in the ‘<code
class=css>@supports</code>’ rule is slightly more complicated than for
the other conditional group rules (though has some similarities to media
queries) since:
<ul>
<li>negation is needed so that the new-feature styles and the fallback
styles can be separated (within the forward-compatible grammar's rules
for the syntax of @-rules), and not required to override each other
<li>conjunction (and) is needed so that multiple required features can be
tested
<li>disjunction (or) is needed when there are multiple alternative
features for a set of styles, particularly when some of those
alternatives are vendor-prefixed properties or values
</ul>
<p>Therefore, the syntax of the ‘<code class=css>@supports</code>’ rule
allows testing for property:value pairs, and arbitrary conjunctions (and),
disjunctions (or), and negations (not) of them.
<p>This extends the lexical scanner in the <a
href="http://www.w3.org/TR/CSS21/grammar.html">Grammar of CSS 2.1</a> (<a
href="#CSS21" rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>, Appendix G) by
adding:
<pre>
@{S}{U}{P}{P}{O}{R}{T}{S} {return <dfn
id="supports_sym">SUPPORTS_SYM</dfn>;}
{O}{R} {return <dfn
id=or>OR</dfn>;}
</pre>
<p>This then extends the grammar in the <a
href="http://www.w3.org/TR/CSS21/grammar.html">Grammar of CSS 2.1</a>,
using the lexical scanner there, with the additions of <code><a
href="http://www.w3.org/TR/css3-mediaqueries/#syntax">AND</a></code> and
<code><a
href="http://www.w3.org/TR/css3-mediaqueries/#syntax">NOT</a></code>
tokens defined in the Media Queries specification <a href="#MEDIAQ"
rel=biblioentry>[MEDIAQ]<!--{{!MEDIAQ}}--></a> and the <a
href="#or"><code>OR</code></a> and <a
href="#supports_sym"><code>SUPPORTS_SYM</code></a> tokens defined above,
and with <code><a
href="http://www.w3.org/TR/CSS21/syndata.html#tokenization">declaration</a></code>,
<code><a
href="http://www.w3.org/TR/CSS21/syndata.html#tokenization">any</a></code>,
and <code><a
href="http://www.w3.org/TR/CSS21/syndata.html#tokenization">unused</a></code>
productions and the <code><a
href="http://www.w3.org/TR/CSS21/syndata.html#tokenization">FUNCTION</a></code>
token taken from the core syntax of CSS defined in <a
href="http://www.w3.org/TR/CSS21/syndata.html#tokenization">section 4.1.1
(Tokenization)</a> of <a href="#CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>, by adding:
<pre><dfn id="supports_rule">supports_rule</dfn>
: <a
href="#supports_sym"><i>SUPPORTS_SYM</i></a> <a
href="http://www.w3.org/TR/CSS21/grammar.html#scanner"><i>S</i></a>* <a
href="#supports_condition"><i>supports_condition</i></a> <a
href="http://www.w3.org/TR/CSS21/grammar.html#scanner"><i>S</i></a>* <a
href="#group_rule_body"><i>group_rule_body</i></a>
;
<dfn
id="supports_condition">supports_condition</dfn>
: <a
href="#supports_negation"><i>supports_negation</i></a> | <a
href="#supports_conjunction"><i>supports_conjunction</i></a> | <a
href="#supports_disjunction"><i>supports_disjunction</i></a> |
<a
href="#supports_condition_in_parens"><i>supports_condition_in_parens</i></a>
;
<dfn
id="supports_condition_in_parens">supports_condition_in_parens</dfn>
: ( '(' <a
href="http://www.w3.org/TR/CSS21/grammar.html#scanner"><i>S</i></a>* <a
href="#supports_condition"><i>supports_condition</i></a> <a
href="http://www.w3.org/TR/CSS21/grammar.html#scanner"><i>S</i></a>* ')' ) | <a
href="#supports_declaration_condition"><i>supports_declaration_condition</i></a> |
<a
href="#general_enclosed"><i>general_enclosed</i></a>
;
<dfn
id="supports_negation">supports_negation</dfn>
: <a
href="http://www.w3.org/TR/css3-mediaqueries/#syntax"><i>NOT</i></a> <a
href="http://www.w3.org/TR/CSS21/grammar.html#scanner"><i>S</i></a>+ <a
href="#supports_condition_in_parens"><i>supports_condition_in_parens</i></a>
;
<dfn
id="supports_conjunction">supports_conjunction</dfn>
: <a
href="#supports_condition_in_parens"><i>supports_condition_in_parens</i></a> ( <a
href="http://www.w3.org/TR/CSS21/grammar.html#scanner"><i>S</i></a>+ <a
href="http://www.w3.org/TR/css3-mediaqueries/#syntax"><i>AND</i></a> <a
href="http://www.w3.org/TR/CSS21/grammar.html#scanner"><i>S</i></a>+ <a
href="#supports_condition_in_parens"><i>supports_condition_in_parens</i></a> )+
;
<dfn
id="supports_disjunction">supports_disjunction</dfn>
: <a
href="#supports_condition_in_parens"><i>supports_condition_in_parens</i></a> ( <a
href="http://www.w3.org/TR/CSS21/grammar.html#scanner"><i>S</i></a>+ <a
href="#or"><i>OR</i></a> <a
href="http://www.w3.org/TR/CSS21/grammar.html#scanner"><i>S</i></a>+ <a
href="#supports_condition_in_parens"><i>supports_condition_in_parens</i></a> )+
;
<dfn
id="supports_declaration_condition">supports_declaration_condition</dfn>
: '(' <a
href="http://www.w3.org/TR/CSS21/grammar.html#scanner"><i>S</i></a>* <a
href="http://www.w3.org/TR/CSS21/syndata.html#tokenization"><i>declaration</i></a> ')'
;
<dfn
id="general_enclosed">general_enclosed</dfn>
: ( <a
href="http://www.w3.org/TR/CSS21/syndata.html#tokenization"><i>FUNCTION</i></a> | '(' ) ( <a
href="http://www.w3.org/TR/CSS21/syndata.html#tokenization"><i>any</i></a> | <a
href="http://www.w3.org/TR/CSS21/syndata.html#tokenization"><i>unused</i></a> )* ')'
;
</pre>
<p> Implementations <strong>must</strong> parse ‘<code
class=css>@supports</code>’ rules based on the above grammar, and when
interpreting the above grammar, <strong>must</strong> match the production
before an <code>|</code> operator in preference to the one after it.
<p> The above grammar is purposely very loose for forwards-compatibility
reasons, since the <a
href="#general_enclosed"><code>general_enclosed</code></a> production
allows for substantial future extensibility. Any ‘<code
class=css>@supports</code>’ rule that does not parse according to the
grammar above (that is, a rule that does not match this loose grammar
which includes the <a
href="#general_enclosed"><code>general_enclosed</code></a> production) is
invalid. Style sheets <strong>must not</strong> use such a rule and
processors <strong>must</strong> ignore such a rule (including all of its
contents).
<p>Each of these grammar terms is associated with a boolean result, as
follows:
<dl>
<dt>supports_condition
<dd> The result is the result of the single child term.
<dt>supports_condition_in_parens
<dd> The result is the result of the single <a
href="#supports_condition"><code>supports_condition</code></a> or <a
href="#supports_declaration_condition"><code>supports_declaration_condition</code></a>
child term.
<dt>supports_negation
<dd> The result is the <em>negation</em> of the result of the <a
href="#supports_condition_in_parens"><code>supports_condition_in_parens</code></a>
child term.
<dt>supports_conjunction
<dd> The result is true if the result of <em>all</em> of the <a
href="#supports_condition_in_parens"><code>supports_condition_in_parens</code></a>
child terms is true; otherwise it is false.
<dt>supports_disjunction
<dd> The result is true if the result of <em>any</em> of the <a
href="#supports_condition_in_parens"><code>supports_condition_in_parens</code></a>
child terms is true; otherwise it is false.
<dt>supports_declaration_condition
<dd> The result is whether the CSS processor <a
href="#support-definition">supports</a> the declaration within the
parentheses.
<dt>general_enclosed
<dd> The result is always false. Additionally, style sheets <strong>must
not</strong> write ‘<code class=css>@supports</code>’ rules that
match this grammar production. (In other words, this production exists
only for future extensibility, and is not part of the description of a
valid style sheet in this level of the specification.) <span
class=note>Note that future levels may define functions or other
parenthesized expressions that can evaluate to true.</span>
</dl>
<p>The condition of the ‘<code class=css>@supports</code>’ rule is the
result of the <a
href="#supports_condition"><code>supports_condition</code></a> term that
is a child of the <a href="#supports_rule"><code>supports_rule</code></a>
term.
<div class=example>
<p>For example, the following rule
<pre>@supports ( display: flexbox ) {
body, #navigation, #content { display: flexbox; }
#navigation { background: blue; color: white; }
#article { background: white; color: black; }
}</pre>
<p>applies the rules inside the ‘<code class=css>@supports</code>’
rule only when ‘<code class=css>display: flexbox</code>’ is
supported.
</div>
<div class=example>
<p>The following example shows an additional ‘<code
class=css>@supports</code>’ rule that can be used to provide an
alternative for when ‘<code class=css>display: flexbox</code>’ is not
supported:
<pre>@supports not ( display: flexbox ) {
body { width: 100%; height: 100%; background: white; color: black; }
#navigation { width: 25%; }
#article { width: 75%; }
}</pre>
<p>Note that the ‘<code class=property>width</code>’ declarations may
be harmful to the flexbox-based layout, so it is important that they be
present only in the non-flexbox styles.
</div>
<div class=example>
<p>The following example checks for support for the ‘<code
class=property>box-shadow</code>’ property, including checking for
support for vendor-prefixed versions of it. When the support is present,
it specifies both ‘<code class=property>box-shadow</code>’ (with the
prefixed versions) and ‘<code class=property>color</code>’ in a way
what would cause the text to become invisible were ‘<code
class=property>box-shadow</code>’ not supported.
<pre>@supports ( box-shadow: 2px 2px 2px black ) or
( -moz-box-shadow: 2px 2px 2px black ) or
( -webkit-box-shadow: 2px 2px 2px black ) or
( -o-box-shadow: 2px 2px 2px black ) {
.outline {
color: white;
-moz-box-shadow: 2px 2px 2px black;
-webkit-box-shadow: 2px 2px 2px black;
-o-box-shadow: 2px 2px 2px black;
box-shadow: 2px 2px 2px black; /* unprefixed last */
}
}</pre>
</div>
<p>To avoid confusion between ‘<code class=css>and</code>’ and ‘<a
href="#or"><code class=css>or</code></a>’, the syntax requires that both
‘<code class=css>and</code>’ and ‘<a href="#or"><code
class=css>or</code></a>’ be specified explicitly (rather than, say,
using commas or spaces for one of them). Likewise, to avoid confusion
caused by precedence rules, the syntax does not allow ‘<code
class=css>and</code>’, ‘<a href="#or"><code
class=css>or</code></a>’, and ‘<code class=css>not</code>’ operators
to be mixed without a layer of parentheses.
<div class=example>
<p>For example, the following rule is not valid:
<pre class=illegal>@supports (transition-property: color) or
(animation-name: foo) and
(transform: rotate(10deg)) {
// ...
}</pre>
<p>Instead, authors must write one of the following:
<pre>@supports ((transition-property: color) or
(animation-name: foo)) and
(transform: rotate(10deg)) {
// ...
}</pre>
<pre>@supports (transition-property: color) or
((animation-name: foo) and
(transform: rotate(10deg))) {
// ...
}</pre>
</div>
<p>Furthermore, whitespace is required after a ‘<code
class=css>not</code>’ and on both sides of an ‘<code
class=css>and</code>’ or ‘<a href="#or"><code
class=css>or</code></a>’.
<p>The declaration being tested must always occur within parentheses, when
it is the only thing in the expression.
<p>
<div class=example>
<p>For example, the following rule is not valid:
<pre class=illegal>@supports display: flexbox {
// ...
}</pre>
<p>Instead, authors must write:
<pre>@supports (display: flexbox) {
// ...
}</pre>
</div>
<p>The syntax allows extra parentheses when they are not needed. This
flexibility is sometimes useful for authors (for example, when commenting
out parts of an expression) and may also be useful for authoring tools.
<div class=example>
<p>For example, authors may write:
<pre>@supports ((display: flexbox)) {
// ...
}</pre>
</div>
<p>A trailing ‘<code class=css>!important</code>’ on a declaration
being tested is allowed, though it won't change the validity of the
declaration.
<div class=example>
<p>For example, the following rule is valid:
<pre>@supports (display: flexbox !important) {
// ...
}</pre>
</div>
<h3 id=support-definition><span class=secno>6.1. </span>Definition of
support</h3>
<p>For forward-compatibility, <a
href="http://www.w3.org/TR/CSS21/syndata.html#declaration">section 4.1.8
(Declarations and properties)</a> of <a href="#CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a> defines rules for handling
invalid properties and values. CSS processors that do not implement or
partially implement a specification <strong>must</strong> treat any part
of a value that they do not implement, or do not have a usable level of
support for, as invalid according to this rule for handling invalid
properties and values, and therefore <strong>must</strong> discard the
declaration as a parse error.
<p>A CSS processor is considered to <dfn id=dfn-support>support</dfn> a
declaration (consisting of a property and value) if it accepts that
declaration (rather than discarding it as a parse error). If a processor
does not implement, with a usable level of support, the value given, then
it <strong>must not</strong> accept the declaration or claim support for
it.
<p class=note>Note that properties or values whose support is effectively
disabled by user preferences are still considered as supported by this
definition. For example, if a user has enabled a high-contrast mode that
causes colors to be overridden, the CSS processor is still considered to
support the ‘<code class=property>color</code>’ property even though
declarations of the ‘<code class=property>color</code>’ property may
have no effect. On the other hand, a developer-facing preference whose
purpose is to enable or disable support for an experimental CSS feature
does affect this definition of support.
<p>These rules (and the equivalence between them) allow authors to use
fallback (either in the <a href="#CSS1"
rel=biblioentry>[CSS1]<!--{{CSS1}}--></a> sense of declarations that are
overridden by later declarations or with the new capabilities provided by
the ‘<code class=css>@supports</code>’ rule in this specification)
that works correctly for the features implemented. This applies especially
to compound values; implementations must implement all parts of the value
in order to consider the declaration supported, either inside a ruleset or
in the declaration condition of an ‘<code class=css>@supports</code>’
rule.</p>
<!--
<h2 id="at-document">Document queries: the '@document' rule</h2>
<p>The <dfn>'@document' rule</dfn> is a conditional group
rule whose condition depends on the
<a href="#url-of-doc">URL of the document being styled</a>.
This allows style sheets, particularly user style sheets, to have styles
that only apply to a set of pages rather than to all pages using the
style sheet.</p>
<p class="issue">Given that this @-rule is intended primarily for user
style sheets, what should this specification say about its use in author
style sheets? Should it be forbidden? Should use instead be
discouraged? Or should this specification remain neutral on the
topic, since there are valid uses in author style sheets?</p>
<p id="url-of-doc">The <dfn>URL of the document being styled</dfn> is
the URI at which the document is located, excluding any fragment
identifiers. (This means, for example, that HTTP redirects have been
followed.) If the styles are being applied inside a complete document
embedded into the presentation of another (e.g., [[HTML5]]'s <code
class="html">iframe</code>, <code class="html">object</code>, or <code
class="html">img</code> elements), the relevant URI is that of the
frame, not of its container. However, if content from other documents
is mixed in via mechanisms that mix content from one document into
another (e.g., [[SVG11]]'s <code>use</code> element), then the
address of the container document is used.</p>
<p class="note">Note: In [[HTML5]], this is the
<a href="http://dev.w3.org/html5/spec/dom.html#documents">document's address</a>
of a document in a
<a href="http://dev.w3.org/html5/spec/browsers.html#browsing-context">browsing context</a>.</p>
<div class="issue">What form of normalization is done on URLs and domains
before matching? In particular, this specification needs to describe:
<ul>
<li>what form is used for the <a href="#url-of-doc">URL of the document
being styled</a> (and what has been normalized in that form)</li>
<li>what normalization (if any) happens to the argument of each of the match
functions before the comparison that they describe and</li>
<li>whether the
comparison algorithm used is string comparison or some other URL
comparison algorithm.</li></ul></div>
<p>The '@document' rule's condition is written as a
comma-separated list of <dfn>URL matching functions</dfn>, and the
condition evaluates to true whenever any one of those functions
evaluates to true. The following URL matching functions are
permitted:</p>
<dl>