Recall & Review
beginner
What is a CSS variable?
A CSS variable is a custom property that stores a value you can reuse throughout your CSS. It helps keep styles consistent and easy to update.
Click to reveal answer
beginner
How do you declare a CSS variable?
You declare a CSS variable inside a selector using two dashes before the name, like
--main-color: blue;. Usually, variables are declared inside the :root selector for global use.Click to reveal answer
beginner
How do you use a CSS variable in your styles?
Use the
var() function with the variable name, like color: var(--main-color);. This applies the stored value wherever you use it.Click to reveal answer
beginner
Why use CSS variables instead of repeating values?
CSS variables make it easy to update styles in one place. For example, changing
--main-color updates all uses of that color, saving time and reducing mistakes.Click to reveal answer
intermediate
Can CSS variables have fallback values?
Yes! You can provide a fallback value inside
var(), like color: var(--unknown-color, black);. If the variable is not defined, the fallback is used.Click to reveal answer
How do you declare a CSS variable named
--font-size with value 16px globally?✗ Incorrect
CSS variables are declared inside selectors with two dashes. The
:root selector is used for global scope.Which syntax correctly uses a CSS variable named
--main-color for text color?✗ Incorrect
Use the
var() function to access CSS variables.What happens if you use
color: var(--unknown-color, red); but --unknown-color is not defined?✗ Incorrect
The fallback value
red is used if the variable is not defined.Why is it good to declare CSS variables inside
:root?✗ Incorrect
:root is the highest-level selector, so variables declared there can be used anywhere.Which of these is NOT a benefit of using CSS variables?
✗ Incorrect
CSS variables only affect styles, not HTML content.
Explain how to declare and use a CSS variable for a background color.
Think about where to put the variable and how to apply it in CSS.
You got /4 concepts.
Describe the benefits of using CSS variables in a website's style.
Consider how variables save time and reduce errors.
You got /4 concepts.