Bug 16517 - CSS variables: Need a way to define a default value
CSS variables: Need a way to define a default value
Status: NEW
Product: CSS
Classification: Unclassified
Component: Variables
PC All
: P2 normal
: ---
Assigned To: Tab Atkins Jr.
Depends on:
  Show dependency treegraph
Reported: 2012-03-26 05:47 UTC by Roland Steiner
Modified: 2012-07-16 18:41 UTC (History)
1 user (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Roland Steiner 2012-03-26 05:47:02 UTC
In the current CSS variables spec, AFAICT it is not possible to specify a default value if a variable is not defined. For example, one cannot write:

p {
    background-color: black;
    background-color: var(user-bg-color);

to have the background color default of "black" be overwritten with the contents of "var-user-bg-color", since the latter will always be selected, and revert to invalid (i.e., transparent) rather than black if that variable is not defined.

One way to allow this (IMHO essential) use case is to add a default-value parameter to the var() function:

p {
    background-color: var(user-bg-color, black);

In this case, it should be allowed to nest var() functions, for multiple levels of fall-back:

.menuitem {
    background-color: var(menu-item-bg, var(menu-bg, navy));