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 value of
color in this CSS snippet?Given the CSS below, what color will the
h1 text be rendered in the browser?CSS
:root {
--main-color: #3498db;
}
h1 {
color: var(--main-color);
}Attempts:
2 left
💡 Hint
Look at how the variable
--main-color is defined and used.✗ Incorrect
The variable
--main-color is set to #3498db in the root. The h1 uses var(--main-color) so it will have that blue color.🧠 Conceptual
intermediate2:00remaining
Which CSS variable scope is correct for this behavior?
You want a CSS variable
--btn-bg to have different values inside .card and outside it. Which scope should you use to achieve this?Attempts:
2 left
💡 Hint
Variables cascade and inherit from their scope.
✗ Incorrect
Variables defined in
:root apply globally. Defining --btn-bg inside .card overrides it only there, allowing different values inside and outside.❓ selector
advanced2:00remaining
What color will the
p text have?Consider the CSS below. What color will the
p inside .container be?CSS
:root {
--text-color: black;
}
.container {
--text-color: red;
}
.container p {
color: var(--text-color, blue);
}Attempts:
2 left
💡 Hint
Variables cascade and the closest scope applies.
✗ Incorrect
The
p inside .container inherits --text-color from .container which is red, so the text color is red.❓ layout
advanced2:00remaining
How does using CSS variables improve layout flexibility?
Which statement best explains how CSS variables help when adjusting layout spacing?
Attempts:
2 left
💡 Hint
Think about how variables can be reused.
✗ Incorrect
CSS variables let you define spacing once and reuse it. Changing the variable updates all places using it, making layout adjustments easier.
❓ accessibility
expert3:00remaining
How can CSS variables improve accessibility for users with visual impairments?
Which approach using CSS variables best supports users who need high contrast themes?
Attempts:
2 left
💡 Hint
Think about how variables can be changed dynamically.
✗ Incorrect
Using CSS variables for colors allows easy switching between normal and high contrast themes by changing variable values, improving accessibility.