CSS custom properties (variables) are part of the CSS language and exist in the browser. They can be updated dynamically using JavaScript or CSS at runtime. SASS variables are processed during the build step and do not exist in the browser, so they cannot be changed after compilation.
CSS custom properties are defined with two dashes (--) and accessed with the var() function. SASS variables use $ and are not valid in CSS.
$main-color: red; :root { --main-color: blue; } .btn { color: $main-color; background-color: var(--main-color); }
The SASS variable $main-color is replaced with red during compilation, so color: $main-color; becomes color: red;. The CSS custom property --main-color is blue and used at runtime for background color.
--main-color only for buttons inside a <section>. Which CSS snippet does this correctly?To change a CSS custom property for specific elements, you set it as a normal CSS property with two dashes inside the selector. Option A does this correctly. Options A and B have invalid syntax. Option A uses SASS variable syntax, which is invalid in CSS.
CSS custom properties can be changed dynamically on a parent element, allowing easy theme switching without recompiling or editing many styles. This improves accessibility by letting users toggle themes instantly. SASS variables are static and require recompilation. Inline styles and JavaScript replacements are less efficient and harder to maintain.