Define --brand on :root and use it for the box colour.
Acceptance criteria
- 1.Define --brand on :root and use it for the box colour.
CSS Tutorial · CSS Foundations
These 10 tasks go with the CSS Variables chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “Define reusable values that participate in the cascade and can change across components, themes, and media conditions. The examples show global tokens, component-level overrides, fallbacks, inheritance, and typed properties registered with @property.” .
1.Define a variableexercise · easy · 10 min
Define --brand on :root and use it for the box colour.
Passes when: Define --brand on :root and use it for the box colour.
2.Use a variable for spacingexercise · easy · 10 min · practice plan
Define --gap as 24px and use it as padding.
Passes when: Define --gap as 24px and use it as padding.
3.Provide a fallbackexercise · easy · 10 min · practice plan
Use a fallback so the box is blue when the variable is undefined.
Passes when: Use a fallback so the box is blue when the variable is undefined.
4.Scope a variableexercise · easy · 10 min · practice plan
Define --brand on #parent so only its children use it.
Passes when: Define --brand on #parent so only its children use it.
5.Override a variable deeper downexercise · medium · 10 min · practice plan
Root sets red; #parent overrides it to blue.
Passes when: Root sets red; #parent overrides it to blue.
6.Fix the missing dashesbug fix · easy · 8 min
Custom properties must start with two dashes.
Passes when: Custom properties must start with two dashes.
7.Fix the variable used without var()bug fix · easy · 8 min · practice plan
A custom property must be read through var().
Passes when: A custom property must be read through var().
8.Fix the out-of-scope variablebug fix · easy · 8 min · practice plan
The variable is defined on a sibling, so the box cannot see it.
Passes when: The variable is defined on a sibling, so the box cannot see it.
9.Fix the missing fallbackbug fix · easy · 8 min · practice plan
The variable is undefined, so the colour never applies.
Passes when: The variable is undefined, so the colour never applies.
10.Fix the typo in the variable namebug fix · easy · 8 min · practice plan
The name used does not match the one defined.
Passes when: The name used does not match the one defined.
Between them these tasks cover Defining variables, var() and fallbacks and Scoping.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.