Challenge - 5 Problems
CSS Variable Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate2:00remaining
What is the correct way to declare a CSS variable for primary color?
Choose the option that correctly declares a CSS variable named
--primary-color with the value #3498db inside the :root selector.Attempts:
2 left
💡 Hint
CSS variables start with two dashes and are declared inside a selector like :root.
✗ Incorrect
CSS variables must be declared with two dashes (--) and a value inside a selector block. The :root selector is commonly used to declare global variables.
🧠 Conceptual
intermediate2:00remaining
How do CSS variables inherit values?
If a CSS variable is declared inside a
body selector, which statement is true about its availability?Attempts:
2 left
💡 Hint
Think about how CSS inheritance works with selectors.
✗ Incorrect
CSS variables declared inside a selector are inherited by its child elements unless overridden by another declaration.
❓ selector
advanced2:00remaining
Which selector correctly uses a CSS variable for background color?
Given the variable
--bg-color declared in :root, which CSS rule correctly applies it as a background color to all section elements?Attempts:
2 left
💡 Hint
CSS variables are accessed with the var() function and two dashes.
✗ Incorrect
To use a CSS variable, you must call it with var() and include the two dashes in the variable name.
❓ layout
advanced2:00remaining
How can CSS variables help create a responsive layout?
Which option shows a CSS variable declaration that changes based on screen width using media queries?
Attempts:
2 left
💡 Hint
Variables can be redefined inside media queries on the same selector.
✗ Incorrect
You can redefine CSS variables inside media queries on the :root selector to change values responsively.
❓ accessibility
expert2:00remaining
Why is it important to use CSS variables for color themes in accessible web design?
Which statement best explains the accessibility benefit of using CSS variables for color themes?
Attempts:
2 left
💡 Hint
Think about how changing variables can help users customize appearance.
✗ Incorrect
CSS variables let developers create multiple themes and switch them easily, helping users with visual impairments choose comfortable colors.