Recall & Review
beginner
What is variable scope in CSS?
Variable scope in CSS means where a CSS custom property (variable) can be used or accessed in your styles. It can be global or limited to a specific part of the page.
Click to reveal answer
beginner
How do you declare a CSS variable globally?
You declare a CSS variable globally by defining it inside the
:root selector. For example: :root { --main-color: blue; } makes --main-color available everywhere.Click to reveal answer
intermediate
What happens if you declare the same CSS variable inside a specific selector?
The variable inside the specific selector overrides the global one only within that selector's scope. Outside, the global variable is used.
Click to reveal answer
intermediate
Example: What color will the text be?<br>
:root { --text-color: black; }
.special { --text-color: red; color: var(--text-color); }Text inside elements with class
special will be red because the local variable --text-color overrides the global one. Other elements use black.Click to reveal answer
beginner
Why is understanding CSS variable scope useful?
It helps you organize styles better, avoid conflicts, and create themes by changing variables in specific parts without rewriting all styles.
Click to reveal answer
Where should you declare a CSS variable to make it available everywhere?
✗ Incorrect
Declaring variables inside :root makes them global and accessible throughout the CSS.
If a variable is declared both globally and inside a class, which one is used inside that class?
✗ Incorrect
The variable inside the class overrides the global variable within that class's scope.
What CSS function is used to access a variable's value?
✗ Incorrect
The var() function is used to get the value of a CSS custom property.
Can CSS variables be scoped inside media queries?
✗ Incorrect
Variables declared inside media queries are scoped to those queries and apply only when conditions match.
What is the benefit of scoping CSS variables locally?
✗ Incorrect
Local scoping helps avoid conflicts and allows different parts of the page to have customized styles.
Explain CSS variable scope and how it affects styling on a webpage.
Think about where you declare variables and where they can be used.
You got /3 concepts.
Describe a scenario where you would use local CSS variables instead of global ones.
Consider theming or special sections with unique colors.
You got /3 concepts.