0
0
CSSmarkup~20 mins

Why CSS variables are used - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
CSS Variable Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2: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?
AThey make the website load faster by compressing colors.
BThey automatically change colors based on the time of day without extra code.
CThey prevent users from changing colors in their browser.
DThey let you store the color once and reuse it everywhere, so changing it in one place updates all uses.
Attempts:
2 left
💡 Hint
Think about how many places you might use the same color in your CSS.
📝 Syntax
intermediate
2: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?
A:root { --font-size = 1.2rem; } p { font-size: var(--font-size); }
B:root { --font-size: 1.2rem; } p { font-size: var(--font-size); }
C:root { --font-size: 1.2rem; } p { font-size: --font-size; }
D:root { font-size: --1.2rem; } p { font-size: var(font-size); }
Attempts:
2 left
💡 Hint
CSS variables start with two dashes and are accessed with var().
rendering
advanced
2: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; }
CSS
:root { --main-color: blue; }
h1 { color: var(--main-color); }
:root { --main-color: red; }
AThe heading text will be blue because the first declaration is used.
BThe heading text will be purple because the colors mix.
CThe heading text will be red because the last variable declaration overrides the first.
DThe heading text will be black because the variable is invalid.
Attempts:
2 left
💡 Hint
Later CSS rules override earlier ones if they have the same specificity.
selector
advanced
2: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?
Asection { --bg-color: green; }
B:root section { --bg-color: green; }
Csection::root { --bg-color: green; }
Dbody > section { --bg-color: green; }
Attempts:
2 left
💡 Hint
Variables can be scoped to any selector by declaring them inside it.
accessibility
expert
3: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?
AThey allow users or developers to change colors and sizes easily by updating variables, supporting high contrast or larger text modes.
BThey automatically detect screen readers and adjust content accordingly.
CThey prevent users from changing font sizes, keeping design consistent.
DThey replace all images with text descriptions for screen readers.
Attempts:
2 left
💡 Hint
Think about how changing one value can affect many style properties.