By the end of this lesson you can
- Explain variables and how they relate to design tokens.
- Create colour, number and string variables in collections.
- Use modes to switch between themes such as light and dark.
The idea
Variables store reusable values: colours, numbers (spacing, radius), strings (text) and booleans. Instead of typing #1D4ED8 into every button, you apply a variable such as color/primary. Change the variable and every use updates.
Design tokens
Design tokens are the same idea in a form shared with code: named values for design decisions. Variables in a design tool can be exported or synced as tokens, so designers and developers use the same names and values.
Primitive and semantic variables
Many teams use two layers. Primitive variables hold raw values (blue/600 = #1D4ED8). Semantic variables describe purpose and point to primitives (color/action/primary = blue/600). Components use semantic variables. When the brand changes, you change what the semantic variable points to.
Collections and modes
Variables live in collections. A collection can have modes: for example Light and Dark, or Compact and Comfortable. Each mode gives the same variable a different value, so switching a frame's mode switches the whole theme.
Why it matters in real projects
Variables make large-scale changes safe and fast, support themes such as dark mode without duplicating screens, and create a shared vocabulary with developers. They are a core skill for working on any modern design system.
A realistic example
A banking app needs a dark theme. Without variables, every screen would have to be duplicated and recoloured.
The team creates primitive colour variables and a semantic collection with Light and Dark modes: surface/default, text/primary, action/primary and so on. Components are updated to use the semantic variables. Switching any screen frame to Dark mode now shows the dark theme instantly, and developers implement it from the same token names.
Step by step
Create primitives
Make a collection of raw colour values, such as a blue and grey scale.
Create semantics
Make a collection with names describing purpose, pointing to primitives.
Add modes
Add Light and Dark modes to the semantic collection.
Add number variables
Create spacing and radius variables from your scales.
Apply to components
Use semantic variables in fills, strokes, padding and gaps.
Switch modes
Change a frame's mode and check everything updates.
Common mistakes
Mistake Applying primitive colours directly in components.
Instead Use semantic variables so themes can change.
Mistake Names describing appearance ("blue-button").
Instead Describe purpose ("action/primary").
Mistake Too many variables.
Instead Start small and add only when needed.
Check your understanding
Choose an answer, then check it. There is an explanation either way.
Practice exercise
Exercise · about 1 h
Themeable card
Create variables and make a card that switches between light and dark themes.
Steps
- Create primitive colours.
- Create semantic colours with Light and Dark modes.
- Build a card using only semantic variables.
- Switch modes and fix any contrast problems.
Deliverable
Variable collections and a card shown in both modes.
Self-assessment
Tick each item when it is true of your exercise. Be honest; this is for you.
4 items
Summary
- Variables store reusable values.
- Design tokens share the same idea with code.
- Use primitive and semantic layers.
- Modes switch themes without duplicating screens.
Further reading
Third-party sources, chosen for reliability. They open in a new tab.
- Design tokens (opens in a new tab)Material Design 3
- Design Tokens Community Group (opens in a new tab)W3C Community Group
Your notes
Marking complete updates your course and roadmap progress.