Design tokens help keep colors, fonts, and sizes consistent across your website. They make it easy to change styles in one place and see updates everywhere.
When you want to use the same colors and fonts on many pages.
When you need to update your website's look quickly and easily.
When working with a team to keep styles consistent.
When building a design system or reusable style library.
When you want to avoid repeating the same values in your CSS.
Syntax
SASS
$token-name: value;
Design tokens are usually stored as variables in Sass using the $ sign.
Use clear names for tokens to know what they control, like $color-primary or $font-size-base.
Examples
This sets a primary color token to a blue shade.
SASS
$color-primary: #3498db;
This sets a base font size token using relative units for better scaling.
SASS
$font-size-base: 1rem;
This token controls small spacing used for padding or margins.
SASS
$spacing-small: 0.5rem;
Sample Program
This example shows how to define design tokens as Sass variables and use them in CSS rules. The button changes color slightly on hover using a Sass color function.
A. Missing semicolon after $color-primary declaration
B. Wrong variable name syntax
C. Using hex colors is not allowed in Sass variables
D. Background color property is invalid
Solution
Step 1: Check variable declarations
$color-primary is missing a semicolon at the end of the line, which is required in Sass.
Step 2: Verify other parts
Variable names and background-color property are correct. Hex colors are valid.
Final Answer:
Missing semicolon after $color-primary declaration -> Option A
Quick Check:
Each Sass variable line must end with ; [OK]
Hint: Always end Sass variable lines with semicolon ; [OK]
Common Mistakes:
Omitting semicolons after variable declarations
Thinking hex colors are invalid in Sass
Misnaming variables without $ sign
5. You want to create a design token system in Sass that allows easy theme switching between light and dark modes. Which approach below best manages color tokens for this purpose?
hard
A. Hardcode colors directly in CSS without variables
B. Define separate maps for light and dark colors, then use a variable to select the active map
C. Use JavaScript to change colors only, ignoring Sass variables
D. Create one set of variables and manually change each color in the stylesheet
Solution
Step 1: Understand theme switching needs
Theme switching requires grouping colors so you can easily swap them based on mode.
Step 2: Evaluate options for managing tokens
Using separate Sass maps for light and dark themes allows selecting the active theme map with a variable, making switching easy and maintainable.
Step 3: Reject other options
Hardcoding colors or manual changes are error-prone and not scalable. JavaScript alone ignores Sass benefits.
Final Answer:
Define separate maps for light and dark colors, then use a variable to select the active map -> Option B
Quick Check:
Use maps and variables for theme switching [OK]
Hint: Use Sass maps and a variable to switch themes [OK]
Common Mistakes:
Hardcoding colors instead of using variables
Ignoring Sass variables and relying only on JavaScript
Manually changing colors everywhere instead of grouping
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.