Sass·Sass from variables to a design system

Functions and operators

Compute values with colour functions, maps and arithmetic.

Intermediate 13 min read Lesson 6 of 300 Challenge included
What you will be able to do
  • Use lighten/darken carefully; prefer colour spaces.
  • Use map-get to read token maps.
  • Use math.div for division.
  • Write @function for reusable calculations.

In plain English

Sass functions transform values at build time. Colour functions adjust lightness and alpha; map functions read scales; math functions compute spacing. Use @function for your own calculations.

functions.scssSCSS
@use "sass:map";
@use "sass:math";

$space: (sm: 8px, md: 16px);

@function space($key) {
  @return map.get($space, $key);
}

.card { padding: space(md); }
Your turn

Read a map value

Easy

Return the md value from a $space map.

SCSS · starter
@function space($key) {
Check your understanding before moving on.
Knowledge checkQuestion 1

Which module provides map.get?

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: Control flow
Lesson 6 of 300 · 0% of course