CSS Custom Properties and References Module Level 2

Extensible Web CG's Draft (2012-12-07)

This version:
Extensible CSS's unofficial draft
Latest version:
http://www.w3.org/TR/css-variables/
CSS WG's editors:
Luke Macpherson, Google, Inc.,
Tab Atkins Jr., Google, Inc.
Daniel Glazman, Disruptive Innovations,
Extensible Web CG's editors:
François REMY, Université Libre de Bruxelles
Brian Kardell, Apollo Group, Inc.

Abstract

CSS is a language for describing the rendering of structured documents (such as HTML and XML) on screen, on paper, in speech, etc. This module contains the features of CSS level 3 relating to custom properties. It includes and extends the functionality of CSS level 2 [CSS21], which builds on CSS level 1 [CSS1].

The main extensions of this spec to CSS level 2 are the introduction of references as a new primitive value type that is accepted by all properties, as well has a new family of inherited properties called custom properties whose value can be any valid CSS token list.

Status of this document

This is a public copy of a proposal 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.

The (archived) public mailing list www-style@w3.org (see instructions) is preferred for discussion of this specification. When sending e-mail, please put the text “css-custom” in the subject, preferably like this: “[css-custom] …summary of comment…”.

Table of contents

1. Introduction

This section is not normative.

Modern documents and applications contain a significant amount of styling information, often spread across numerous related stylesheets.  By their nature, they describe important implicit design relationships.  For example, most authors design a palette consisting of a small number of colors and font treatments which are used repeatedly in numerous locations, targeting disparate pieces of the styled document. Today, the intended link between those values is often lost as values are repeated, making altering this data difficult and error-prone.

Each of these related values, in concept, points to a single virtual CSS value. Until now, however, the link between them has never materialized in expressive terms. One of the goals of this module is to make factual this link by introducing the concept of reference in CSS.

To accomplish those goals, this module introduces a new family of properties known collectively as custom properties, which allow an author to assign arbitrary values to properties with an author-chosen name. This module also introduces property references, a mechanism which allows an author to reuse the value of those properties into other CSS properties. 

