Bird
Raised Fist0
SASSmarkup~20 mins

CSS custom properties vs SASS variables - Practice Questions

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
CSS Variable Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
How do CSS custom properties behave differently from SASS variables?
Which statement correctly describes a key difference between CSS custom properties and SASS variables?
ACSS custom properties are only available during SASS compilation, while SASS variables exist in the browser.
BSASS variables can be updated by JavaScript after the page loads, but CSS custom properties cannot.
CSASS variables support inheritance in CSS selectors, but CSS custom properties do not.
DCSS custom properties can be changed dynamically in the browser at runtime, while SASS variables are fixed at compile time.
Attempts:
2 left
💡 Hint
Think about when each variable type is processed and if they can be changed after the page loads.
📝 Syntax
intermediate
1:30remaining
Identify the valid CSS custom property syntax
Which option shows the correct way to define and use a CSS custom property?
A:root { $main-color: #3498db; } .btn { color: var($main-color); }
B:root { --main-color: #3498db; } .btn { color: $main-color; }
C:root { --main-color: #3498db; } .btn { color: var(--main-color); }
D:root { --main-color = #3498db; } .btn { color: var(--main-color); }
Attempts:
2 left
💡 Hint
CSS custom properties start with two dashes and use var() to access.
rendering
advanced
2:00remaining
What color will the button text be?
Given this SASS and CSS code, what color will the button text appear in the browser?
SASS
$main-color: red;
:root {
  --main-color: blue;
}
.btn {
  color: $main-color;
  background-color: var(--main-color);
}
ARed text on blue background
BBlue text on blue background
CRed text on red background
DBlue text on red background
Attempts:
2 left
💡 Hint
Remember which variables are replaced during compilation and which are used by the browser.
selector
advanced
1:30remaining
Which selector correctly changes a CSS custom property for a specific element?
You want to change the CSS custom property --main-color only for buttons inside a <section>. Which CSS snippet does this correctly?
Asection button { --main-color: green; }
Bsection button { color: var(--main-color: green); }
Csection button { --main-color = green; }
Dsection button { $main-color: green; }
Attempts:
2 left
💡 Hint
CSS custom properties are set like normal CSS properties with two dashes.
accessibility
expert
2:30remaining
How can CSS custom properties improve accessibility?
Which approach best uses CSS custom properties to help users with visual impairments switch between color themes?
AUse SASS variables to define colors and recompile CSS for each theme.
BDefine color variables with CSS custom properties and change their values on a parent element when toggling themes.
CHardcode colors in CSS and use JavaScript to replace all color values inline when switching themes.
DUse inline styles on each element to set colors directly for each theme.
Attempts:
2 left
💡 Hint
Think about which method allows changing colors without recompiling or editing many elements.

Practice

(1/5)
1. Which of the following is true about CSS custom properties compared to SASS variables?
easy
A. SASS variables start with -- and are dynamic in the browser.
B. SASS variables start with -- and work in the browser at runtime.
C. CSS custom properties start with $ and are replaced before the browser sees CSS.
D. CSS custom properties start with -- and work in the browser at runtime.

Solution

  1. Step 1: Identify CSS custom properties syntax

    CSS custom properties always start with -- and are live in the browser, meaning they can be changed dynamically.
  2. Step 2: Identify SASS variables syntax and behavior

    SASS variables start with $ and are replaced during the build process, so they don't exist in the browser.
  3. Final Answer:

    CSS custom properties start with -- and work in the browser at runtime. -> Option D
  4. Quick Check:

    CSS variables = -- prefix and runtime [OK]
Hint: CSS vars use -- and work live; SASS vars use $ and compile away [OK]
Common Mistakes:
  • Confusing $ and -- prefixes
  • Thinking SASS variables work in the browser
  • Assuming CSS variables are replaced before runtime
2. Which is the correct way to declare a SASS variable for a color?
easy
A. primary-color: #3498db;
B. --primary-color: #3498db;
C. $primary-color: #3498db;
D. $primary-color == #3498db;

Solution

  1. Step 1: Recall SASS variable syntax

    SASS variables start with $ and use a colon : to assign values.
  2. Step 2: Check each option

    $primary-color: #3498db; uses correct syntax. --primary-color: #3498db; uses the CSS custom property prefix. primary-color: #3498db; omits the $ prefix. $primary-color == #3498db; uses double equals which is invalid.
  3. Final Answer:

    $primary-color: #3498db; -> Option C
  4. Quick Check:

    SASS variable = $name: value; [OK]
Hint: SASS vars start with $ and use colon for assignment [OK]
Common Mistakes:
  • Using -- instead of $ for SASS variables
  • Using == instead of : for assignment
  • Omitting $ prefix
3. Given the following code, what color will the text be in the browser?
:root { --main-color: red; }
.box { color: var(--main-color); }
$main-color: blue;
.box2 { color: $main-color; }
medium
A. Both .box and .box2 text will be red
B. .box text will be red; .box2 text will be blue
C. .box text will be blue; .box2 text will be red
D. Both .box and .box2 text will be blue

Solution

  1. Step 1: Understand CSS custom property usage

    The --main-color is set to red in :root. The class .box uses var(--main-color), so it will be red at runtime.
  2. Step 2: Understand SASS variable usage

    The SASS variable $main-color is blue and used in .box2. This is replaced during compilation, so .box2 color will be blue in the final CSS.
  3. Final Answer:

    .box text will be red; .box2 text will be blue -> Option B
  4. Quick Check:

    CSS var = red; SASS var = blue [OK]
Hint: CSS vars live in browser; SASS vars replaced before browser sees CSS [OK]
Common Mistakes:
  • Thinking SASS variables work at runtime
  • Confusing which variable affects which class
  • Assuming CSS variables are replaced before runtime
4. What is wrong with this SASS code snippet?
$color: green;
.text { color: var($color); }
medium
A. The var() function is only for CSS custom properties, not SASS variables.
B. The variable name should start with -- instead of $.
C. SASS variables cannot be used inside var() function.
D. The color value green is invalid.

Solution

  1. Step 1: Understand var() function usage

    The var() function is a CSS function used only for CSS custom properties (those starting with --).
  2. Step 2: Understand SASS variable usage

    SASS variables start with $ and are used directly without var(). Using var($color) is invalid because var() expects a CSS custom property name.
  3. Final Answer:

    The var() function is only for CSS custom properties, not SASS variables. -> Option A
  4. Quick Check:

    var() = CSS vars only, not SASS [OK]
Hint: Use $var directly in SASS; var() only for CSS custom properties [OK]
Common Mistakes:
  • Using var() with SASS variables
  • Confusing $ and -- prefixes
  • Thinking var() works for SASS variables
5. You want to create a theme where users can switch colors dynamically in the browser. Which approach is best and why?
$primary-color: #0055ff;
:root { --primary-color: #0055ff; }
hard
A. Use CSS custom property --primary-color because it can change dynamically in the browser.
B. Use SASS variable $primary-color because it compiles faster.
C. Use both SASS and CSS variables together for better performance.
D. Use inline styles instead of variables for dynamic changes.

Solution

  1. Step 1: Understand dynamic changes in the browser

    CSS custom properties (starting with --) live in the browser and can be changed with JavaScript or media queries without recompiling CSS.
  2. Step 2: Understand SASS variable limitations

    SASS variables are replaced during build time and cannot change after the CSS is loaded, so they are not suitable for dynamic theming.
  3. Final Answer:

    Use CSS custom property --primary-color because it can change dynamically in the browser. -> Option A
  4. Quick Check:

    Dynamic theme = CSS vars [OK]
Hint: Dynamic changes need CSS vars; SASS vars are static [OK]
Common Mistakes:
  • Choosing SASS variables for runtime changes
  • Thinking both together improve dynamic behavior
  • Ignoring CSS custom properties' runtime flexibility