-
Notifications
You must be signed in to change notification settings - Fork 792
Expand file tree
/
Copy pathOverview.src.html
More file actions
876 lines (725 loc) · 32.6 KB
/
Overview.src.html
File metadata and controls
876 lines (725 loc) · 32.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>CSS Variables Module Level 1</title>
<link rel="stylesheet" type="text/css" href="http://dev.w3.org/csswg/default.css">
<link rel="stylesheet" type="text/css" href="http://www.w3.org/StyleSheets/TR/W3C-[STATUS].css">
<style>
pre.idl { border:solid thin; background:#eee; color:#000; padding:0.5em }
pre.idl :link, pre.idl :visited { color:inherit; background:transparent }
i { font-style: normal; }
</style>
</head>
<div class="head">
<!--logo-->
<h1>CSS Variables Module Level 1</h1>
<h2 class="no-num no-toc">[LONGSTATUS] [DATE]</h2>
<dl>
<dt>This version:
<!--<dd><a href="http://www.w3.org/TR/[YEAR]/WD-css-variables-[CDATE]/">[VERSION]</a>-->
<dd><a href="http://dev.w3.org/csswg/[SHORTNAME]/">Editor's draft</a> (version of [DATE])
<dt>Latest version:
<dd><a href="http://www.w3.org/TR/[SHORTNAME]/">http://www.w3.org/TR/[SHORTNAME]/</a>
<dt>Editor's draft:
<dd><a href="http://dev.w3.org/csswg/css-variables/">http://dev.w3.org/csswg/css-variables/</a>
<dt>Editors:
<dd class="vcard"><span class="fn">Luke Macpherson</span>,
<span class="org">Google, Inc.</span>,
<span class="email">macpherson@google.com</span>
<dd class='vcard'>
<a href="http://xanthir.com/contact/" class='url'>
<span class='fn'>Tab Atkins Jr.</span>,
</a>
<span class=org>Google, Inc.</span>
<dd class='vcard'>
<span class='fn'>Daniel Glazman</span>,
<span class='org'>Disruptive Innovations</span>,
<span class='email'>daniel.glazman@disruptive-innovations.com</span>
</dl>
<!--copyright-->
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc" id="abstract">Abstract</h2>
<p>CSS is a language for describing the rendering of structured documents (such as HTML and XML) on screen, on paper, in speech, etc. This module contains the features of CSS level 3 relating to variables. It includes and extends the functionality of CSS level 2 [[!CSS21]], which builds on CSS level 1 [[CSS1]]. The main extensions compared to level 2 are the introduction of the variable as a new primitive value type that is accepted by all properties.
<h2 class="no-num no-toc" id="status">Status of this document</h2>
<!--status-->
<!--<p>The following features are at risk: …-->
<h2 class="no-num no-toc" id="contents">Table of contents</h2>
<!--toc-->
<h2 id="intro">
Introduction</h2>
<p><em>This section is not normative.</em>
<p>
Large documents or applications
(and even small ones)
can contain quite a bit of CSS.
Many of the values in the CSS file will be duplicate data;
for example,
a site may establish a color scheme
and reuse three or four colors throughout the site.
Altering this data can be difficult and error-prone,
since it's scattered throughout the CSS file
(and possibly across multiple files),
and may not be amenable to Find-and-Replace.
<p>
This module introduces a family of custom user-defined properties known collectively as <i>variable properties</i>,
which allow an author to assign arbitrary values to a property with an author-chosen name,
and <i>variables</i>,
which allow an author to then use those values in other properties elsewhere in the document.
This makes it easier to read large files,
as seemingly-arbitrary values now have informative names,
and makes editing such files much easier and less error-prone,
as one only has to change the value once,
at the variable definition site,
and the change will propagate to all uses of that variable automatically.
<h3 id="placement">
Module Interactions</h3>
<p>
This module defines a new type of primitive value,
the <i>variable</i>,
which is accepted by all properties.
<h3 id="values">
Values</h3>
<p>
This specification follows the <a href="http://www.w3.org/TR/CSS21/about.html#property-defs">CSS property definition conventions</a> 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.
<h2 id="defining-variables">
Defining Variables With Variable Properties</h2>
<p>
This specification defines an open-ended set of properties called <i>variable properties</i>,
which are used to define <i>variables</i>.
<table class='propdef'>
<tr>
<th>Name:</th>
<td><dfn>var-*</dfn>
<tr>
<th>Values:
<td><var><value></var>
<tr>
<th>Initial:
<td>(nothing, see prose)
<tr>
<th>Applies To:
<td>all elements
<tr>
<th>Inherited:
<td>yes
<tr>
<th>Computed Value:
<td>specified value with variables substituted (but see prose for "invalid variables")
<tr>
<th>Media:
<td>all
</table>
<p>
The <dfn id='value-type'><var><value></var></dfn> type used in the syntax above is defined as
anything matching the "value" production in <a href="http://www.w3.org/TR/CSS2/syndata.html#tokenization">CSS 2.1 Chapter 4.1</a> [[!CSS21]].
This puts almost no restrictions on what kinds of values you can store in variables.
Obviously, any valid property value
or component of a property
is allowed.
Additionally, this allows things that aren't yet valid CSS,
like unknown keywords or functions,
blocks,
at-rules,
and other kinds of custom micro-syntaxes like what's allowed in calc().
There <em>are</em> still rules, however;
for example,
unbalanced parentheses are invalid.
<p>
The term <dfn title="variable property|variables properties">variable property</dfn> refers to any property
whose name is composed of a "var-" prefix
followed by something matching the IDENT production in <a href="http://www.w3.org/TR/CSS2/syndata.html#tokenization">CSS2.1 Chapter 4</a>.
A <i>variable property</i> defines a value for a corresponding <i>variable</i>
with the same name as the property except that the "var-" prefix is replaced with a "$" prefix.
<p>
The initial value of a <i>variable property</i> is an empty invalid value.
This means that,
until a <i>variable property</i> is explicitly defined otherwise by a style sheet,
it defines an <i>invalid variable</i>
<p class='issue'>
As defined here,
the syntax for variable usage is different from the syntax for variable definition
(i.e. var-foo for definition, $foo for usage).
It might be nice to have the syntaxes match,
using "$foo" as the property name as well.
This would require a minor change in the Core Grammar.
<p>
<i>Variable properties</i> are defined to be valid but meaningless
as they are meant solely for allowing authors to pass custom data around their page,
similar to the <a href="http://www.w3.org/TR/html5/global-attributes.html#embedding-custom-non-visible-data-with-the-data-attributes">custom data attributes</a> in HTML.
Other specifications and user agents must not assign a particular meaning to <i>variable properties</i>
or attach a specific effect to them beyond the bare minimum that comes from them being valid properties.
<p>
This specification reserves the use of all function tokens starting with the prefix "var" within variable properties.
Authors must not use any such functions
except as defined in this specification or future updates.
If a variable property contains such a function,
it must match the grammar defined in this specification or future updates;
the use of such a function that does not follow the grammar,
or that utilizes such a function that is not yet defined,
makes the variable property invalid and it must be ignored.
<div class='example'>
<p>
For example,
even though this spec doesn't define a ''var-inherit()'' function,
that name is reserved by default and cannot be used.
Similarly,
the ''var()'' function <em>is</em> defined by this spec,
so any use of it must match the definition in the spec.
The following property declarations are thus invalid:
<pre>
:root {
var-foo: var-inherit(bar); /* Use of reserved, but undefined, function. */
var-foo: var(bar, baz, qux); /* Invalid use of var() function. */
}</pre>
</div>
<p>
For each <i>variable property</i>,
there is an associated variable with the same name save for the "var-" prefix.
For example,
a variable property named "var-foo" is associated with the variable named "foo".
See the next chapter for details on how to use variables.
<div class=example>
<p>
This style rule:
<pre>
:root {
var-header-color: #06c;
}</pre>
<p>
declares a <i>variable property</i> named "var-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 the "header-color" variable:
<pre>h1 { background-color: $header-color; }</pre>
<p>
The preceding rule is equivalent to writing ''background-color: #06c;'',
except that the variable name makes the origin of the color clearer,
and if ''var(header-color)'' is used on other elements in the document,
all of the uses can be updated at once
by changing the 'var-header-color' property on the root element.
</div>
<p>
Variable properties are ordinary properties,
so they can be declared on any element,
are resolved with the normal inheritance and cascade rules,
can be made conditional with ''@media'' and other conditional rules,
can be used in HTML's <code>style</code> attribute,
can be read or set using the CSSOM, etc..
<div class='example'>
<p>
If a <i>variable property</i> is declared multiple times,
the standard cascade rules help resolve it.
Variables always draw from the computed value of the associated variable property on the same element:
<pre>
:root { var-color: blue; }
div { var-color: green; }
#alert { var-color: red; }
* { color: $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></pre>
</div>
<p>
<i>Variable properties</i> may use variables in their own values to build up composite variables.
This can create cyclic dependencies
where two or more <i>variable properties</i> each attempt to use the variable that the other defines;
doing so makes all the <i>variable properties</i> involved in the cycle
compute to their initial value (which is a guaranteed-invalid value).
<div class='example'>
<p>
This example shows a variable property safely using a variable:
<pre>
:root {
var-main-color: #c06;
var-accent-background: linear-gradient(to top, $main-color, white);
}</pre>
<p>
The 'var-accent-background' property will automatically update when the 'var-main-color' property is changed.
</div>
<div class='example invalid-example'>
<p>
On the other hand,
this example shows an invalid instance of variables depending on each other:
<pre>
:root {
var-one: calc($two + 20px);
var-two: calc($one - 20px);
}</pre>
<p>
Both 'var-one' and 'var-two' now define <i>invalid variables</i> rather than lengths.
</div>
<p>
It is important to note that
<i>variable properties</i> resolve any <i>variables</i> in their values at computed-value time,
which occurs <em>before</em> the value is inherited.
In general,
cyclic dependencies occur only when multiple variable properties on the same element refer to each other;
variable 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.
<div class='example'>
<p>
For example,
given the following structure,
these variable properties are <strong>not</strong> cyclic,
and all define valid variables:
<pre>
<one><two><three /></two></one>
one { var-foo: 10px; }
two { var-bar: calc($foo + 10px); }
three { var-foo: calc($bar + 10px); }</pre>
<p>
The <one> element defines a value for 'var-foo'.
The <two> element inherits this value,
and additionally assigns a value to 'var-bar' using the ''foo'' variable.
Finally,
the <three> element inherits the 'var-bar' value
<em>after</em> variable substitution
(in other words, it sees the value ''calc(10px + 10px)''),
and then redefines 'var-foo' in terms of that value.
Since the value it inherited for 'var-bar' no longer contains a reference to the 'var-foo' property defined on <one>,
defining 'var-foo' using the ''var(bar)'' variable is not cyclic,
and actually defines a value that will eventually
(when referenced as a variable in a normal property)
resolve to ''30px''.
</div>
<!--
UUUUUUUU UUUUUUUU iiii
U::::::U U::::::U i::::i
U::::::U U::::::U iiii
UU:::::U U:::::UU
U:::::U U:::::U ssssssssss iiiiiiinnnn nnnnnnnn ggggggggg ggggg
U:::::D D:::::U ss::::::::::s i:::::in:::nn::::::::nn g:::::::::ggg::::g
U:::::D D:::::Uss:::::::::::::s i::::in::::::::::::::nn g:::::::::::::::::g
U:::::D D:::::Us::::::ssss:::::s i::::inn:::::::::::::::ng::::::ggggg::::::gg
U:::::D D:::::U s:::::s ssssss i::::i n:::::nnnn:::::ng:::::g g:::::g
U:::::D D:::::U s::::::s i::::i n::::n n::::ng:::::g g:::::g
U:::::D D:::::U s::::::s i::::i n::::n n::::ng:::::g g:::::g
U::::::U U::::::Ussssss s:::::s i::::i n::::n n::::ng::::::g g:::::g
U:::::::UUU:::::::Us:::::ssss::::::si::::::i n::::n n::::ng:::::::ggggg:::::g
UU:::::::::::::UU s::::::::::::::s i::::::i n::::n n::::n g::::::::::::::::g
UU:::::::::UU s:::::::::::ss i::::::i n::::n n::::n gg::::::::::::::g
UUUUUUUUU sssssssssss iiiiiiii nnnnnn nnnnnn gggggggg::::::g
g:::::g
gggggg g:::::g
g:::::gg gg:::::g
g::::::ggg:::::::g
gg:::::::::::::g
ggg::::::ggg
gggggg
-->
<h2 id='using-variables'>
Using Variables</h2>
<p>
After assigning a value to a <dfn>variable</dfn>
with a <i>variable property</i>,
A <dfn>variable</dfn> allows the value of a <i>variable property</i> on an element
to be substituted into another property on the element.
There are several ways to use variables:
by name,
via the ''var()'' notation,
or via the ''parent-var()'' notation to get at a variable on the element's parent.
<p>
A variable can be used in place of any component value in any property on an element.
Variables can not be used as
property names,
selectors,
or anything else besides property values -
doing so either produces an invalid value or,
in some situations like the attribute value of an attribute selector,
produces a valid value that nonetheless has no relation to the variable of that name.
<p>
A variable is substituted for its value in the property value at computed-value time.
If a declaration,
once all variables are substituted in,
is invalid,
the declaration is <i>invalid at computed-value time</i>.
<div class='example'>
<p>
For example,
the following usage is fine from a syntax standpoint,
but results in nonsense when the variable is substituted in:
<pre>
:root { var-looks-valid: 20px; }
p { background-color: $looks-valid; }</pre>
<p>
Since ''20px'' is an invalid value for 'background-color',
this instance of the property computes to 'transparent'
(the initial value for 'background-color')
instead.
</div>
<h3 id='var-glyph'>
The $ Prefix</h3>
<p>
The simplest way to use a variable is to refer to it by its name,
which is the same as the <i>variable property</i> defining it,
except with the "var-" prefix swapped out for a "$" prefix.
Formally, the syntax of a variable is:
<pre><dfn id='type-var'><var></dfn> = "$" <var>IDENT</var></pre>
<p>
...where <var>IDENT</var> is anything matching the IDENT production in <a href="http://www.w3.org/TR/CSS2/syndata.html#tokenization">CSS2.1 Chapter 4</a>.
<div class='example'>
<p>
For example,
the following code defines and uses a variable named "main-color".
<pre>
:root {
var-main-color: blue;
}
h1 {
color: $main-color;
}</pre>
</div>
<h3 id='var-function'>
Default Values - the ''var()'' notation</h3>
<p>
In some cases,
it can be useful to provide a "default" value for a variable
in case the variable isn't defined or is invalid.
<p>
For example, if a site uses variables to provide "hooks" for customization,
expecting the variables to be defined in a separate custom stylesheet,
the main stylesheet can use default values for its variable
so that the theming stylesheet can just override the variables it cares about,
rather than being forced to provide values for all of them.
<p>
The ''var()'' notation allows a default value to be specified when referencing a variable.
The syntax of ''var()'' is:
<pre><dfn id='default-var-type'><default-var></dfn> = var( <var><var></var> [, <var><value></var> ]? )</pre>
<p>
If the variable named by the first argument is valid,
the variable's value is substituted as normal.
If it's invalid, and a second argument was provided,
the value of the second argument is substituted instead.
Otherwise, the ''var()'' represents an <i>invalid variable</i>.
<p class='note'>
Note that using ''var()'' without a second argument offers no benefits
over using the variable by itself.
This is allowed for consistency with ''parent-var()'',
which <em>does</em> do something useful with only one argument.
Future variable functions will likely be similar.
<h3 id='parent-var-notation'>
Getting the Parent's Variable - the ''parent-var()'' notation</h3>
<p>
Several advanced use-cases for variables need
the ability to reference the value that a variable has on the element's parent,
rather than on the element itself.
This can be accomplished with the ''parent-var()'' notation:
<pre><dfn id='parent-var-notation-type'><parent-var></dfn> = parent-var( <var><var></var> [, <var><value></var> ]? )</pre>
<p>
If the element has a parent,
and the variable named by the first argument is valid on the parent,
the variable's value on the parent is substituted as normal.
Otherwise, if a second argument was provided,
the value of the second argument is substituted instead.
Otherwise, the ''parent-var()'' represents an <i>invalid variable</i>.
<div class='example'>
<p>
For example,
''parent-var()'' 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.
<pre>
<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 {
var-bg: parent-var($bg2, white);
var-bg2: parent-var($bg, silver);
background: url(comment.png) $bg;
}
</style></pre>
<p>
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 <code><div class='main'></code>
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 variables 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.
<p>
The ''var()'' notation can't be used here either
as it would immediately produce a cycle between $bg and $bg2,
making them both invalid.
</div>
<h3 id='using-invalid-variables'>
Using Invalid Variables</h3>
<p>
When a <i>variable property</i> has its initial value,
the <i>variable</i> it defines
represents an <dfn>invalid variable</dfn>.
Using an <i>invalid variable</i> in a property value
(including other <i>variable properties</i>)
makes the declaration <i>invalid at computed-value time</i>.
<p>
A declaration can be <dfn>invalid at computed-value time</dfn>
if it uses an invalid <i>variable</i>, as explained above,
or if it uses a valid <i>variable</i>,
but the property value,
after substituting its <i>variables</i>,
is invalid.
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.
<div class='example'>
<p>
For example, in the following code:
<pre>
:root { var-not-a-color: 20px; }
p { background-color: red; }
p { background-color: $not-a-color; }</pre>
<p>
the <p> elements will have transparent backgrounds
(the initial value for 'background-color'),
rather than red backgrounds.
The same would happen if the variable itself was invalid.
<p>
Note the difference between this
and what happens if the author had just written ''background-color: 20px'' directly in their stylesheet -
that would be a normal syntax error,
which would cause the rule to be discarded,
so the ''background-color: red'' rule would be used instead.
</div>
<p class='note'>
The <i>invalid at computed-value time</i> concept exists
because variables can't "fail early" like other syntax errors can,
so by the time the user agent realizes a property value is invalid,
it's already thrown away the other cascaded values.
<h2 id='cssom'>
CSSOM</h2>
<p>
<i>Variable properties</i> are ordinary properties,
and can be read or modified using all of the existing CSSOM APIs for reading or modifying properties.
<p>
The specification extends the IDL definitions in the CSSOM spec to represent the use of the ''var()'' function.
<h3 id='cssom-cssvariable'>
Interface CSSVariableComponentValue</h3>
<p>
The CSSVariableComponentValue interface represents a use of the ''var()'' function.
<dl>
<dt>IDL Definition
<dd>
<pre class='idl'>
[NoInterfaceObject] interface CSSVariableComponentValue {
attribute DOMString variableName;
readonly attribute any variableValue;
}</pre>
<dt>Attributes
<dd>
<dl>
<dt><code>variableName</code> of type <code>DOMString</code>
<dd>This attribute represents the argument to the function. Changing this attribute changes the <i>variable property</i> being referred to.
<dt><code>variableValue</code> of type <code>any</code>, readonly
<dd>This attribute represents the value of the <i>variable property</i> the function is referencing.
</dl>
</dl>
<h3 id='cssstyledeclaration-interface'>
Additions to the <code>CSSStyleDeclaration</code> Interface</h3>
<p class='issue'>
The set of variable properties is open-ended,
so it's 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 first,
set up a getter behavior on the interface somehow that deals with variable properties,
and second,
set up a <code>vars</code> map that exposes the variable properties that aren't set to their initial value.
<h2 id="conformance">
Conformance</h2>
<h3 id="conventions">
Document Conventions</h3>
<p>Conformance requirements are expressed with a combination of
descriptive assertions and RFC 2119 terminology. The key words “MUST”,
“MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”,
“RECOMMENDED”, “MAY”, and “OPTIONAL” in the normative parts of this
document are to be interpreted as described in RFC 2119.
However, for readability, these words do not appear in all uppercase
letters in this specification.
<p>All of the text of this specification is normative except sections
explicitly marked as non-normative, examples, and notes. [[!RFC2119]]
<p>Examples in this specification are introduced with the words “for example”
or are set apart from the normative text with <code>class="example"</code>,
like this:
<div class="example">
<p>This is an example of an informative example.
</div>
<p>Informative notes begin with the word “Note” and are set apart from the
normative text with <code>class="note"</code>, like this:
<p class="note">Note, this is an informative note.
<h3 id="conformance-classes">
Conformance Classes</h3>
<p>Conformance to CSS Variables Module
is defined for three conformance classes:
<dl>
<dt><dfn title="style sheet!!as conformance class">style sheet</dfn>
<dd>A <a href="http://www.w3.org/TR/CSS21/conform.html#style-sheet">CSS
style sheet</a>.
<dt><dfn>renderer</dfn></dt>
<dd>A <a href="http://www.w3.org/TR/CSS21/conform.html#user-agent">UA</a>
that interprets the semantics of a style sheet and renders
documents that use them.
<dt><dfn id="authoring-tool">authoring tool</dfn></dt>
<dd>A <a href="http://www.w3.org/TR/CSS21/conform.html#user-agent">UA</a>
that writes a style sheet.
</dl>
<p>A style sheet is conformant to CSS Variables Module
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.
<p>A renderer is conformant to CSS Variables Module
if, in addition to interpreting the style sheet as defined by the
appropriate specifications, it supports all the features defined
by CSS Variables Module 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.)
<p>An authoring tool is conformant to CSS Variables 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.
<h3 id="partial">
Partial Implementations</h3>
<p>So that authors can exploit the forward-compatible parsing rules to
assign fallback values, CSS renderers <strong>must</strong>
treat as invalid (and <a href="http://www.w3.org/TR/CSS21/conform.html#ignore">ignore
as appropriate</a>) any at-rules, properties, property values, keywords,
and other syntactic constructs for which they have no usable level of
support. In particular, user agents <strong>must not</strong> 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.
<h3 id="experimental">
Experimental Implementations</h3>
<p>To avoid clashes with future CSS features, the CSS2.1 specification
reserves a <a href="http://www.w3.org/TR/CSS21/syndata.html#vendor-keywords">prefixed
syntax</a> for proprietary and experimental extensions to CSS.
<p>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.
<h3 id="testing">Non-Experimental Implementations</h3>
<p>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.
<p>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.
<p>Further information on submitting testcases and implementation reports
can be found from on the CSS Working Group's website at
<a href="http://www.w3.org/Style/CSS/Test/">http://www.w3.org/Style/CSS/Test/</a>.
Questions should be directed to the
<a href="http://lists.w3.org/Archives/Public/public-css-testsuite">public-css-testsuite@w3.org</a>
mailing list.
<h3 id="cr-exit-criteria">
CR Exit Criteria</h3>
<p>
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:
<dl>
<dt>independent <dd>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.
<dt>interoperable <dd>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.
<dt>implementation <dd>a user agent which:
<ol class=inline>
<li>implements the specification.
<li>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.
<li>is not experimental (i.e., a version specifically designed
to pass the test suite and is not intended for normal usage
going forward).
</ol>
</dl>
<p>The specification will remain Candidate Recommendation for at least
six months.
<h2 class=no-num id="acknowledgments">Acknowledgments</h2>
<p>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.
<h2 class=no-num id="references">References</h2>
<h3 class="no-num" id="normative-references">Normative references</h3>
<!--normative-->
<h3 class="no-num" id="other-references">Other references</h3>
<!--informative-->
<h2 class="no-num" id="index">Index</h2>
<!--index-->
<h2 class="no-num" id="property-index">Property index</h2>
<!-- properties -->
</body>
</html>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-declaration:"~/SGML/HTML4.decl"
sgml-default-doctype-name:"html"
sgml-minimize-attributes:t
sgml-nofill-elements:("pre" "style" "br")
sgml-live-element-indicator:t
sgml-omittag:nil
sgml-shorttag:nil
sgml-namecase-general:t
sgml-general-insert-case:lower
sgml-always-quote-attributes:t
sgml-indent-step:nil
sgml-indent-data:t
sgml-parent-document:nil
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->