HTML & CSS · Junior · Question 37 of 75
How do you correctly declare and use a CSS variable?
- 1
$main: red; color: var($main); - 2
@main: red; color: get(@main); - ✓Correct answer:
--main: red; color: var(--main);
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.