HTML & CSS · Junior · Question 37 of 75

How do you correctly declare and use a CSS variable?

Explanation

CSS custom properties are declared with two dashes and read with var(), optionally with a fallback: var(--main, black). $var is Sass syntax and @var is Less; those are resolved at build time. CSS variables live in the browser: they inherit, take part in the cascade and can change in media queries or via JS.

Further reading

Problem with a question

HTML & CSS · Junior · question 37

Test yourself

Take the HTML & CSS · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz