Joyce Babu
Joyce Babu

Reputation: 20654

CSS Variables - Multiple fallbacks not working

According to MDN, the var function accepts multiple fallbacks. But I am unable to get them to work.

I tried the following code on Chrome, Firefox and Safari. The background-color for .demo3 is transparent on all the above browsers.

Is it an error with the code, or is it because the browsers have not implemented variable fallback?

:root {
  --my-var: red;
}

.demo1 {
  background-color: var(--my-var);
}

.demo2 {
  background-color: var(--my-background, pink);
}

.demo3 {
  background-color: var(--my-background, --my-var, pink);
}
<div class="demo1">No fallback</div>

<div class="demo2">Single fallback</div>

<div class="demo3">Multiple fallbacks</div>

Upvotes: 5

Views: 2382

Answers (1)

alexhenkel
alexhenkel

Reputation: 602

For multiple fallbacks try: background-color: var(--my-background, var(--my-var, pink));

Upvotes: 16

Related Questions