@@ -137,22 +137,17 @@ <h2 class="no-num no-toc" id=contents>Table of contents</h2>
137137 </ ul >
138138
139139 < li > < a href ="#defining-variables "> < span class =secno > 2. </ span > Defining
140- Variables With Custom Properties</ a >
140+ Custom Properties: the ‘< code class =css > var-*</ code > ’ family of
141+ properties</ a >
141142
142143 < li > < a href ="#using-variables "> < span class =secno > 3. </ span > Using
143- Variables</ a >
144+ Variables - the ‘ < code class = css > var() </ code > ’ notation </ a >
144145 < ul class =toc >
145- < li > < a href ="#var-glyph "> < span class =secno > 3.1. </ span > The $ Prefix</ a >
146-
147-
148- < li > < a href ="#var-function "> < span class =secno > 3.2. </ span > Default
149- Values - the ‘< code class =css > var()</ code > ’ notation</ a >
150-
151- < li > < a href ="#parent-var-notation "> < span class =secno > 3.3. </ span >
146+ < li > < a href ="#parent-var-notation "> < span class =secno > 3.1. </ span >
152147 Getting the Parent's Variable - the ‘< code
153148 class =css > parent-var()</ code > ’ notation</ a >
154149
155- < li > < a href ="#using-invalid-variables "> < span class =secno > 3.4 . </ span >
150+ < li > < a href ="#using-invalid-variables "> < span class =secno > 3.2 . </ span >
156151 Using Invalid Variables</ a >
157152 </ ul >
158153
@@ -245,8 +240,9 @@ <h3 id=values><span class=secno>1.2. </span> Values</h3>
245240 when combined with this module, expands the definition of the
246241 <color> value type as used in this specification.
247242
248- < h2 id =defining-variables > < span class =secno > 2. </ span > Defining Variables
249- With Custom Properties</ h2 >
243+ < h2 id =defining-variables > < span class =secno > 2. </ span > Defining Custom
244+ Properties: the ‘< a href ="#var- "> < code class =css > var-*</ code > </ a > ’
245+ family of properties</ h2 >
250246
251247 < p > This specification defines an open-ended set of properties called < a
252248 href ="#custom-property "> < i > custom properties</ i > </ a > , which are used to
@@ -262,7 +258,7 @@ <h2 id=defining-variables><span class=secno>2. </span> Defining Variables
262258 < tr >
263259 < th > Values:
264260
265- < td > < a href =" #value-type " > < var > <value> </ var > </ a >
261+ < td > < var > <value> </ var >
266262
267263 < tr >
268264 < th > Initial:
@@ -291,54 +287,53 @@ <h2 id=defining-variables><span class=secno>2. </span> Defining Variables
291287 < td > all
292288 </ table >
293289
294- < p > The < dfn id =value-type > < var > <value> </ var > </ dfn > type used in the
295- syntax above is defined as anything matching the "value" production in < a
296- href ="http://www.w3.org/TR/CSS2/syndata.html#tokenization "> CSS 2.1 Chapter
297- 4.1</ a > < a href ="#CSS21 " rel =biblioentry > [CSS21]<!--{{!CSS21}}--> </ a > .
298- This puts almost no restrictions on what kinds of values you can store in
299- variables. Obviously, any valid property value or component of a property
300- is allowed. Additionally, this allows things that aren't yet valid CSS,
301- like unknown keywords or functions, blocks, at-rules, and other kinds of
302- custom micro-syntaxes like what's allowed in calc(). There < em > are</ em >
303- still rules, however; for example, unbalanced parentheses are invalid.
304-
305- < p > The term < dfn id =custom-property
306- title ="custom property|custom properties "> custom property</ dfn > refers to
307- any property whose name is composed of a "var-" prefix followed by
308- something matching the IDENT production in < a
309- href ="http://www.w3.org/TR/CSS2/syndata.html#tokenization "> CSS2.1 Chapter
310- 4</ a > . A < a href ="#custom-property "> < i > custom property</ i > </ a > defines a
311- value for a corresponding < a href ="#variable "> < i > variable</ i > </ a > with the
312- same name as the property except that the "var-" prefix is replaced with a
313- "$" prefix.
314-
315- < p > The initial value of a < a href ="#custom-property "> < i > custom
316- property</ i > </ a > is an empty invalid value. This means that, until a < a
317- href ="#custom-property "> < i > custom property</ i > </ a > is explicitly defined
318- otherwise by a style sheet, it defines an < a
319- href ="#invalid-variable "> < i > invalid variable</ i > </ a >
320-
321- < p class =issue > As defined here, the syntax for variable usage is different
322- from the syntax for variable definition (i.e. var-foo for definition, $foo
323- for usage). It might be nice to have the syntaxes match, using "$foo" as
324- the property name as well. This would require a minor change in the Core
325- Grammar.
326-
327- < p > < a href ="#custom-property "> < i > Custom properties</ i > </ a > are defined to
328- be valid but meaningless as they are meant solely for allowing authors to
329- pass custom data around their page, similar to the < a
330- href ="http://www.w3.org/TR/html5/global-attributes.html#embedding-custom-non-visible-data-with-the-data-attributes "> custom
331- data attributes</ a > in HTML. Other specifications and user agents must not
332- assign a particular meaning to < a href ="#custom-property "> < i > custom
333- properties</ i > </ a > or attach a specific effect to them beyond the bare
334- minimum that comes from them being valid properties.
335-
336- < p > For each < a href ="#custom-property "> < i > custom property</ i > </ a > , there
337- is an associated variable with the same name save for the "var-" prefix.
338- For example, a custom property named "var-foo" is associated with the
339- variable named "foo". See the next chapter for details on how to use
290+ < p > A < dfn id =custom-property
291+ title ="custom property|custom properties "> custom property</ dfn > is any
292+ property whose name is composed of "var-" followed by an
293+ < code > <ident> </ code > < a href ="#CSS3VAL "
294+ rel =biblioentry > [CSS3VAL]<!--{{!CSS3VAL}}--> </ a > < a
295+ href ="#custom-property "> < i > Custom properties</ i > </ a > are solely for use by
296+ authors and users; CSS will never give them a meaning beyond what is
297+ presented here.
298+
299+ < p > < a href ="#custom-property "> < i > Custom properties</ i > </ a > have an
300+ extremely permissive value grammar, defined as the "value" production in
301+ < a href ="http://www.w3.org/TR/CSS2/syndata.html#tokenization "> CSS 2.1
302+ Chapter 4.1</ a > < a href ="#CSS21 "
303+ rel =biblioentry > [CSS21]<!--{{!CSS21}}--> </ a > . This implies that any valid
304+ CSS value can be used, but it's much wider than that. Roughly, anything
305+ can be used except for unclosed quotes, parens, braces, or square
306+ brackets, or any character that would normally end a declaration (a
307+ top-level semicolon or close brace).
308+
309+ < p > There are an infinity of < a href ="#custom-property "> < i > custom
310+ properties</ i > </ a > , but the initial value of a < a
311+ href ="#custom-property "> < i > custom property</ i > </ a > is an empty invalid
312+ value. This means that, until a < a href ="#custom-property "> < i > custom
313+ property</ i > </ a > is explicitly defined otherwise by a style sheet, it
314+ defines an < a href ="#invalid-variable "> < i > invalid variable</ i > </ a > .
315+
316+ < p > The primary purpose of < a href ="#custom-property "> < i > custom
317+ properties</ i > </ a > is to define < a href ="#variable "> < i > variables</ i > </ a > .
318+ In CSS, a < dfn id =variable > variable</ dfn > is a value that can be
319+ substituted into other properties, allowing authors to "abstract" parts of
320+ their page's CSS out. Every < a href ="#custom-property "> < i > custom
321+ property</ i > </ a > defines a corresponding < a
322+ href ="#variable "> < i > variable</ i > </ a > with the same name, minus the "var-"
323+ prefix. For example, the custom property ‘< code
324+ class =property > var-foo</ code > ’ defines a variable named ‘< code
325+ class =css > foo</ code > ’. See the next chapter for details on how to use
340326 variables.
341327
328+ < p > < a href ="#custom-property "> < i > Custom properties</ i > </ a > can be put to
329+ several other uses, of course. For example, they can be used to
330+ conveniently attach values to elements so that JavaScript can later use
331+ those values. Another example is providing "custom CSS" by treating "var-"
332+ as a kind of "author prefix" (similar to a vendor prefix) that allows an
333+ author to write custom CSS properties without having them thrown away as
334+ invalid by the CSS parser, and then having JavaScript come along afterward
335+ to actually implement the functionality.
336+
342337 < div class =example >
343338 < p > This style rule:
344339
@@ -363,7 +358,7 @@ <h2 id=defining-variables><span class=secno>2. </span> Defining Variables
363358 class =property > var-header-color</ code > ’ property on the root element.
364359 </ div >
365360
366- < p > custom properties are ordinary properties, so they can be declared on
361+ < p > Custom properties are ordinary properties, so they can be declared on
367362 any element, are resolved with the normal inheritance and cascade rules,
368363 can be made conditional with ‘< code class =css > @media</ code > ’ and other
369364 conditional rules, can be used in HTML's < code > style</ code > attribute, can
@@ -490,14 +485,13 @@ <h2 id=defining-variables><span class=secno>2. </span> Defining Variables
490485 gggggg
491486-->
492487
493- < h2 id =using-variables > < span class =secno > 3. </ span > Using Variables</ h2 >
488+ < h2 id =using-variables > < span class =secno > 3. </ span > Using Variables - the
489+ ‘< code class =css > var()</ code > ’ notation</ h2 >
494490
495- < p > A < dfn id =variable > variable</ dfn > allows the value of a < a
496- href ="#custom-property "> < i > custom property</ i > </ a > on an element to be
497- substituted into another property on the element. There are several ways
498- to use variables: by name, via the ‘< code class =css > var()</ code > ’
499- notation, or via the ‘< code class =css > parent-var()</ code > ’ notation to
500- get at a variable on the element's parent.
491+ < p > A < a href ="#custom-property "> < i > custom property</ i > </ a > automatically
492+ defines The value of a < a href ="#custom-property "> < i > custom
493+ property</ i > </ a > on an element can be substituted into another property
494+ using the ‘< code class =css > var()</ code > ’ function.
501495
502496 < p > A variable can be used in place of any component value in any property
503497 on an element. Variables can not be used as property names, selectors, or
@@ -527,36 +521,6 @@ <h2 id=using-variables><span class=secno>3. </span> Using Variables</h2>
527521 instead.
528522 </ div >
529523
530- < h3 id =var-glyph > < span class =secno > 3.1. </ span > The $ Prefix</ h3 >
531-
532- < p > The simplest way to use a variable is to refer to it by its name, which
533- is the same as the < a href ="#custom-property "> < i > custom property</ i > </ a >
534- defining it, except with the "var-" prefix swapped out for a "$" prefix.
535- Formally, the syntax of a variable is:
536-
537- < pre > < dfn id =type-var > <var> </ dfn > = "$" < var > IDENT</ var > </ pre >
538-
539- < p > ...where < var > IDENT</ var > is anything matching the IDENT production in
540- < a href ="http://www.w3.org/TR/CSS2/syndata.html#tokenization "> CSS2.1
541- Chapter 4</ a > .
542-
543- < div class =example >
544- < p > For example, the following code defines and uses a variable named
545- "main-color".
546-
547- < pre >
548- :root {
549- var-main-color: blue;
550- }
551-
552- h1 {
553- color: $main-color;
554- }</ pre >
555- </ div >
556-
557- < h3 id =var-function > < span class =secno > 3.2. </ span > Default Values - the
558- ‘< code class =css > var()</ code > ’ notation</ h3 >
559-
560524 < p > In some cases, it can be useful to provide a "default" value for a
561525 variable in case the variable isn't defined or is invalid.
562526
@@ -570,9 +534,8 @@ <h3 id=var-function><span class=secno>3.2. </span> Default Values - the
570534 to be specified when referencing a variable. The syntax of ‘< code
571535 class =css > var()</ code > ’ is:
572536
573- < pre > < dfn id =default-var-type > <default-var> </ dfn > = var( < a
574- href ="#type-var "> < var > <var> </ var > </ a > [, < a
575- href ="#value-type "> < var > <value> </ var > </ a > ]? )</ pre >
537+ < pre > < dfn
538+ id =default-var-type > <default-var> </ dfn > = var( < var > <var> </ var > [, < var > <value> </ var > ]? )</ pre >
576539
577540 < p > If the variable named by the first argument is valid, the variable's
578541 value is substituted as normal. If it's invalid, and a second argument was
@@ -586,7 +549,7 @@ <h3 id=var-function><span class=secno>3.2. </span> Default Values - the
586549 which < em > does</ em > do something useful with only one argument. Future
587550 variable functions will likely be similar.
588551
589- < h3 id =parent-var-notation > < span class =secno > 3.3 . </ span > Getting the
552+ < h3 id =parent-var-notation > < span class =secno > 3.1 . </ span > Getting the
590553 Parent's Variable - the ‘< code class =css > parent-var()</ code > ’ notation</ h3 >
591554
592555 < p > Several advanced use-cases for variables need the ability to reference
@@ -595,9 +558,7 @@ <h3 id=parent-var-notation><span class=secno>3.3. </span> Getting the
595558 class =css > parent-var()</ code > ’ notation:
596559
597560 < pre > < dfn
598- id =parent-var-notation-type > <parent-var> </ dfn > = parent-var( < a
599- href ="#type-var "> < var > <var> </ var > </ a > [, < a
600- href ="#value-type "> < var > <value> </ var > </ a > ]? )</ pre >
561+ id =parent-var-notation-type > <parent-var> </ dfn > = parent-var( < var > <var> </ var > [, < var > <value> </ var > ]? )</ pre >
601562
602563 < p > If the element has a parent, and the variable named by the first
603564 argument is valid on the parent, the variable's value on the parent is
@@ -658,7 +619,7 @@ <h3 id=parent-var-notation><span class=secno>3.3. </span> Getting the
658619 making them both invalid.
659620 </ div >
660621
661- < h3 id =using-invalid-variables > < span class =secno > 3.4 . </ span > Using Invalid
622+ < h3 id =using-invalid-variables > < span class =secno > 3.2 . </ span > Using Invalid
662623 Variables</ h3 >
663624
664625 < p > When a < a href ="#custom-property "> < i > custom property</ i > </ a > has its
@@ -956,6 +917,16 @@ <h3 class=no-num id=normative-references>Normative references</h3>
956917 </ dd >
957918 <!---->
958919
920+ < dt id =CSS3VAL > [CSS3VAL]
921+
922+ < dd > Håkon Wium Lie; Tab Atkins; Elika J. Etemad. < a
923+ href ="http://www.w3.org/TR/2012/WD-css3-values-20120308/ "> < cite > CSS
924+ Values and Units Module Level 3.</ cite > </ a > 8 March 2012. W3C Working
925+ Draft. (Work in progress.) URL: < a
926+ href ="http://www.w3.org/TR/2012/WD-css3-values-20120308/ "> http://www.w3.org/TR/2012/WD-css3-values-20120308/</ a >
927+ </ dd >
928+ <!---->
929+
959930 < dt id =RFC2119 > [RFC2119]
960931
961932 < dd > S. Bradner. < a href ="http://www.ietf.org/rfc/rfc2119.txt "> < cite > Key
@@ -1010,17 +981,17 @@ <h2 class=no-num id=index>Index</h2>
1010981 title ="custom property "> < strong > 2.</ strong > </ a >
1011982
1012983 < li > <default-var> , < a href ="#default-var-type "
1013- title ="<default-var> "> < strong > 3.2. </ strong > </ a >
984+ title ="<default-var> "> < strong > 3.</ strong > </ a >
1014985
1015986 < li > invalid at computed-value time, < a
1016987 href ="#invalid-at-computed-value-time "
1017- title ="invalid at computed-value time "> < strong > 3.4 .</ strong > </ a >
988+ title ="invalid at computed-value time "> < strong > 3.2 .</ strong > </ a >
1018989
1019990 < li > invalid variable, < a href ="#invalid-variable "
1020- title ="invalid variable "> < strong > 3.4 .</ strong > </ a >
991+ title ="invalid variable "> < strong > 3.2 .</ strong > </ a >
1021992
1022993 < li > <parent-var> , < a href ="#parent-var-notation-type "
1023- title ="<parent-var> "> < strong > 3.3 .</ strong > </ a >
994+ title ="<parent-var> "> < strong > 3.1 .</ strong > </ a >
1024995
1025996 < li > renderer, < a href ="#renderer " title =renderer > < strong > 5.2.</ strong > </ a >
1026997
@@ -1031,15 +1002,9 @@ <h2 class=no-num id=index>Index</h2>
10311002 title ="style sheet, as conformance class "> < strong > 5.2.</ strong > </ a >
10321003 </ ul >
10331004
1034- < li > < a href ="#value-type "> < var > <value> </ var > </ a > , < a href ="#value-type "
1035- title ="<value> "> < strong > 2.</ strong > </ a >
1036-
1037- < li > <var> , < a href ="#type-var "
1038- title ="<var> "> < strong > 3.1.</ strong > </ a >
1039-
10401005 < li > var-*, < a href ="#var- " title ="var-* "> < strong > 2.</ strong > </ a >
10411006
1042- < li > variable, < a href ="#variable " title =variable > < strong > 3 .</ strong > </ a >
1007+ < li > variable, < a href ="#variable " title =variable > < strong > 2 .</ strong > </ a >
10431008 </ ul >
10441009 <!--end-index-->
10451010
0 commit comments