Fri, 26 Oct 2012 15:25:45 -0700
added test annotation script to css3-conditional
1 <!DOCTYPE html public '-//W3C//DTD HTML 4.01//EN'
2 'http://www.w3.org/TR/html4/strict.dtd'>
3 <html lang="en">
4 <head profile="http://www.w3.org/2006/03/hcard">
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6 <title>CSS Conditional Rules Module Level 3</title>
7 <link rel="stylesheet" type="text/css" href="../default.css">
8 <link rel="stylesheet" type="text/css"
9 href="http://www.w3.org/StyleSheets/TR/W3C-[STATUS].css">
10 <script src="http://test.csswg.org/harness/annotate.js#CSS3-CONDITIONAL_DEV"
11 type="text/javascript" defer></script>
12 </head>
14 <div class="head">
15 <!--logo-->
17 <h1>CSS Conditional Rules Module Level 3</h1>
19 <h2 class="no-num no-toc">[LONGSTATUS] [DATE]</h2>
20 <dl>
21 <dt>This version:
22 <dd><a href="[VERSION]">
23 http://www.w3.org/TR/[YEAR]/ED-css3-conditional-[CDATE]/</a>
25 <dt>Latest version:
26 <dd><a href="http://www.w3.org/TR/[SHORTNAME]/">http://www.w3.org/TR/[SHORTNAME]/</a>
28 <dt>Editor's draft:
29 <dd><a href="http://dev.w3.org/csswg/[SHORTNAME]/">http://dev.w3.org/csswg/[SHORTNAME]/</a>
31 <dt>Previous version:
32 <dd><a href="http://www.w3.org/TR/2012/WD-css3-conditional-20120911/">http://www.w3.org/TR/2012/WD-css3-conditional-20120911/</a></dd>
34 <dt>Editors:
35 <dd class=vcard><a class=fn href="http://dbaron.org/">L. David Baron</a>,
36 <a class=org href="http://www.mozilla.org/">Mozilla</a>
38 <dt>Issues list:
39 <dd>Maintained in document (only editor's draft is current)
41 <dt>Feedback:
43 <dd><a
44 href="http://lists.w3.org/Archives/Public/www-style/">www-style@w3.org</a>
45 with subject line “<kbd>[[SHORTNAME]] <var>… message topic
46 …</var></kbd>”
48 <dt>Test suite:
49 <dd><a href="https://test.csswg.org/shepherd/search/spec/css3-conditional/">submitted tests</a>; no built test suite yet
51 </dl>
53 <!--copyright-->
55 <hr title="Separator for header">
56 </div>
58 <h2 class="no-num no-toc" id="abstract">Abstract</h2>
60 <p>CSS is a language for describing the rendering of structured documents
61 (such as HTML and XML) on screen, on paper, in speech, etc. This module
62 contains the features of CSS for conditional processing of parts of
63 style sheets, conditioned on capabilities of the processor or the
64 document the style sheet is being applied to.
65 It includes and extends the functionality of CSS level 2 [[!CSS21]],
66 which builds on CSS level 1 [[CSS1]].
67 The main extensions compared to level 2 are
68 allowing nesting of certain at-rules inside '@media',
69 and the addition of the '@supports'
70 rule for conditional processing.
72 <h2 class="no-num no-toc" id="status">Status of this document</h2>
74 <!--status-->
76 <p>The following features are at risk:
77 <ul>
78 <li>The inclusion of '@font-face' rules and
79 '@keyframes' rules as allowed within all of the @-rules in
80 this specification is at risk, though only because of the relative
81 rates of advancement of specifications. If this specification is able
82 to advance faster than one or both of the specifications defining
83 those rules, then the inclusion of those rules will move from this
84 specification to the specification defining those rules.</li>
86 <li>The addition of support for @-rules inside of conditional grouping
87 rules is at risk; if interoperable implementations are not found, it
88 may be removed to advance the other features in this specification to
89 Proposed Recommendation.</li>
91 <li>The '@supports' rule is at risk; if interoperable
92 implementations are not found, it may be removed to advance the other
93 features in this specification to Proposed Recommendation.</li>
94 </ul>
96 <!--
98 Things to go in level 4:
100 * Create some way to put these new conditional things on an @import.
101 * The @document rule (commented out, down below).
103 -->
105 <h2 class="no-num no-toc" id="contents">Table of contents</h2>
107 <!--toc-->
109 <h2 id="introduction">Introduction</h2>
111 <h3 id="context">Background</h3>
113 <p><em>This section is not normative.</em>
115 <p>[[!CSS21]] defines one type of conditional group rule, the
116 '@media' rule, and allows only rulesets (not other @-rules)
117 inside of it. The '@media' rule provides the ability to
118 have media-specific style sheets, which is also provided by style
119 sheet linking features such as '@import' and
120 <code class="html"><link></code>. The restrictions on the contents of
121 '@media' rules made them less useful; they have forced authors
122 using CSS features involving @-rules in media-specific style sheets to
123 use separate style sheets for each medium.</p>
125 <p>This specification extends the rules for the contents of
126 conditional group rules to allow other @-rules, which enables authors
127 to combine CSS features involving @-rules with media specific style
128 sheets within a single style sheet.</p>
130 <p>This specification also defines an additional type of conditional
131 group rule, '@supports', to
132 address author and user requirements.</p>
134 <p>The '@supports' rule allows CSS to be conditioned on
135 implementation support for CSS properties and values. This rule makes
136 it much easier for authors to use new CSS features and provide good
137 fallback for implementations that do not support those features. This
138 is particularly important for CSS features that provide new layout
139 mechanisms, and for other cases where a set of related styles needs to
140 be conditioned on property support.</p>
142 <h3 id="placement">Module Interactions</h3>
144 <p>This module replaces and extends the '@media' rule
145 feature defined in [[!CSS21]] section <var>7.2.1</var> and
146 incorporates the modifications previously made non-normatively by
147 [[!MEDIAQ]] section <var>1</var>.</p>
149 <p>Its current definition depends on @-rules defined in [[!CSS3-FONTS]]
150 and [[!CSS3-ANIMATIONS]], but that dependency is only on the
151 assumption that those modules will advance ahead of this one. If this
152 module advances faster, then the dependency will be reversed.</p>
154 <h3 id="conventions">Document Conventions</h3>
156 <p>Conformance requirements are expressed with a combination of
157 descriptive assertions and RFC 2119 terminology. The key words “MUST”,
158 “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”,
159 “RECOMMENDED”, “MAY”, and “OPTIONAL” in the normative parts of this
160 document are to be interpreted as described in RFC 2119.
161 However, for readability, these words do not appear in all uppercase
162 letters in this specification.
164 <p>All of the text of this specification is normative except sections
165 explicitly marked as non-normative, examples, and notes. [[!RFC2119]]</p>
167 <p>Examples in this specification are introduced with the words “for example”
168 or are set apart from the normative text with
169 <code class="html">class="example"</code>, like this:
171 <div class="example">
172 <p>This is an example of an informative example.</p>
173 </div>
175 <p>Informative notes begin with the word “Note” and are set apart from the
176 normative text with <code class="html">class="note"</code>, like this:
178 <p class="note">Note, this is an informative note.</p>
180 <h2 id="processing">Processing of conditional group rules</h2>
182 <p>This specification defines some CSS @-rules, called <dfn>conditional
183 group rules</dfn>, that associate a condition with a group of other
184 CSS rules. These different rules allow testing different types of
185 conditions, but share common behavior for how their contents are used
186 when the condition is true and when the condition is false.</p>
188 <div class="example">
189 <p>For example, this rule:</p>
190 <pre>@media print {
191 #navigation { display: none }
192 }</pre>
193 <p>causes a particular CSS rule (making elements with ID "navigation" be
194 display:none) apply only when the style sheet is used for a print
195 medium.
196 </div>
198 <p>Each conditional group rule has a condition, which at any time
199 evaluates to true or false. When the condition is true, CSS processors
200 <strong>must</strong> apply the rules inside the group rule as though
201 they were at the group rule's location; when the condition is false, CSS
202 processors <strong>must not</strong> apply any of rules inside the group
203 rule. The current state of the condition does not affect the CSS object
204 model, in which the contents of the group rule always remain within the
205 group rule.</p>
207 <p>This means that when multiple conditional group rules are nested,
208 a rule inside of both of them applies only when all of the rules'
209 conditions are true.</p>
211 <div class="example">For example, with this set of nested rules:
212 <pre>@media print { // rule (1)
213 #navigation { display: none }
214 @media (max-width: 12cm) { // rule (2)
215 .note { float: none }
216 }
217 }</pre>
218 the condition of the rule marked (1) is true for print media, and the
219 condition of the rule marked (2) is true when the width of the display
220 area (which for print media is the page box) is less than or equal to
221 12cm. Thus the rule ''#navigation { display: none }'' applies
222 whenever this style sheet is applied to print media, and the rule
223 ''.note { float: none }'' is applied only when the style sheet
224 is applied to print media <em>and</em> the width of the page box is less
225 than or equal to 12 centimeters.</div>
227 <p>When the condition for a conditional group rule changes, CSS
228 processors <strong>must</strong> reflect that the rules now apply or no
229 longer apply, except for properties whose definitions define effects of
230 computed values that persist past the lifetime of that value (such as
231 for some properties in [[CSS3-TRANSITIONS]] and
232 [[!CSS3-ANIMATIONS]]).</p>
234 <h2 id="contents-of">Contents of conditional group rules</h2>
236 <p>The syntax of each conditional group rule consists of some syntax
237 specific to the type of rule followed by a <dfn>group rule body</dfn>,
238 which is a block (pair of braces) containing a sequence of rules.</p>
240 <p>A group rule body is allowed to contain rulesets and any @-rules that
241 are allowed at the top level of a style sheet before and after a
242 ruleset. This means that @-rules that must occur at the beginning of
243 the style sheet (such as '@charset', '@import',
244 and '@namespace' rules) are not allowed inside of conditional group
245 rules. Conditional group rules can be nested.</p>
247 <p>In terms of the grammar, this specification defines the following
248 productions for use in the grammar of conditional group rules:</p>
250 <pre>nested_statement
251 : ruleset | media | page | font_face_rule | keyframes_rule |
252 supports_rule
253 ;
255 group_rule_body
256 : '{' S* nested_statement* '}' S*
257 ;</pre>
258 <p>
259 in which all the productions are defined in that grammar with the
260 exception of <code>font_face_rule</code>
261 defined in [[!CSS3-FONTS]], <code>keyframes_rule</code> defined in
262 [[!CSS3-ANIMATIONS]], and <code>media</code> and <code>supports_rule</code>
263 defined in this specification.</p>
265 <p>In general, future CSS specifications that add new @-rules that are
266 not forbidden to occur after some other types of rules should modify
267 this <code>nested_statement</code> production to keep the grammar
268 accurate.</p>
270 <p>Style sheets <strong>must not</strong> use rules other than the allowed ones inside
271 conditional group rules.</p>
273 <p>CSS processors <strong>must</strong> ignore rules that are not
274 allowed within a group rule, and <strong>must</strong> handle invalid
275 rules inside of group rules as described in <a
276 href="http://www.w3.org/TR/CSS21/syndata.html#parsing-errors">section
277 4.2 (Rules for handling parsing errors)</a>, <a
278 href="http://www.w3.org/TR/CSS21/syndata.html#at-rules">section 4.1.5
279 (At-rules)</a>, and <a
280 href="http://www.w3.org/TR/CSS21/syndata.html#rule-sets">section 4.1.7
281 (Rule sets, declaration blocks, and selectors)</a> of [[!CSS21]].</p>
283 <h2 id="use">Placement of conditional group rules</h2>
285 <p>Conditional group rules are allowed at the top-level of a style
286 sheet, and inside other conditional group rules. CSS processors
287 <strong>must</strong> process such rules as <a
288 href="#processing">described above</a>.</p>
290 <p>Any rules that are not allowed after a ruleset (e.g., ''@charset'',
291 ''@import'', or ''@namespace'' rules) are also not allowed after a
292 conditional group rule. Therefore, style sheets <strong>must
293 not</strong> place such rules after a conditional group rules, and CSS
294 processors <strong>must</strong> ignore such rules.</p>
296 <h2 id="at-media">Media-specific style sheets: the '@media' rule</h2>
298 <p>The <dfn>'@media' rule</dfn> is a conditional group rule whose
299 condition is a media query. It consists of the at-keyword
300 '@media' followed by a (possibly empty) media query list (as
301 defined in [[!MEDIAQ]]), followed by a group rule body. The condition
302 of the rule is the result of the media query.</p>
304 <div class="example">
305 <p>This '@media' rule:</p>
306 <pre>@media print, (max-width: 600px) {
307 #extra_navigation { display: none }
308 }</pre>
309 <p>has the condition ''print, (max-width: 600px)'', which is
310 true for print media and for devices whose width is at most 600px. When
311 either of these is true, the condition of the rule is true, and the rule
312 ''#extra_navigation { display: none }'' is applied.
313 </div>
315 <p>In terms of the grammar, this specification extends the
316 <code>media</code> production in the
317 <a href="http://www.w3.org/TR/CSS21/grammar.html">Grammar of CSS 2.1</a>
318 ([[!CSS21]], Appendix G) into:
319 <pre>media
320 : MEDIA_SYM S* media_query_list group_rule_body
321 ;</pre>
322 <p>where the <code>group_rule_body</code> production is defined in this
323 specification, the <code>media_query_list</code> production is defined
324 in [[!MEDIAQ]], and the others are defined in the <a
325 href="http://www.w3.org/TR/CSS21/grammar.html">Grammar of CSS 2.1</a>
326 ([[!CSS21]], Appendix G).
328 <h2 id="at-supports">Feature queries: the '@supports' rule</h2>
330 <p>The <dfn>'@supports' rule</dfn> is a conditional group
331 rule whose condition tests whether the user agent supports CSS
332 property:value pairs. Authors can use it to write style sheets that use
333 new features when available but degrade gracefully when those features
334 are not supported. CSS has existing mechanisms for graceful
335 degradation, such as ignoring unsupported properties or values, but
336 these are not always sufficient when large groups of styles need to be
337 tied to the support for certain features, as is the case for use of new
338 layout system features.</p>
340 <p>The syntax of the condition in the '@supports' rule is
341 slightly more complicated than for the other conditional group rules
342 (though has some similarities to media queries) since:</p>
343 <ul>
344 <li>negation is needed so that the new-feature styles and the fallback
345 styles can be separated (within the forward-compatible grammar's rules
346 for the syntax of @-rules), and not required to override each other</li>
347 <li>conjunction (and) is needed so that multiple required features can
348 be tested</li>
349 <li>disjunction (or) is needed when there are multiple alternative
350 features for a set of styles, particularly when some of those
351 alternatives are vendor-prefixed properties or values</li>
352 </ul>
354 <p>Therefore, the syntax of the '@supports' rule allows
355 testing for property:value pairs, and arbitrary conjunctions (and),
356 disjunctions (or), and negations (not) of them.</p>
358 <p>This extends the lexical scanner in the
359 <a href="http://www.w3.org/TR/CSS21/grammar.html">Grammar of CSS 2.1</a>
360 ([[!CSS21]], Appendix G) by adding:
361 <pre>
362 @{S}{U}{P}{P}{O}{R}{T}{S} {return SUPPORTS_SYM;}
363 {O}{R} {return OR;}
364 </pre>
365 <p>and the grammar by adding</p>
366 <pre><dfn>supports_rule</dfn>
367 : SUPPORTS_SYM S* supports_condition group_rule_body
368 ;
370 <dfn>supports_condition</dfn>
371 : supports_negation | supports_conjunction | supports_disjunction |
372 supports_condition_in_parens
373 ;
375 <dfn>supports_condition_in_parens</dfn>
376 : ( '(' S* supports_condition ')' S* ) | supports_declaration_condition
377 ;
379 <dfn>supports_negation</dfn>
380 : NOT S* supports_condition_in_parens
381 ;
383 <dfn>supports_conjunction</dfn>
384 : supports_condition_in_parens ( AND S* supports_condition_in_parens )+
385 ;
387 <dfn>supports_disjunction</dfn>
388 : supports_condition_in_parens ( OR S* supports_condition_in_parens )+
389 ;
391 <dfn>supports_declaration_condition</dfn>
392 : '(' S* core_declaration ')' S* | FUNCTION S* [any|unused]* ')'
393 ;</pre>
394 <p>in which <code>core_declaration</code> is the production
395 <code>declaration</code> in the core syntax of CSS defined in <a
396 href="http://www.w3.org/TR/CSS21/syndata.html#tokenization">section
397 4.1.1 (Tokenization)</a> of [[!CSS21]],
398 and the <code>AND</code> and <code>NOT</code> tokens are defined in
399 the Media Queries specification [[!MEDIAQ]].</p>
401 <p>Any ''@supports'' rule that does not parse according to the grammar
402 above is invalid. Style sheets <strong>must not</strong> use such a
403 rule and processors <strong>must</strong> ignore such a rule.</p>
405 <p class="note">Note that this means that declarations that meet the
406 forward-compatible syntax for declarations are permitted (and support
407 for them is then tested by the ''@supports'' rule), but declarations
408 that do not meet the forward-compatible syntax for declarations cause
409 the entire ''@supports'' rule to be ignored.</p>
411 <p>Each of these grammar terms is associated with a boolean result, as
412 follows:</p>
413 <dl>
414 <dt>supports_condition</dt>
415 <dd>
416 The result is the result of the single child term.
417 </dd>
419 <dt>supports_condition_in_parens</dt>
420 <dd>
421 The result is the result of the single <code>supports_condition</code>
422 or <code>supports_declaration_condition</code> child term.
423 </dd>
425 <dt>supports_negation</dt>
426 <dd>
427 The result is the <em>negation</em> of the result of the
428 <code>supports_condition_in_parens</code> child term.
429 </dd>
431 <dt>supports_conjunction</dt>
432 <dd>
433 The result is true if the result of <em>all</em> of the
434 <code>supports_condition_in_parens</code> child terms is true;
435 otherwise it is false.
436 </dd>
438 <dt>supports_disjunction</dt>
439 <dd>
440 The result is true if the result of <em>any</em> of the
441 <code>supports_condition_in_parens</code> child terms is true;
442 otherwise it is false.
443 </dd>
445 <dt>supports_declaration_condition</dt>
446 <dd>
447 The result is false if this corresponds to a functional notation;
448 otherwise, the result is whether the CSS processor <a
449 href="#support-definition">supports</a> the declaration
450 within the parentheses.
451 <span class="note">Note that future levels may define functions that can evaluate to true.</span>
452 </dd>
453 </dl>
455 <p>The condition of the '@supports' rule is the result of the
456 <code>supports_condition</code> term that is a child of the
457 <code>supports_rule</code> term.</p>
459 <div class="example">
460 <p>For example, the following rule</p>
461 <pre>@supports ( display: flexbox ) {
462 body, #navigation, #content { display: flexbox; }
463 #navigation { background: blue; color: white; }
464 #article { background: white; color: black; }
465 }</pre>
466 <p>applies the rules inside the '@supports' rule only when
467 ''display: flexbox'' is supported.</p>
468 </div>
470 <div class="example">
471 <p>The following example shows an additional '@supports' rule that can
472 be used to provide an alternative for when ''display: flexbox'' is not
473 supported:</p>
474 <pre>@supports not ( display: flexbox ) {
475 body { width: 100%; height: 100%; background: white; color: black; }
476 #navigation { width: 25%; }
477 #article { width: 75%; }
478 }</pre>
479 <p>Note that the 'width' declarations may be harmful to the
480 flexbox-based layout, so it is important that they be present only in
481 the non-flexbox styles.</p>
482 </div>
484 <div class="example">
485 <p>The following example checks for support for the 'box-shadow'
486 property, including checking for support for vendor-prefixed versions of
487 it. When the support is present, it specifies both 'box-shadow' (with
488 the prefixed versions) and 'color' in a way what would cause the text to
489 become invisible were 'box-shadow' not supported.</p>
490 <pre>@supports ( box-shadow: 2px 2px 2px black ) or
491 ( -moz-box-shadow: 2px 2px 2px black ) or
492 ( -webkit-box-shadow: 2px 2px 2px black ) or
493 ( -o-box-shadow: 2px 2px 2px black ) {
494 .outline {
495 color: white;
496 -moz-box-shadow: 2px 2px 2px black;
497 -webkit-box-shadow: 2px 2px 2px black;
498 -o-box-shadow: 2px 2px 2px black;
499 box-shadow: 2px 2px 2px black; /* unprefixed last */
500 }
501 }</pre></div>
503 <p>To avoid confusion between ''and'' and ''or'', the syntax requires
504 that both ''and'' and ''or'' be specified explicitly (rather than, say,
505 using commas or spaces for one of them). Likewise, to avoid confusion
506 caused by precedence rules, the syntax does not allow ''and'', ''or'',
507 and ''not'' operators to be mixed without a layer of parentheses.</p>
509 <div class="example">
510 <p>For example, the following rule is not valid:
511 <pre class="illegal">@supports (transition-property: color) or
512 (animation-name: foo) and
513 (transform: rotate(10deg)) {
514 // ...
515 }</pre>
516 <p>Instead, authors must write one of the following:</p>
517 <pre>@supports ((transition-property: color) or
518 (animation-name: foo)) and
519 (transform: rotate(10deg)) {
520 // ...
521 }</pre>
522 <pre>@supports (transition-property: color) or
523 ((animation-name: foo) and
524 (transform: rotate(10deg))) {
525 // ...
526 }</pre>
527 </div>
529 <p>The declaration being tested must always occur within parentheses,
530 when it is the only thing in the expression.<p>
532 <div class="example">
533 <p>For example, the following rule is not valid:
534 <pre class="illegal">@supports display: flexbox {
535 // ...
536 }</pre>
537 <p>Instead, authors must write:</p>
538 <pre>@supports (display: flexbox) {
539 // ...
540 }</pre>
541 </div>
543 <p>The syntax allows extra parentheses when they are not needed. This
544 flexibility is sometimes useful for authors (for example, when
545 commenting out parts of an expression) and may also be useful for
546 authoring tools.</p>
548 <div class="example">
549 <p>For example, authors may write:</p>
550 <pre>@supports ((display: flexbox)) {
551 // ...
552 }</pre>
553 </div>
555 <p>A trailing ''!important'' on a declaration being tested is allowed,
556 though it won't change the validity of the declaration.
558 <div class="example">
559 <p>For example, the following rule is valid:
560 <pre>@supports (display: flexbox !important) {
561 // ...
562 }</pre>
563 </div>
565 <h3 id="support-definition">Definition of support</h3>
567 <p>For forward-compatibility,
568 <a href="http://www.w3.org/TR/CSS21/syndata.html#declaration">section 4.1.8
569 (Declarations and properties)</a> of [[!CSS21]]
570 defines rules for handling invalid properties and values.
571 CSS processors that
572 do not implement or partially implement a specification
573 <strong>must</strong> treat any part of a value that they
574 do not implement, or
575 do not have a usable level of support for,
576 as invalid according to this rule
577 for handling invalid properties and values,
578 and therefore <strong>must</strong> discard the declaration as a parse error.</p>
580 <p>A CSS processor is considered to <dfn id="dfn-support">support</dfn>
581 a declaration (consisting of a property and value) if it accepts that
582 declaration (rather than discarding it as a parse error).
583 If a processor does not implement, with a usable level of support,
584 the value given,
585 then it <strong>must not</strong>
586 accept the declaration or claim support for it.</p>
588 <p>These rules (and the equivalence between them) allow
589 authors to use fallback (either in the [[CSS1]] sense of declarations
590 that are overridden by later declarations or with the new capabilities
591 provided by the ''@supports'' rule in this specification) that works
592 correctly for the features implemented. This applies especially to
593 compound values; implementations must implement all parts of the value
594 in order to consider the declaration supported, either inside a ruleset
595 or in the declaration condition of an ''@supports'' rule.</p>
597 <!--
598 <h2 id="at-document">Document queries: the '@document' rule</h2>
600 <p>The <dfn>'@document' rule</dfn> is a conditional group
601 rule whose condition depends on the
602 <a href="#url-of-doc">URL of the document being styled</a>.
603 This allows style sheets, particularly user style sheets, to have styles
604 that only apply to a set of pages rather than to all pages using the
605 style sheet.</p>
607 <p class="issue">Given that this @-rule is intended primarily for user
608 style sheets, what should this specification say about its use in author
609 style sheets? Should it be forbidden? Should use instead be
610 discouraged? Or should this specification remain neutral on the
611 topic, since there are valid uses in author style sheets?</p>
613 <p id="url-of-doc">The <dfn>URL of the document being styled</dfn> is
614 the URI at which the document is located, excluding any fragment
615 identifiers. (This means, for example, that HTTP redirects have been
616 followed.) If the styles are being applied inside a complete document
617 embedded into the presentation of another (e.g., [[HTML5]]'s <code
618 class="html">iframe</code>, <code class="html">object</code>, or <code
619 class="html">img</code> elements), the relevant URI is that of the
620 frame, not of its container. However, if content from other documents
621 is mixed in via mechanisms that mix content from one document into
622 another (e.g., [[SVG11]]'s <code>use</code> element), then the
623 address of the container document is used.</p>
625 <p class="note">Note: In [[HTML5]], this is the
626 <a href="http://dev.w3.org/html5/spec/dom.html#documents">document's address</a>
627 of a document in a
628 <a href="http://dev.w3.org/html5/spec/browsers.html#browsing-context">browsing context</a>.</p>
630 <div class="issue">What form of normalization is done on URLs and domains
631 before matching? In particular, this specification needs to describe:
632 <ul>
633 <li>what form is used for the <a href="#url-of-doc">URL of the document
634 being styled</a> (and what has been normalized in that form)</li>
635 <li>what normalization (if any) happens to the argument of each of the match
636 functions before the comparison that they describe and</li>
637 <li>whether the
638 comparison algorithm used is string comparison or some other URL
639 comparison algorithm.</li></ul></div>
641 <p>The '@document' rule's condition is written as a
642 comma-separated list of <dfn>URL matching functions</dfn>, and the
643 condition evaluates to true whenever any one of those functions
644 evaluates to true. The following URL matching functions are
645 permitted:</p>
647 <dl>
648 <dt><dfn id="url-exact" title="url()|URL matching functions::exact"><url></dfn></dt>
650 <dd>
651 <p>The 'url()' function is the <dfn>exact url matching
652 function</dfn>. It evaluates to true whenever the <a
653 href="#url-of-doc">URL of the document being styled</a> is exactly
654 the URL given.</p>
656 <p class="Note">The 'url()' function, since it is a core syntax
657 element in CSS, is allowed (subject to different character
658 limitations and thus escaping requirements) to contain an unquoted
659 value (in addition to the string values that are allowed as
660 arguments for all four functions).</p>
662 <div class="example">
663 <p>For example, this rule:</p>
664 <pre>@document url("http://www.w3.org/Style/CSS/") {
665 #summary { background: yellow; color: black}
666 }</pre>
667 <p>styles the <code class="html">summary</code> element on the page
668 <code>http://www.w3.org/Style/CSS/</code>, but not on any other
669 pages.</p>
670 </div>
671 </dd>
673 <dt><dfn id="url-prefix" title="url-prefix()|URL matching functions::prefix">url-prefix(<string>)</dfn></dt>
675 <dd>
676 <p>The 'url-prefix()' function is the <dfn>url prefix
677 matching function</dfn>. It evaluates to true whenever the
678 <a href="#url-of-doc">URL of the document being styled</a>
679 has the argument to the function as an
680 initial substring (which is true when the two strings are equal).
681 When the argument is the empty string, it evaluates to true for all
682 documents.</p>
683 <div class="example">
684 <p>For example, this rule:</p>
685 <pre>@document url-prefix("http://www.w3.org/Style/CSS/") {
686 #summary { background: yellow; color: black}
687 }</pre>
688 <p>styles the <code class="html">summary</code> element on the page
689 <code>http://www.w3.org/Style/CSS/</code> and on the page
690 <code>http://www.w3.org/Style/CSS/Test</code>, but it does not
691 affect the page <code>http://www.w3.org/</code> or the page
692 <code>http://www.example.com/Style/CSS/</code>.</p>
693 </div>
694 </dd>
696 <dt><dfn id="url-domain" title="domain()|URL matching functions::domain">domain(<string>)</dfn></dt>
698 <dd>
699 <p>The 'domain()' function is the <dfn>domain
700 matching function</dfn>. It evaluates to true whenever
701 the <a href="#url-of-doc">URL of the document being styled</a>
702 has a host subcomponent (as defined in [[!URI]])
703 and that host subcomponent is exactly the argument to the
704 'domain()' function or a final substring of the host
705 component is a period (U+002E) immediately followed by the argument
706 to the 'domain()' function.</p>
707 <div class="example">
708 <p>For example, this rule:</p>
709 <pre>@document domain("w3.org") {
710 body { font-size: 16px ! important }
711 }</pre>
712 <p>changes the font size of the body element for pages such as
713 <code>http://www.w3.org/Style/CSS/</code> and
714 <code>http://w3.org/Style/CSS/</code> and
715 <code>http://lists.w3.org/Archives/Public/www-style/</code>
716 but it does not affect the page
717 <code>http://www.example.com/Style/CSS/</code>.</p>
718 </div>
719 </dd>
721 <dt><dfn id="url-regexp" title="regexp()|URL matching functions::regular expression">regexp(<string>)</dfn></dt>
723 <dd>
724 <p>The contents of the <string> argument <strong>must</strong>
725 match the JavaScript <code>Pattern</code> production
726 ([[!ECMA-262-5.1]], section 15.10.1). However,
727 failing to do so is not a CSS syntax error and does not trigger any
728 error handling for CSS syntax errors.</p>
730 <p>The ''regexp()'' function evaluates to true whenever the string
731 argument compiled as a JavaScript regular expression with the
732 <code>global</code>, <code>ignoreCase</code> and
733 <code>multiline</code> flags <em>disabled</em>
734 (see [[!ECMA-262-5.1]], sections 15.10.7.2 through 15.10.7.4)
735 compiles successfully and the resulting regular expression matches
736 the entirety of the
737 <a href="#url-of-doc">URL of the document being styled</a>.</p>
739 <p class="note">Note that regular expression must match the entire
740 URL, not just a part of it.</p>
742 <p class="note">Note that this definition intentionally matches the
743 behavior of the <a
744 href="http://dev.w3.org/html5/spec/common-input-element-attributes.html#attr-input-pattern"><code class="html">pattern</code>
745 attribute</a> on the <code class="html">input</code> element
746 in [[HTML5]].</p>
748 <div class="example">
749 <p>For example, this rule:</p>
750 <pre>@document regexp("http://www.w3.org/TR/\\d{4}/[^/]*-CSS2-\\d{8}/") {
751 body { font-size: 20px ! important }
752 }</pre>
753 <p>changes the font size of the body element for pages such as
754 <code>http://www.w3.org/TR/2011/PR-CSS2-20110412/</code>.</p>
755 <p class="note">Note that the backslashes in the regular
756 expression require CSS escaping as ''\\''.</p>
757 </div>
758 </dd>
760 </dl>
762 <p>Implementations <strong>must</strong> treat any unknown URL matching
763 functions as a syntax error, and thus ignore the '@document' rule.
764 <span class="issue">Should we instead have more complicated error
765 handling rules to make forward-compatibility work differently, or is
766 this rule the best solution for such future expansion anyway?</span></p>
768 <div class="issue">This syntax doesn't offer any ability to do negations,
769 which has been requested in <a
770 href="https://bugzilla.mozilla.org/show_bug.cgi?id=349813">Mozilla bug
771 349813</a>. Use cases that people have wanted negations for
772 include:
773 <ul>
774 <li>User style sheets that want a particular rule in general, but know
775 that that rule does more harm than good on specific sites.</li>
776 <li>Authors who have a rule that they want to apply to most of their
777 pages, but wish to make a few exceptions for.</li>
778 </ul>
779 </div>
781 <p>This extends the lexical scanner in the
782 <a href="http://www.w3.org/TR/CSS21/grammar.html">Grammar of CSS 2.1</a>
783 ([[!CSS21]], Appendix G) by adding:
784 <pre>@{D}{O}{C}{U}{M}{E}{N}{T} {return DOCUMENT_SYM;}</pre>
785 <p>and the grammar by adding</p>
786 <pre>document_rule
787 : DOCUMENT_SYM S+ url_match_fn ( "," S* url_match_fn )* group_rule_body
788 ;
790 url_match_fn
791 : (URI | FUNCTION S* STRING S* ')' ) S*
792 ;</pre>
793 -->
796 <h2 id="apis">APIs</h2>
798 <h3 id='extentions-to-cssrule-interface'>
799 Extensions to the <code>CSSRule</code> interface</h3>
801 <p>The <code>CSSRule</code> interface is extended as follows:
803 <pre class='idl'>partial interface CSSRule {
804 const unsigned short SUPPORTS_RULE = 12;
805 <!--
806 const unsigned short DOCUMENT_RULE = 13;
807 -->
808 }</pre>
811 <h3 id='the-cssgroupingrule-interface'>
812 The <code>CSSGroupingRule</code> interface</h3>
814 <p>The <dfn><code>CSSGroupingRule</code></dfn> interface represents an at-rule that contains other rules nested inside itself.
816 <pre class='idl'>interface CSSGroupingRule : CSSRule {
817 readonly attribute CSSRuleList cssRules;
818 unsigned long insertRule (DOMString rule, unsigned long index);
819 void deleteRule (unsigned long index);
820 }</pre>
822 <dl class='idl-attributes'>
823 <dt><code>cssRules</code> of type <code>CSSRuleList</code>, readonly
824 <dd>The <code>cssRules</code> attribute must return a <code>CSSRuleList</code>
825 object for the list of CSS rules nested inside the grouping rule.
826 </dl>
828 <dl class='idl-methods'>
829 <dt><code>insertRule(DOMString rule, unsigned long index)</code>, returns
830 <code>unsigned long</code>
831 <dd>The <code>insertRule</code> operation must insert a CSS rule <var>rule</var>
832 into the CSS rule list returned by <code>cssRules</code> at <var>index</var>.
834 <dt><code>deleteRule (unsigned long index)</code>, return <code>void</code>
835 <dd>The <code>deleteRule</code> operation must remove a CSS rule from the
836 CSS rule list returned by <code>cssRules</code> at <var>index</var>.
837 </dl>
840 <h3 id="the-cssconditionrule-interface">
841 The <code>CSSConditionRule</code> interface</h3>
843 <p>The <dfn><code>CSSConditionRule</code></dfn> interface represents all the "conditional" at-rules,
844 which consist of a condition and a statement block.
846 <pre class='idl'>interface CSSConditionRule : CSSGroupingRule {
847 attribute DOMString conditionText;
848 }</pre>
850 <dl class='idl-attributes'>
852 <dt><code>conditionText</code> of type <code>DOMString</code>
853 <dd>
854 <p>The <code>conditionText</code> attribute represents
855 the condition of the rule.
856 Since what this condition does
857 varies between the derived interfaces of <code>CSSConditionRule</code>,
858 those derived interfaces
859 may specify different behavior for this attribute
860 (see, for example, <code>CSSMediaRule</code> below).
861 In the absence of such rule-specific behavior,
862 the following rules apply:</p>
864 <p>The <code>conditionText</code> attribute, on getting, must return
865 the result of serializing the associated condition.
867 <p>On setting the <code>conditionText</code> attribute these steps
868 must be run:
870 <ol>
871 <li>Trim the given value of white space.
872 <li>If the given value matches the grammar of the
873 appropriate condition production for the given rule,
874 replace the associated CSS condition with the given value.
875 <li>Otherwise, do nothing.
876 </ol>
877 </dl>
880 <h3 id="the-cssmediarule-interface">
881 The <code>CSSMediaRule</code> interface</h3>
883 <p>The <dfn><code>CSSMediaRule</code></dfn> interface represents a ''@media'' rule:
885 <pre class='idl'>interface CSSMediaRule : CSSConditionRule {
886 readonly attribute MediaList media;
887 }</pre>
889 <dl class='idl-attributes'>
890 <dt><code>media</code> of type <code>MediaList</code>, readonly
891 <dd>The <code>media</code> attribute must return a <code>MediaList</code> object
892 for the list of media queries specified with the ''@media'' rule.
894 <dt><code>conditionText</code> of type <code>DOMString</code>
895 <dd>The <code>conditionText</code> attribute (defined on the <code>CSSConditionRule</code> parent rule),
896 on getting, must return the value of <code>media.mediaText</code> on the rule.
898 <p>Setting the <code>conditionText</code> attribute
899 must set the <code>media.mediaText</code> attribute on the rule.
900 </dl>
903 <h3 id="the-csssupportsrule-interface">
904 The <code>CSSSupportsRule</code> interface</h3>
906 <p>The <dfn><code>CSSSupportsRule</code></dfn> interface represents a ''@supports'' rule.</p>
908 <pre class='idl'>interface CSSSupportsRule : CSSConditionRule {
909 }</pre>
911 <!--
912 <h3 id="the-cssdocumentrule-interface">
913 The <code>CSSDocumentRule</code> interface</h3>
915 <p>The <dfn><code>CSSDocumentRule</code></dfn> interface represents a ''@document'' rule.</p>
917 <pre class='idl'>interface CSSDocumentRule : CSSConditionRule {
918 }</pre>
919 -->
922 <h3 id='the-css-interface'>
923 The <code>CSS</code> interface, and the <code title=''>supports()</code> function</h3>
925 <p>The <dfn id='CSS-interface'><code>CSS</code></dfn> interface holds useful CSS-related functions that do not belong elsewhere.
927 <pre class='idl'>interface CSS {
928 boolean supports(DOMString property, DOMString value);
929 boolean supports(DOMString declaration);
930 }</pre>
932 <dl class='idl-methods'>
933 <dt><code>supports(DOMString property, DOMString value)</code>,
934 returns <code>boolean</code>
935 <dt><code>supports(DOMString conditionText)</code>,
936 returns <code>boolean</code>
937 <dd>
938 When the <code title=''>supports()</code> method is invoked with two arguments <var>property</var> and <var>value</var>,
939 it must return <code>true</code> if <var>property</var> is a literal match for the name of a CSS property that the UA supports,
940 and <var>value</var> would be successfully parsed as a supported value for that property.
941 Otherwise, it must return <code>false</code>.
943 <p>
944 When invoked with a single <var>conditionText</var> argument,
945 it must return <code>true</code> if <var>conditionText</var>,
946 when parsed and evaluated as a <code>supports_condition</code>,
947 would return true.
948 Otherwise, it must return <code>false</code>.
949 </dl>
952 <h2 class=no-num id="grammar">Grammar</h2>
954 <p>In order to allow these new @-rules in CSS style sheets, this
955 specification modifies the <code>stylesheet</code> production in the <a
956 href="http://www.w3.org/TR/CSS21/grammar.html">Appendix G</a> grammar of
957 [[!CSS21]] by replacing the <code>media</code> production defined in
958 [[!CSS21]] with the <code>media</code> production defined in this one,
959 and additionally inserting <code>| supports_rule</code>
960 alongside <code>ruleset | media | page</code>.</p>
963 <h2 id="conformance">Conformance</h2>
965 <h3 id="base-modules">Base Modules</h3>
967 <p>This specification defines conformance in terms of base modules,
968 which are modules that this specification builds on top of. The base
969 modules of this module are:</p>
971 <ul>
972 <li>[[!CSS21]]</li>
973 </ul>
975 <p>All of the conformance requirements of all base modules are
976 incorporated as conformance requirements of this module, except where
977 overridden by this module.</p>
979 <p>Additionally, all conformance requirements related to validity of
980 syntax in this module and all of its base modules are to be interpreted
981 as though all syntax in all of those modules is valid.</p>
983 <div class="example"><p>For example, this means that grammar presented
984 in modules other than [[!CSS21]] must obey the requirements that
985 [[!CSS21]] defines for the parsing of properties, and that requirements
986 for handling invalid syntax in [[!CSS21]] do not treat syntax added by
987 other modules as invalid.</p></div>
989 <p>Additionally, the set of valid syntax can be increased by the
990 conformance of a style sheet or processor to additional modules; use of
991 such syntax does not make a style sheet nonconformant and failure to
992 treat such syntax as invalid does not make a processor
993 nonconformant.</p>
995 <h3 id="conformance-classes">Conformance Classes</h3>
997 <p>Conformance to the CSS Conditional Rules Module is defined for three
998 conformance classes:
999 <dl>
1000 <dt><dfn title="conformance::style sheet" id="conform-style-sheet">style sheet</dfn>
1001 <dd>A <a href="http://www.w3.org/TR/CSS21/conform.html#style-sheet">CSS
1002 style sheet</a>.</dd>
1003 <dt><dfn title="conformance::processor" id="conform-processor">processor</dfn></dt>
1004 <dd>A tool that reads CSS style sheets: it may be a renderer or
1005 <a
1006 href="http://www.w3.org/TR/CSS21/conform.html#user-agent">user-agent</a>
1007 that interprets the semantics of a style sheet and renders
1008 documents that use style sheets, or it may be a validator that
1009 checks style sheets.</dd>
1010 <dt><dfn title="conformance::authoring tool" id="conform-authoring-tool">authoring tool</dfn></dt>
1011 <dd>A tool that writes a style sheet.</dd>
1012 </dl>
1014 <p>A style sheet is conformant to the CSS Conditional Rules Module
1015 if it meets all of the conformance requirements in the module that are
1016 described as requirements of style sheets.</p>
1018 <p>A processor is conformant to the CSS Conditional Rules Module if it
1019 meets all applicable conformance requirements in the module that are
1020 described as requirements of processors. In general, all requirements
1021 are applicable to renderers. Requirements concerning a part of CSS
1022 not performed by a processor are not applicable, e.g., requirements
1023 related to rendering are not applicable to a validator. The inability
1024 of a processor to correctly render a document due to limitations of
1025 the device does not make it non-conformant. (For example, a renderer
1026 is not required to render color on a monochrome monitor.)</p>
1028 <p>An authoring tool is conformant to the CSS Conditional Rules Module
1029 if it writes style sheets that conform to the module and (if it reads
1030 CSS) it is a conformant processor.</p>
1032 <h3 id="partial">
1033 Partial Implementations</h3>
1035 <p>So that authors can exploit the forward-compatible parsing rules to
1036 assign fallback values, CSS renderers <strong>must</strong>
1037 treat as invalid (and <a href="http://www.w3.org/TR/CSS21/conform.html#ignore">ignore
1038 as appropriate</a>) any at-rules, properties, property values, keywords,
1039 and other syntactic constructs for which they have no usable level of
1040 support. In particular, user agents <strong>must not</strong> selectively
1041 ignore unsupported component values and honor supported values in a single
1042 multi-value property declaration: if any value is considered invalid
1043 (as unsupported values must be), CSS requires that the entire declaration
1044 be ignored.</p>
1046 <h3 id="experimental">Experimental Implementations</h3>
1048 <p>To avoid clashes with future CSS features, the CSS specifications
1049 reserve a <a href="http://www.w3.org/TR/CSS21/syndata.html#vendor-keywords">prefixed
1050 syntax</a> for proprietary property and value extensions to CSS. The CSS
1051 Working Group recommends that experimental implementations of features in
1052 CSS Working Drafts also use vendor-prefixed property or value names. This
1053 avoids any incompatibilities with future changes in the draft. Once a
1054 specification reaches the Candidate Recommendation stage, implementors
1055 should implement the non-prefixed syntax for any feature they consider to
1056 be correctly implemented according to spec.</p>
1058 <h3 id="cr-exit-criteria">CR Exit Criteria</h3>
1060 <p>For this specification to be advanced to Proposed Recommendation,
1061 there must be at least two independent, interoperable implementations
1062 of each feature. Each feature may be implemented by a different set of
1063 products, there is no requirement that all features be implemented by
1064 a single product. For the purposes of this criterion, we define the
1065 following terms:
1067 <dl>
1068 <dt>independent <dd>each implementation must be developed by a
1069 different party and cannot share, reuse, or derive from code
1070 used by another qualifying implementation. Sections of code that
1071 have no bearing on the implementation of this specification are
1072 exempt from this requirement.
1074 <dt>interoperable <dd>passing the respective test case(s) in the
1075 official CSS test suite, or, if the implementation is not a Web
1076 browser, an equivalent test. Every relevant test in the test
1077 suite should have an equivalent test created if such a user
1078 agent (UA) is to be used to claim interoperability. In addition
1079 if such a UA is to be used to claim interoperability, then there
1080 must one or more additional UAs which can also pass those
1081 equivalent tests in the same way for the purpose of
1082 interoperability. The equivalent tests must be made publicly
1083 available for the purposes of peer review.
1085 <dt>implementation <dd>a user agent which:
1087 <ol class=inline>
1088 <li>implements the specification.
1090 <li>is available to the general public. The implementation may
1091 be a shipping product or other publicly available version
1092 (i.e., beta version, preview release, or “nightly build”).
1093 Non-shipping product releases must have implemented the
1094 feature(s) for a period of at least one month in order to
1095 demonstrate stability.
1097 <li>is not experimental (i.e., a version specifically designed
1098 to pass the test suite and is not intended for normal usage
1099 going forward).
1100 </ol>
1101 </dl>
1103 <p>The specification will remain Candidate Recommendation for at least
1104 six months.
1106 <h2 id="changes">
1107 Changes</h2>
1109 <p>The following (non-editorial) changes were made to this specification since the
1110 <a href="http://www.w3.org/TR/2012/WD-css3-conditional-20120911/">11 September 2012 Working Draft</a>:
1112 <ul>
1113 <li>Removed ''@document'' rule; it has been deferred to Level 4.
1114 <li>Allow functional notation in ''@supports'' queries to be valid (to allow for future extensions),
1115 but treat such notations as always being false.
1116 <li>Corrected the grammar as follows:
1117 <pre>
1118 - : SUPPORTS_SYM S+ supports_condition group_rule_body
1119 + : SUPPORTS_SYM S* supports_condition group_rule_body
1120 </pre>
1121 <pre>
1122 - : (URI | FUNCTION) S*
1123 + : (URI | FUNCTION S* STRING S* ')' ) S*
1124 </pre>
1125 <li>Switched "and", "or", and "not" keywords to use appropriate productions rather than literals.
1126 <li>Clarified definition of support used for interpreting ''@support'' rules
1127 and its relationship to CSS forwards-compatible parsing rules.
1128 </ul>
1130 <h2 class=no-num id="acknowledgments">Acknowledgments</h2>
1132 <p>
1133 Thanks to the ideas and feedback from
1134 Tab Atkins,
1135 <span lang="tr">Tantek Çelik</span>,
1136 Alex Danilo,
1137 Elika Etemad,
1138 Pascal Germroth,
1139 <span lang="de">Björn Höhrmann</span>,
1140 Paul Irish,
1141 Vitor Menezes,
1142 Alex Mogilevsky,
1143 Chris Moschini,
1144 Simon Sapin,
1145 Ben Ward,
1146 Zack Weinberg,
1147 Estelle Weyl,
1148 Boris Zbarsky,
1149 and all the rest of the <a href="http://lists.w3.org/Archives/Public/www-style/">www-style</a> community.
1151 </p>
1153 <h2 class=no-num id="references">References</h2>
1156 <h3 class="no-num" id="normative-references">Normative references</h3>
1157 <!--normative-->
1159 <h3 class="no-num" id="other-references">Other references</h3>
1160 <!--informative-->
1162 <h2 class="no-num" id="index">Index</h2>
1163 <!--index-->
1165 </body>
1166 </html>
1167 <!-- Keep this comment at the end of the file
1168 Local variables:
1169 mode: sgml
1170 sgml-declaration:"~/SGML/HTML4.decl"
1171 sgml-default-doctype-name:"html"
1172 sgml-minimize-attributes:t
1173 sgml-nofill-elements:("pre" "style" "br")
1174 sgml-live-element-indicator:t
1175 sgml-omittag:nil
1176 sgml-shorttag:nil
1177 sgml-namecase-general:t
1178 sgml-general-insert-case:lower
1179 sgml-always-quote-attributes:t
1180 sgml-indent-step:nil
1181 sgml-indent-data:t
1182 sgml-parent-document:nil
1183 sgml-exposed-tags:nil
1184 sgml-local-catalogs:nil
1185 sgml-local-ecat-files:nil
1186 End:
1187 -->