CSS Variables — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the CSS Variables lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.
Exercises(5)
- 1
Define a variable
easy10 minDefine --brand on :root and use it for the box colour.
- 2
Use a variable for spacing
easy10 minDefine --gap as 24px and use it as padding.
- 3
Provide a fallback
easy10 minUse a fallback so the box is blue when the variable is undefined.
- 4
Scope a variable
easy10 minDefine --brand on #parent so only its children use it.
- 5
Override a variable deeper down
medium10 minRoot sets red; #parent overrides it to blue.
Find the bug(5)
- 1
Fix the missing dashes
easy8 minCustom properties must start with two dashes.
- 2
Fix the variable used without var()
easy8 minA custom property must be read through var().
- 3
Fix the out-of-scope variable
easy8 minThe variable is defined on a sibling, so the box cannot see it.
- 4
Fix the missing fallback
easy8 minThe variable is undefined, so the colour never applies.
- 5
Fix the typo in the variable name
easy8 minThe name used does not match the one defined.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace