How do CSS custom properties differ from Sass/LESS variables in scope and runtime behavior?

Prepare for the CSS Mastery SAD Maintenance and CSA Stand Ups Test. With flashcards and multiple choice questions, ready yourself for the exam with hints and explanations for every question. Ace your exam today!

Multiple Choice

How do CSS custom properties differ from Sass/LESS variables in scope and runtime behavior?

Explanation:
The key idea is when and how values are resolved. CSS custom properties are actual CSS that the browser reads at runtime. They participate in the cascade and inheritance, so you can override them with more specific selectors or switch themes by changing values in the DOM (often with JavaScript or data attributes). Because they’re resolved while the page is live, they can respond to context like media queries or user actions without recompiling. Sass/LESS variables, on the other hand, are resolved during preprocessing. They’re substituted with concrete values before the CSS is sent to the browser, so they don’t exist in the final CSS and can’t be changed by normal CSS rules or runtime DOM changes. They’re scoped in the preprocessor (lexical scope) and effectively become constants in the generated CSS. So the best description is that CSS variables are runtime, cascade-based, and themeable, while Sass/LESS variables are compile-time constants that don’t change at runtime.

The key idea is when and how values are resolved. CSS custom properties are actual CSS that the browser reads at runtime. They participate in the cascade and inheritance, so you can override them with more specific selectors or switch themes by changing values in the DOM (often with JavaScript or data attributes). Because they’re resolved while the page is live, they can respond to context like media queries or user actions without recompiling.

Sass/LESS variables, on the other hand, are resolved during preprocessing. They’re substituted with concrete values before the CSS is sent to the browser, so they don’t exist in the final CSS and can’t be changed by normal CSS rules or runtime DOM changes. They’re scoped in the preprocessor (lexical scope) and effectively become constants in the generated CSS.

So the best description is that CSS variables are runtime, cascade-based, and themeable, while Sass/LESS variables are compile-time constants that don’t change at runtime.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy