Challenge - 5 Problems
CSS Variable Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
Why use CSS variables for colors?
You want to change the main color of your website easily in one place. Why are CSS variables helpful here?
Attempts:
2 left
💡 Hint
Think about how many places you might use the same color in your CSS.
✗ Incorrect
CSS variables let you define a value once and reuse it multiple times. This makes it easy to update styles consistently by changing the variable value in one place.
📝 Syntax
intermediate2:00remaining
How to declare and use a CSS variable?
Which option correctly declares a CSS variable for font size and uses it in a paragraph?
Attempts:
2 left
💡 Hint
CSS variables start with two dashes and are accessed with var().
✗ Incorrect
CSS variables are declared with two dashes and accessed using var(). The correct syntax is shown in option B.
❓ rendering
advanced2:00remaining
What is the visible effect of this CSS code?
Given this CSS, what color will the heading text show?
:root { --main-color: blue; }
h1 { color: var(--main-color); }
:root { --main-color: red; }
:root { --main-color: blue; }
h1 { color: var(--main-color); }
:root { --main-color: red; }
CSS
:root { --main-color: blue; }
h1 { color: var(--main-color); }
:root { --main-color: red; }Attempts:
2 left
💡 Hint
Later CSS rules override earlier ones if they have the same specificity.
✗ Incorrect
CSS variables follow normal CSS cascading rules. The last declaration of --main-color is red, so the heading uses red.
❓ selector
advanced2:00remaining
Which selector correctly changes a CSS variable only inside a section?
You want to set --bg-color to green only inside a element. Which CSS code does this?
Attempts:
2 left
💡 Hint
Variables can be scoped to any selector by declaring them inside it.
✗ Incorrect
Declaring --bg-color inside section applies it only to that section and its children. Option A is correct.
❓ accessibility
expert3:00remaining
How do CSS variables improve accessibility for users with visual impairments?
Which statement best explains how CSS variables help make websites easier to customize for accessibility?
Attempts:
2 left
💡 Hint
Think about how changing one value can affect many style properties.
✗ Incorrect
CSS variables let developers create themes or modes (like high contrast or large text) by changing variable values, making accessibility easier.