W3C home > Mailing lists > Public > www-style@w3.org > May 2012

[css-variables] Initial value of variables

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Wed, 30 May 2012 18:12:08 -0700
Message-ID: <CAAWBYDAE4UwT_1WSX+A60HR0QENLCbqJ1Bzeg8mtmU0e3Axy1A@mail.gmail.com>
To: www-style list <www-style@w3.org>
The initial value of a variable is always invalid, regardless of how
you try to use it - you need to explicitly provide a variable property
to get a valid variable.  Thus, you don't actually *need* an initial
value, since it will never be used.  However, operating under the
assumption that I needed to provide *something*, I've defined the
initial value to be the keyword "invalid", except it's also always

Divya recently reported that she found this boggling.  I agree it's
not great.  Here's an example from the spec:

  <p>Sample text</p>
p { var-foo: invalid; }
div,p { font-family: $foo; }

In this example, the "foo" variable is an invalid variable at the time
the DIV element references it, because the ‘var-foo’ property still
has its initial value. This causes the DIV's ‘font-family’ property to
compute to the initial value for ‘font-family’.

On the other hand, the P element defines an explicit value for the
‘var-foo’ property. Its ‘font-family’ property thus references a font
named "invalid".

In a similar vein, it means that assigning a property's value to
itself via JS, which should be a no-op, flips the variable to being
valid with the value "invalid":

el.style.varFoo = el.style.varFoo

Is it acceptable to instead just define that the initial value of a
var property is nothing?  That is, if you ask for it to be serialized,
you'll get "" out of JS.  You can't actually use this value, since the
variable is guaranteed to be invalid, and you can't actually *create*
this value manually either, since the <value> production has a + in
it.  This would avoid the weirdness discussed above.

Received on Thursday, 31 May 2012 01:13:00 UTC

This archive was generated by hypermail 2.4.0 : Monday, 23 January 2023 02:14:15 UTC