Sass·Sass from variables to a design system

Variables and tokens

Store colours, spacing and type values in one place.

Intermediate 12 min read Lesson 2 of 300 Challenge included
What you will be able to do
  • Use $name for Sass variables.
  • Group tokens by role.
  • Use maps for spacing and type scales.
  • Use CSS variables for runtime themes.

In plain English

Variables make design decisions reusable. Group them by role, not by value, and prefer maps for scales. CSS custom properties are still the right tool for runtime theming.

tokens.scssSCSS
$brand: #2f74c0;
$space: (sm: 8px, md: 16px, lg: 24px);
$radius: 12px;

.card {
  padding: map-get($space, md);
  border-radius: $radius;
  color: $brand;
}
Your turn

Create a token

Easy

Create a $brand variable and use it as a colour.

SCSS · starter
$brand: #2f74c0;
Check your understanding before moving on.
Knowledge checkQuestion 1

Which prefix declares a Sass variable?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Next: Nesting
Lesson 2 of 300 · 0% of course