Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Design Token Management with Sass
📖 Scenario: You are building a simple style system for a website. You want to keep your colors and font sizes organized using design tokens in Sass variables. This helps you change the look easily later.
🎯 Goal: Create Sass variables for colors and font sizes as design tokens. Then use these tokens to style a heading and a paragraph in CSS.
📋 What You'll Learn
Create Sass variables for primary color, secondary color, and base font size.
Create a Sass map called $font-sizes with keys small, medium, and large and their respective sizes.
Use the design tokens to style an h1 with the primary color and large font size.
Use the design tokens to style a p with the secondary color and medium font size.
💡 Why This Matters
🌍 Real World
Design tokens help teams keep consistent styles across websites and apps. They make it easy to update colors or fonts in one place.
💼 Career
Front-end developers and UI designers use design tokens with Sass or CSS preprocessors to build scalable and maintainable style systems.
Progress0 / 4 steps
1
Create design token variables
Create three Sass variables: $color-primary with value #3498db, $color-secondary with value #2ecc71, and $font-base-size with value 1rem.
SASS
Hint
Use $variable-name: value; syntax to create Sass variables.
2
Create a font size map
Create a Sass map called $font-sizes with keys small, medium, and large and values 0.875rem, 1rem, and 1.5rem respectively.
SASS
Hint
Use parentheses ( ) to create a Sass map with key-value pairs separated by commas.
3
Style the heading using tokens
Write a CSS rule for h1 that sets color to $color-primary and font-size to the large size from the $font-sizes map using map-get().
SASS
Hint
Use map-get($map, key) to get a value from a Sass map.
4
Style the paragraph using tokens
Write a CSS rule for p that sets color to $color-secondary and font-size to the medium size from the $font-sizes map using map-get().
SASS
Hint
Remember to use map-get() to access the medium font size from the map.
Practice
(1/5)
1. What is the main purpose of design tokens in Sass?
easy
A. To write JavaScript functions inside Sass
B. To create animations in Sass
C. To store reusable style values like colors and sizes
D. To manage HTML structure
Solution
Step 1: Understand design tokens concept
Design tokens are variables that hold style values such as colors, fonts, and sizes.
Step 2: Identify their purpose in Sass
They help keep styles consistent and easy to update by reusing these values.
Final Answer:
To store reusable style values like colors and sizes -> Option C
Quick Check:
Design tokens = reusable style values [OK]
Hint: Design tokens store style values for reuse [OK]
Common Mistakes:
Thinking design tokens are for animations
Confusing design tokens with JavaScript code
Believing design tokens manage HTML
2. Which of the following is the correct way to declare a design token for a primary color in Sass?
easy
A. let $primary-color = #3498db;
B. primary-color = #3498db;
C. var primary-color = #3498db;
D. $primary-color: #3498db;
Solution
Step 1: Recall Sass variable syntax
Sass variables start with a dollar sign ($) and use a colon to assign values.
Step 2: Check each option
$primary-color: #3498db; uses correct Sass syntax: $primary-color: #3498db;. Others use JavaScript or invalid syntax.
Final Answer:
$primary-color: #3498db; -> Option D
Quick Check:
Sass variables start with $ and use : [OK]
Hint: Sass variables start with $ and use colon : [OK]
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