Design tokens are the named, foundational values, colors, spacing, typography, and breakpoints, that define a design system. This lesson shows how to model design tokens as Sass maps and variables so they stay consistent and easy to update across an entire project.
What Are Design Tokens?
A design token is a single named value representing a design decision, primary-color, spacing-md, font-size-lg, that gets reused everywhere that decision applies. Sass variables and maps are a natural way to define tokens directly in code, ready to consume from mixins, functions, and components.
map.get() supports multiple keys to reach into nested maps directly.
A small wrapper function (like token()) makes token lookups shorter and more readable at call sites.
Grouping tokens by category (color, spacing, typography) keeps a large token set organized.
Tokens defined with !default can be overridden by a consuming project through with().
Design Tokens Cheatsheet
Common token categories and how to model them in Sass.
Category
Example Tokens
Sass Representation
Color
primary, success, danger, neutral-100...900
Nested map of color values
Spacing
xs, sm, md, lg, xl
Map of length values
Typography
font-size-sm...4xl, font-weight-*
Map of sizes and weights
Breakpoints
sm, md, lg, xl
Map of pixel widths
Radius
sm, md, lg, full
Map of border-radius values
Shadow
sm, md, lg
Map of box-shadow value lists
Writing a Token Accessor Function
Wrapping map.get() in a small custom function gives every token lookup a consistent, short syntax and a place to add validation, like erroring on a typo'd token name.
Sass tokens are compile-time only. For tokens that need to change at runtime (like a user-toggled theme), generate matching CSS custom properties from your Sass token map, covered in more depth in the CSS Custom Properties lesson.
The core benefit of design tokens is consistency: every component references the same map instead of hardcoding its own values, so a single change (like adjusting the brand color) propagates everywhere automatically.
Never hardcode a raw color or spacing value directly inside a component partial.
Always reference the token map (directly or through an accessor function) instead.
Review new components for hardcoded values during code review, not just for typos.
Common Mistakes
Hardcoding raw values in components instead of referencing the central token map, defeating the purpose of having tokens at all.
Building an overly deep, many-level-nested token map that becomes tedious to query without helper functions.
Forgetting that Sass tokens never reach the browser directly, they need to be output as CSS custom properties if runtime theming is required.
Not validating token lookups, letting a typo'd token name silently return null instead of erroring clearly.
Key Takeaways
Design tokens are named values representing design decisions, colors, spacing, typography, breakpoints.
Sass maps are a natural way to model tokens, especially grouped by category.
A small accessor function improves token lookup readability and can validate token names.
For runtime theming, generate CSS custom properties from your Sass token map.
Pro Tip
Generate your CSS custom properties directly from the same Sass token map you use at compile time, this keeps your design-time and run-time values from ever silently drifting apart as the system evolves.
You now know how to model design tokens with Sass. Next, learn how to structure a responsive architecture that scales across many breakpoints and components.