Thus, what were previously arbitrary-seeming values (like #cfcfff) may now have informative names (like x-primary-color). This makes authoring and editing stylesheets much easier and less error-prone, as a single value modification at the custom property declaration site will automatically propagate to anywhere that property is referenced.

The example below demonstrates how custom properties and property references allow the author to adapt the design of websites easily. Imagine the common case in which a website has a variant color scheme depending on the section, but otherwise share a common layout (as illustrated by the following pictures):

[RED WEBSITE]    [GREEN WEBSITE]    [BLUE WEBSITE]

Custom properties and references allow the author to express these relationships variably and thus efficiently manage the CSS:

/* red color scheme (default) */
@document url-prefix("http://example.com/") {
html {
 x-dark-color: #770000;
 x-light-color: #ffdddd;
 x-color: #eebbbb;
 }
}

/* green color scheme */
@document url-prefix("http://example.com/green-section") {
html {
 x-dark-color: #007700;
 x-light-color: #ddffdd;
 x-color: #bbeebb;
 }
}

/* blue color scheme */
@document url-prefix("http://example.com/blue-section") {
html {
x-dark-color: #000077;
x-light-color: #ddddff;
x-color: #bbbbee;
}
}

/* website styling */
header { background-color: get(x-dark-color); }
nav { background-color: get(x-light-color); }
nav .selected { background-color: get(x-color); }
h1 { color: get(x-dark-color); }

Additionally, this module aims to provide a way for authors to dispatch custom styling information to their custom components in a way that does not interfere with browser-provided properties.

This design also brings a new tool for Web authors to shim unimplemented CSS properties in a forward compatible manner by guaranteeing that new native implementations will never overlap with their own implementation.

The example below illustrates how authors can use custom properties and property references to shim properties on their own HTML components:

<style>
.no-toolbar { x-toolbar-display: none }
</style>

<x-property-editor
data-for="document.body"
class="no-toolbar"
/>

In the shadow tree style of the <x-property-editor> element, the following CSS could be used:

#toolbar { display: get(x-toolbar-display); }

This works because custom properties are inherited across the shadow tree boundaries.

The example below, extracted from an hypothetical Christmas animation, illustrates how authors can use custom properties to represent meta-information and affect several other properties :

.snow
{
background: url(snowflake.svg);
width: calc(5px * get(x-radius)); height: calc(5px * get(x-radius));

animation:
 fallOnTheGround 15s infinite;
animation-duration:
calc(15s * get(x-weight));
x-horizontal-bouncing:
calc(5px / get(x-radius) / get(x-radius));
}

.small.snow { x-radius: 0.9; }
.snow { x-radius: 1.0; }
.big.snow { x-radius: 1.5; }

1.1. Module Interactions

This module defines a new type of primitive value, the token stream reference, which is accepted in all CSS expressions, anywhere one or more tokens are required or accepted.

1.2. Values

This specification follows the CSS property definition conventions from [CSS21]. Value types not defined in this specification are defined in CSS Level 2 Revision 1 [CSS21]. Other CSS modules may expand the definitions of these value types: for example [CSS3COLOR], when combined with this module, expands the definition of the <color> value type as used in this specification.

2. Definitions

2.1. Token stream

A token stream is a dynamic list of CSS tokens, as defined in the CSS2.1 Chapter 4 specification (or in the CSS Syntax specification [CSS3-SYNTAX] as soon as it will reach the W3C Recommendation status).

To be valid, a token stream must conform to the <value> type (a token stream which doesn't conform is called an invalid token stream).

Given the <value> type definition, an empty token stream represents an invalid token stream.

2.2. Token stream reference

A token stream reference (also simply called reference) is a set of CSS tokens used in a value expression to reference a token stream called the provided value.

Optionally, a reference can provide a second token stream called the fallback value for the cases where the referenced token stream is invalid. When no fallback value is provided, the fallback value is invalid.

The final value of a reference is either equal to its provided value (if it's valid) or its fallback value (otherwise), eventually after a type conversion (see next section). The final value of a reference must be invalid if both its provided and its fallback value are invalid.

An expression is invalid if contains any reference whose final value is invalid.

The exact syntax and the set of conditions in which a reference can be used are defined in the Chapter 3 of this specification.

2.3. Reference types

A reference can also provide a particular reference type which will effectively constrain the set of values it will accept by providing a value converter. 

The <reference-type> type match any of the following identifiers (‘value’, ‘color’, ‘length’, ‘number’, ‘integer’, ‘angle’, ‘time’, ‘frequency’ or the name of any type defined in a CSS specification). When those values are used, the provided and the fallback value must be valid representations of the type of the given name to be recognized. No conversion is performed to compute the final value, assuming it's valid.

The <reference-type> type also match any of the following identifiers (‘px’, ‘em’, ‘vw’, ‘rad’, ‘s’, ‘Hz’, ‘dpi’ or the name of any unit defined in a CSS specification). When those values are used, the provided and the fallback value must be valid numbers to be recognized. The final value is defined as a dimension whose value is given by the uncomputed final value and whose unit is given by the reference type.

A value is valid according to a reference type if it's recognized by the value converter defined for this type.

2.4. Custom property

This specification defines an open-ended set of properties called custom properties. Custom properties are author-defined properties which do not have any direct impact on the document rendering or behavior but can be used indirectly (by reference) as values in other CSS properties.

Name: x-*
Values: <value>
Initial: (an empty token stream, see prose)
Applies To: all elements
Inherited: yes
Computed Value: strictly equal to the resolved value (CSS-wide keywords aren't replaced)
Media: all

The <value> type used in the syntax above is defined as anything matching the "value" production in CSS 2.1 Chapter 4.1 [CSS21].

This puts only a few restrictions on what kinds of values you can store in custom properties. Obviously, any valid property value or component of a property is allowed. Additionally, it allows things that are not yet valid CSS values, like unknown keywords or functions, blocks, at-rules, and other kinds of custom micro-syntax (for example, what is allowed in calc()).

Still, as the production has to be valid CSS, some restrictions apply.

For example, unbalanced parentheses are always invalid.

The term custom property refers to any property whose name is composed of a "x-" prefix followed by something matching the IDENT production in CSS2.1 Chapter 4.

The initial value of a custom property is empty (doesn't contain any token). This means that, until a custom property is explicitly defined in a stylesheet of the document, it defines an invalid token stream.

Custom properties are defined to be valid but meaningless as they are meant solely for allowing authors to define and use custom styling data, similarly to how the custom data attributes are used in HTML. Other specifications and user agents must not assign a particular meaning to custom properties or attach a specific effect to them beyond the bare minimum that comes from them being valid properties.

This style rule:

:root {
    x-header-color: #06c;
}

declares a custom property named "x-header-color" on the root element, and assigns to it the value "#06c". This property is then inherited to the elements in the rest of the document. Its value can be referenced via an appropriate:

h1 { color: get(x-header-color); }

The preceding rule is equivalent to writing ‘color: #06c;’, except that the name makes the origin of the color clearer, and if ‘get(x-header-color)’ is used on other elements in the document, all of the uses can be updated at once by changing the ‘x-header-color’ property on the root element (since all are descendants of :root).

This change can happen after the document is already loaded, for example in reaction to a media query change, as the user selects an alternate style sheet or as a result of an action performed in script.

Custom properties are ordinary properties, so they can be declared on any element and are resolved with the normal inheritance and cascade rules. They can also be used in HTML's style attribute and be read or modified using the usual CSSOM methods.

If a custom property is declared multiple times, the standard cascade rules help resolve it. Property references always draw from the computed value of the associated custom property on the same element:

:root  { x-color: blue; }
div    { x-color: green; }
#alert { x-color: red; }
* { color: get(x-color); } <p>I inherited blue from the root element!</p> <div>I got green set directly on me!</div> <div id='alert'> While I got red set directly on me! <p>I'm red too, because of inheritance!</p> </div>

2.5. Expression resolution algorithm

Just before an expression is being computed (just after the cascade phase in the case of property value expressions), the references it contains must be resolved.

The value of a property after this phase is called the resolved value.

It is important to note that custom properties resolve any token stream reference their value before the computed-value time. As such, an inherited value doesn't contain any reference.

Resolving an expression is the process of substituting the references it contains by their final value, and continuing until the resulting expression doesn't contain any reference.

It's to be noted that the provided value of a reference must be invalid if computing its provided value would cause the resolution algorithm to enter in a loop (its fallback value must be used instead). This behavior is known as the cyclic dependency resolution.

In general, cyclic dependencies occur only when multiple custom properties on the same element refer to each other; custom properties defined on elements higher in the element tree can never cause a cyclic reference with properties defined on elements lower in the element tree.

A JavaScript implementation of this algorithm can be found on the www-style mailing list.

This example shows a custom property safely using a property reference:

:root {
    x-main-color: #c06;
    x-accent-background: linear-gradient(to top, get(x-main-color), white);
}

The ‘x-accent-background’ property (along with any other properties that directly or indirectly references ‘x-main-color’) will be automatically updated when the ‘x-main-color’ property is changed.

On the other hand, this example shows an invalid instance of custom properties depending on each other:

:root {
    x-a: calc(get(x-b) + 20px);
    x-b: calc(get(x-a) - 20px);
}

Both ‘x-one’ and ‘x-two’ now define invalid token streams rather than lengths.

For example, given the following structure, these custom properties are not cyclic, and all define valid token streams:

<one><two><three /></two></one>
one   { x-foo: 10px; }
two   { x-bar: calc(get(x-foo) + 10px); }
three { x-foo: calc(get(x-bar) + 10px); }

The <one> element defines a value for ‘x-foo’.

The <two> element inherits this value, and additionally assigns a value to ‘x-bar’ by referencing <one>'s ‘x-foo’ property.

Finally, the <three> element inherits the ‘x-bar’ value after token stream substitution (in other words, it sees the value ‘calc(10px + 10px)’), and then redefines ‘x-foo’ in terms of that value.

Since the value it inherited for ‘x-bar’ no longer contains a reference to the ‘x-foo’ property defined on <one>, defining ‘x-foo’ using ‘get(x-bar)’ is not cyclic, and actually defines a value that will eventually (when referenced as a token stream in a normal property) resolve to ‘30px’.

This example shows how fallback value help resolve cyclic dependencies:

:root {
    x-a: get(x-b || 0px);
    x-b: get(x-a);
}

Both ‘x-one’ and ‘x-two’ now have 0px as their computed value.

This example shows how over-constrained fallback values help resolve cyclic dependencies:

:root {
    x-a: get(x-b || 0px);
    x-b: get(x-a || 1px);
}
The ‘x-one’ property computes to 1px and ‘x-two’ to 0px. The fallback value which is located the closest to the cyclic dependency initiator is actually the one that get used, hence the 'inversion'.

Authors should not depend on the cyclic dependencies and their resolution in their style sheets if there's an alternative way to get the same result that doesn't trigger this algorithm.

2.6. Property reference

A property reference is a reference whose provided value depends on the value of a custom property located on an element or pseudo-element of the styled document.

The CSS Custom Properties editors would like to lift the 'custom property' restriction here.

This is the reason why we require the 'x-' prefix to be typed in the property references defined in this specification. Otherwise, it would make inconsistent of difficult its extension to all properties.

If the referenced property doesn't exists, the provided value of the property reference is invalid.

How the property is referenced, on which element it is referenced and which value is going to be used has to be defined for each type of property reference.

3. Syntax and implementations

3.1. General syntax of a reference

When used as or in a value production, some functional notations represent a token stream reference. The general syntax of a reference is the following one :

<ref> = "get" ( <reference-path> [ "|" <reference-type> [ "|" <value> ]? ]? )

...where <reference-path> represent anything matching the IDENT+ production in CSS2.1 Chapter 4.

The second (and optional) argument of the function is its type declaration.

The third (and optional) argument of the function is its fallback value.

In this informative example, the syntax of an hypothetical token stream reference is explained.

p { property: get( foo bar || fallback value ); }

The 'foo' token represents the provider of the reference.
The 'bar' token represents the name of the referenced token stream.
The 'fallback value' tokens represent the fallback token stream of the reference.

If the referenced token stream contained the 'value' token, the previous declaration is equivalent to:

p { property: value; }

If the referenced token stream is invalid, the previous declaration is equivalent to:

p { property: fallback value; }

At resolution time, token stream references are substituted for their final value if it is invalid (otherwise, the declaration is marked invalid at resolution time).

3.2. References as a value

A reference can be used as a substitute to any part of a value, in any expression, to the condition that the resulting expression is valid at declaration time according to the rules defined beneath:

This specification doesn't define a way to use references anywhere else. An UA conforming to this specification and CSS 2.1 should not accept token stream references in property names, selectors, or anywhere else besides property values and media queries arguments - doing so either produces either an invalid value or a valid value that nonetheless has no relation to the reference.

If the fallback value of a reference is not a valid instance of its reference type, the declaration that contains the reference is invalid at declaration time (and should therefore be ignored).

For example, the following usage of a property reference is fine from when the token stream reference is substituted in but invalid at declaration time :

:root { x-color: blue; }
p { background-color: get(x-color | color | 20px); }

Since the fallback value (‘20px’) is not a valid color, the previous declaration is ignored.

An expression containing references is also invalid at declaration time if, when all references it contains providing a fallback value have been replaced by their fallback value, it's impossible to find any valid value for the remaining references that can make the resulting expression valid where it is used.

Given the following CSS file, a conforming user agent should display each matching DIV element with a white text over a green background.

div {
x-background-color: green;
x-foreground-color: white;
x-secondary-color: red;

color: get(x-foreground-color); // valid
color: get(x-secondary-color || 10px); // invalid

background-color: yellow; // valid (overridden)
background-color: get(x-background-color || blue); // valid

outline-color: get(x-a) get(x-b); // invalid (<color> has one token)
}

The rationale behind this restriction is to allow proper fallback for unsupported features.

.selector {
background: get(x-bg-color);
background: get(x-super-cool-bg || unsupported-feature(...));
}

The second declaration of the 'background' property will probably be discarded by the user agent because it doesn't understand the 'unsupported-feature()' function. In this case, the background will use the 'x-bg-color' custom property value.

If a syntactically valid expression becomes invalid once all references are substituted in by their final value, then the expression is said invalid at resolution time

For example, the following usage of a property reference is fine from a syntax standpoint, but results in nonsense when the token stream reference is substituted in:

:root { x-length: 20px; }
p { background-color: get(x-length); }

Since ‘20px’ is an invalid value for ‘background-color’, this instance of the property computes to ‘transparent’ (the initial value for ‘background-color’) instead.

3.3. Invalid References

The ‘get()’ functional notation is an instance of reference if its reference path contains only one identifier, and that this identifier is ‘invalid’, or if the reference path doesn't match any supported reference path format.

The provided value of the invalid reference is empty and invalid.

3.4. Direct Property References

The ‘get()’ functional notation is an instance of property reference if its reference path contains only one identifier, and that this identifier is not ‘invalid’.

The referenced property of the ‘get(property)’ notation is the property applied on the matched element whose name match the last token of its reference path.

The provided value of the ‘get(property)’ notation is either the cascaded value of the referenced property if is is declared on the element, or its inherited/initial value otherwise (depending of whether that property was inherited or not).

Properties whose value is inherited are also valid target, even if they are not specifically applying on the element. Without this, custom properties would not be useful.

For example, the following code defines and references a custom property named "x-main-color".

:root { 
    x-main-color: blue;
}

h1 { 
    color: get(x-main-color);
}

Shouldn't we add a get(local x-property) notation that would only be valid if the property is explicitly declared on the element, and would not take in consideration the inherited/initial value?

This could be useful for using some custom properties as if they were 'non-inherited'. The other option is to ask developers to declare * { x-property: get(invalid); } in their stylesheet to emulate the behavior the x-property would have if it was 'non-inherited'.

3.5. Parent Property References

Several advanced use-cases for custom properties need the ability to reference the value that a property has on the parent element, rather than on the element itself. This can be accomplished with the ‘get(parent property)’ notation.

It's to be noted that

property: get(parent property)

and

property: inherit

are functionally identical.


    

The ‘get()’ functional notation is an instance of property reference if its reference path contains two tokens whose first one is 'parent'. 

The referenced property of the ‘get(parent property)’ notation is the property applied on the parent of the matched element whose name match the last token of its reference path.

The provided value of the ‘get(parent property)’ notation is the computed value of the referenced property.

Nested comments feature another colorFor example, ‘get(parent ...)’ can be used to implement a behavior that's very similar to the ‘toggle()’ notation from [[CSS3VALUES]].

In this example, each nested comment alternates between a white and silver background (as in the picture floating to the right).

<div class='comment'>
    <div class='main'>
        ...
    </div>
    <div class='actions'><a>Reply</a> <a>Comment</a> ...</div>
</div>
<div class='comment'>
    <div class='main'>
        <div class='comment'>
            <div class='main'>
                ...
            </div>
            <div class='actions'><a>Reply</a> <a>Comment</a> ...</div>
        </div>
    </div>
    <div class='actions'><a>reply</a> <a>Comment</a> ...</div>
</div>
<style>
.comment { x-bg1: get(parent x-bg2, white); x-bg2: get(parent x-bg1, silver); background: get(x-bg1); }
</style>

The ‘toggle()’ notation can't be used here, because ‘background-color’ isn't inherited (and thus the nested comments see the initial value of ‘transparent’ rather than ‘white’ or ‘silver’). Even if the author explicitly sets ‘background-color:inherit’ on <div class='main'> so that ‘toggle()’ can actually see the right value, that will make the ".main" elements cover up the ‘background-image’ that ".comment" has on it as well.

Because custom properties don't have any effect on rendering until they're used, they can pass these values through the document without these kinds of side effects.

The ‘get(property)’ notation can't be used here either as it would immediately produce a cycle between 'x-bg' and 'x-bg2', making them both invalid.

37. Document Property references

This section is not normative (because it lacks any content for now).

The idea here is to allow to obtain some document properties like its title or its URL to be used, for example, in the header and footer of printed documents.

3.7. Attribute references

This section is not normative (because it lacks any content for now).

The idea here is to replace the attribute references currently defined in CSS Values and Units but not implemented by any user agent at the time of writing.

3.8. Counter references

This section is not normative (because it lacks any content for now).

The idea here is to allow to obtain the numeric value of a counter to be used in calculations. There has been some discussion on the list recently on the subject, and the result of the discussion was that it's actually impossible to use counters to that purpose (because counters depend on 'display: none'). However, it would possible to define something like an 'indexer' to accomplish the same goal (but an indexer would only rely on the DOM).

3.9. Using invalid references

A property can become invalid at resolution time if its resolved value is invalid according to the property syntax. When this happens, the computed value of the property is either the property's inherited value or its initial value depending on whether the property is inherited or not, respectively.

For example, in the following code:

:root { x-bad-color: 20px; }
p { background-color: red; }
p { background-color: get(x-bad-color); }

the <p> elements will have transparent backgrounds (the initial value for ‘background-color’), rather than red backgrounds. 

Please note the difference between the present behavior and what happens if the author had just written ‘background-color: 20px’ directly in its stylesheet: that would be a normal syntax error, which would cause the rule to be discarded. In that case, the ‘background-color: red’ rule would have been used instead.

The invalid at resolution time concept exists because references can't "fail early" like other syntax errors can. By the time the user agent realizes that a property value is invalid, it already threw away the other cascaded values.

4. CSSOM

Custom properties are ordinary properties, and can be read or modified using all of the existing CSSOM APIs for reading or modifying properties.

The specification extends the IDL definitions in the CSSOM spec to represent the use of the ‘get()’ function.

4.1. Interface CSSTokenStreamReference

The CSSTokenStreamReference interface represents an use of property token stream.

IDL Definition
[NoInterfaceObject] interface CSSTokenStreamReference {
           attribute DOMString referencePath; 
attribute DOMString referenceType; attribute DOMString fallbackValue; readonly attribute DOMString providedValue;
readonly attribute DOMString finalValue; }
Attributes
referencePath of type DOMString
This attribute represents the first argument of the ‘get()’ function. Changing this attribute changes the token stream being referred to. If this property is set to a value that don't match the <reference-path>, it is set to ‘invalid’ instead.
referenceType of type DOMString
This attribute represents the second argument of the ‘get()’ function. Changing this attribute changes the conversion algorithm used to parse the value of the reference. If this property is set to a value that don't match the <reference-type>, it is set to ‘any’ instead.
fallbackValue of type DOMString
This attribute represents the second argument to the function. Changing this attribute changes the fallback value used as a replacement of the provided value whenever it is invalid. If this property is set to a value that don't match the <value> type, it is set to an empty string instead.
providedValue of type DOMString, readonly
This attribute represents the value provided by the referenced token stream. If the provided value is invalid at the time it's retrieved, the value of this attribute must be null.
finalValue of type DOMString, readonly
This attribute represents the final value used as a substitution for the reference. It's equal to the provided value unless it's equal to null. In such case, if the fallback value is valid, it should be returned instead. Otherwhise, the value of this attribute must be null.

4.2. Additions to the CSSStyleDeclaration Interface

The set of custom properties is open-ended, so it is not clear how best to represent this. Ideally, the CSSOM would expose the current set of properties with a non-initial value and allow setting of arbitrary properties.

The most natural way seems to be to set up a getter behavior on the interface somehow that deals with custom properties as well as a 'x' map that exposes the custom properties that aren't set to their initial value.

document.body.style.x.property === document.body.style['x-property']

5. Conformance

5.1. Document Conventions

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.

All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. [RFC2119]

Examples in this specification are introduced with the words “for example” or are set apart from the normative text with class="example", like this:

This is an example of an informative example.

Informative notes begin with the word “Note” and are set apart from the normative text with class="note", like this:

Note, this is an informative note.

5.2. Conformance Classes

Conformance to CSS Custom Properties is defined for three conformance classes:

style sheet
A CSS style sheet.
renderer
A UA that interprets the semantics of a style sheet and renders documents that use them.
authoring tool
A UA that writes a style sheet.

A style sheet is conformant to CSS Custom Properties if all of its declarations that use properties defined in this module have values that are valid according to the generic CSS grammar and the individual grammars of each property as given in this module.

A renderer is conformant to CSS Custom Properties if, in addition to interpreting the style sheet as defined by the appropriate specifications, it supports all the features defined by CSS Custom Properties by parsing them correctly and rendering the document accordingly. However, the inability of a UA to correctly render a document due to limitations of the device does not make the UA non-conformant. (For example, a UA is not required to render color on a monochrome monitor.)

An authoring tool is conformant to CSS Custom Properties Module if it writes style sheets that are syntactically correct according to the generic CSS grammar and the individual grammars of each feature in this module, and meet all other conformance requirements of style sheets as described in this module.

5.3. Partial Implementations

So that authors can exploit the forward-compatible parsing rules to assign fallback values, CSS renderers must treat as invalid (and ignore as appropriate) any at-rules, properties, property values, keywords, and other syntactic constructs for which they have no usable level of support. In particular, user agents must not selectively ignore unsupported component values and honor supported values in a single multi-value property declaration: if any value is considered invalid (as unsupported values must be), CSS requires that the entire declaration be ignored.

5.4. Experimental Implementations

To avoid clashes with future CSS features, the CSS2.1 specification reserves a prefixed syntax for proprietary and experimental extensions to CSS.

Prior to a specification reaching the Candidate Recommendation stage in the W3C process, all implementations of a CSS feature are considered experimental. The CSS Working Group recommends that implementations use a vendor-prefixed syntax for such features, including those in W3C Working Drafts. This avoids incompatibilities with future changes in the draft.

5.5. Non-Experimental Implementations

Once a specification reaches the Candidate Recommendation stage, non-experimental implementations are possible, and implementors should release an unprefixed implementation of any CR-level feature they can demonstrate to be correctly implemented according to spec.

To establish and maintain the interoperability of CSS across implementations, the CSS Working Group requests that non-experimental CSS renderers submit an implementation report (and, if necessary, the testcases used for that implementation report) to the W3C before releasing an unprefixed implementation of any CSS features. Testcases submitted to W3C are subject to review and correction by the CSS Working Group.

Further information on submitting testcases and implementation reports can be found from on the CSS Working Group's website at http://www.w3.org/Style/CSS/Test/. Questions should be directed to the public-css-testsuite@w3.org mailing list.

5.6. CR Exit Criteria

For this specification to be advanced to Proposed Recommendation, there must be at least two independent, interoperable implementations of each feature. Each feature may be implemented by a different set of products, there is no requirement that all features be implemented by a single product. For the purposes of this criterion, we define the following terms:

independent
each implementation must be developed by a different party and cannot share, reuse, or derive from code used by another qualifying implementation. Sections of code that have no bearing on the implementation of this specification are exempt from this requirement.
interoperable
passing the respective test case(s) in the official CSS test suite, or, if the implementation is not a Web browser, an equivalent test. Every relevant test in the test suite should have an equivalent test created if such a user agent (UA) is to be used to claim interoperability. In addition if such a UA is to be used to claim interoperability, then there must one or more additional UAs which can also pass those equivalent tests in the same way for the purpose of interoperability. The equivalent tests must be made publicly available for the purposes of peer review.
implementation
a user agent which:
  1. implements the specification.
  2. is available to the general public. The implementation may be a shipping product or other publicly available version (i.e., beta version, preview release, or “nightly build”). Non-shipping product releases must have implemented the feature(s) for a period of at least one month in order to demonstrate stability.
  3. is not experimental (i.e., a version specifically designed to pass the test suite and is not intended for normal usage going forward).

The specification will remain Candidate Recommendation for at least six months.

Acknowledgments

Thanks to Daniel Glazman and Dave Hyatt for writing the original Variables draft in 2008. Thanks to many WG members for keeping the idea of variables alive through the years. Thanks to Roland Steiner and Shane Stephens for invaluable feedback and implementation experience.Thanks also to all the persons who contributed to this draft via www-style or any other mean.

References

Normative references

[CSS21]
Bert Bos; et al. Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification. 7 June 2011. W3C Recommendation. URL: http://www.w3.org/TR/2011/REC-CSS2-20110607
[RFC2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. Internet RFC 2119. URL: http://www.ietf.org/rfc/rfc2119.txt

Other references

[CSS1]
Håkon Wium Lie; Bert Bos. Cascading Style Sheets (CSS1) Level 1 Specification. 11 April 2008. W3C Recommendation. URL: http://www.w3.org/TR/2008/REC-CSS1-20080411
[CSS3-SYNTAX]
L. David Baron. CSS Syntax Module Level 3. 13 August 2003. W3C Working Draft. URL: http://www.w3.org/TR/css3-syntax/
[CSS3COLOR]
Tantek Çelik; Chris Lilley; L. David Baron. CSS Color Module Level 3. 7 June 2011. W3C Recommendation. URL: http://www.w3.org/TR/2011/REC-css3-color-20110607

Index

Property index

Property Values Initial Applies to Inh. Computed value Media
x-* <value> (nothing, see prose) all elements yes strictly equal to the resolved value
all