Sass Colors

Beginner
⏱️ 15 min read
📚 Updated: Jul 2026
🎯 5 Examples
Hex, HSL & more

What You’ll Learn

Sass colors represent a point in a color space—just like CSS. This page covers writing colors, legacy vs modern spaces, sass:color helpers, alpha, and five compiled examples.

01

Write

Hex / names

02

Spaces

rgb / hsl / …

03

Transform

scale / mix

04

Alpha

Opacity

05

Channels

Read / change

06

Practice

5 examples

What Are Sass Colors?

Official docs: Sass has built-in support for color values. Each color is a point in a particular color space such as rgb or lab. You can write them as:

  • Hex codes — #f2ece4, #b37399aa (with alpha)
  • CSS color names — midnightblue, transparent
  • Functions — rgb(), hsl(), hwb(), and on modern Dart Sass also lab(), oklch(), color()
💡
Beginner tip

Pick one brand color, store it in a variable, then derive tints and shades with sass:color—do not hand-pick twenty almost-identical hex codes.

📝 Syntax

styles.scss
$cream: #f2ece4;
$brand: midnightblue;
$pink: rgb(204, 102, 153);
$violet: hsl(270, 50%, 40%);
$soft: #b37399aa; // 8-digit hex = alpha

🎨 Color Spaces

Official docs: Sass supports the same color spaces as CSS. A color is usually emitted in the space it was written in. Modern wide-gamut spaces (lab, oklch, display-p3, and more) need Dart Sass 1.79+. Older compilers mainly support legacy rgb / hsl (and often hwb).

KindExamples
Legacy*rgb, hsl, hwb
Modern RGB-likesrgb, display-p3, rec2020, …
Perceptuallab, lch, oklab, oklch

Legacy spaces share the classic RGB gamut, so Sass can freely convert between them when emitting CSS. Explicitly pass $space / $method when you use newer color APIs so transforms stay predictable.

❓ Missing & Powerless Channels

Official docs (modern Dart Sass): channels can be written as none when a value is unknown or does not affect rendering—for example hsl(none 0% 50%) because hue does not matter at zero saturation.

  • When mixing colors, a missing channel can take the other color’s value.
  • Converting spaces can preserve analogous none channels.
  • Check with color.is-missing() / color.is-powerless() when available.

🧮 Color Functions

Load @use "sass:color" for helpers that mix colors or scale channels. Official tip: write color spaces as unquoted strings (to match CSS) and channel names as quoted strings so "red" is not parsed as the color red.

styles.scss
@use "sass:color";

$venus: #998099;

$lighter: color.scale($venus, $lightness: 15%);
$blend: color.mix($venus, midnightblue);
$fade: color.change($venus, $alpha: 0.5);
💡
Fun fact

On recent Dart Sass you can scale or mix in a perceptual space like oklch via $space / $method, and Sass still returns a color in the original space unless you call color.to-space().

⚡ Quick Reference

GoalCode
Hex / name#336699 / midnightblue
HSL / HWBhsl(270, 50%, 40%) / hwb(270, 20%, 40%)
Lighten by %color.scale($c, $lightness: 15%)
Blend two colorscolor.mix($a, $b)
Set alphacolor.change($c, $alpha: 0.5)
Read a channelcolor.red($c) / color.hue($c)
Complementcolor.complement($c)

Examples Gallery

Examples use common legacy spaces that compile widely. Open View Compiled CSS for verified output.

📚 Getting Started

Write colors several ways, then transform them with sass:color.

Example 1 — Hex, Names, RGB, HSL & Alpha Hex

Official-docs style literals inspected into custom properties.

styles.scss
@use "sass:meta";

.basics {
  --hex: #{meta.inspect(#f2ece4)};
  --hex-a: #{meta.inspect(#b37399aa)};
  --name: #{meta.inspect(midnightblue)};
  --rgb: #{meta.inspect(rgb(204, 102, 153))};
  --hsl: #{meta.inspect(hsl(270, 50%, 40%))};
}

How It Works

Eight-digit hex expands to rgba(…). Named colors and function forms stay type color either way.

Example 2 — scale, mix, change

Derive related tones from one hex without hand-editing channels.

styles.scss
@use "sass:color";
@use "sass:meta";

$venus: #998099;

.scale-mix {
  --scaled: #{meta.inspect(color.scale($venus, $lightness: 15%))};
  --mixed: #{meta.inspect(color.mix($venus, midnightblue))};
  --alpha: #{meta.inspect(color.change($venus, $alpha: 0.5))};
  --red: #{meta.inspect(color.red($venus))};
}

How It Works

color.scale adjusts relative lightness. color.mix blends two colors. color.change sets absolute channel values such as alpha.

📈 Themes, Channels & Alpha

Build a palette, read HSL parts, and mix with transparency.

Example 3 — One Brand Color → Theme Palette

Generate background, border, and outline tones from a single brand hex.

styles.scss
@use "sass:color";

$brand: #336699;

.theme {
  color: $brand;
  background: color.scale($brand, $lightness: 40%);
  border-color: color.adjust($brand, $saturation: -20%);
  outline-color: color.mix($brand, white, 30%);
}

How It Works

Change $brand once and every derived token updates. Prefer scale / adjust / mix over deprecated lighten() / darken().

Example 4 — Read Channels & Complement

Inspect hue, saturation, lightness, alpha, and the complementary color.

styles.scss
@use "sass:color";
@use "sass:meta";

$base: hsl(200deg, 60%, 45%);

.channels {
  --h: #{meta.inspect(color.hue($base))};
  --s: #{meta.inspect(color.saturation($base))};
  --l: #{meta.inspect(color.lightness($base))};
  --a: #{meta.inspect(color.alpha($base))};
  --type: #{meta.type-of($base)};
  --comp: #{meta.inspect(color.complement($base))};
}

How It Works

Channel helpers return numbers (with units where relevant). color.complement rotates hue by half a turn for a contrasting accent.

Example 5 — Mixing, HWB, Transparent & RGBA

Blend a grey with blue, and show other common alpha-friendly forms.

styles.scss
@use "sass:color";
@use "sass:meta";

$grey: hsl(0, 0%, 50%);

.missing-like {
  --mix: #{meta.inspect(color.mix($grey, blue))};
  --hwb: #{meta.inspect(hwb(270, 20%, 40%))};
  --trans: #{meta.inspect(transparent)};
  --rgba: #{meta.inspect(rgba(179, 115, 153, 0.67))};
}

How It Works

transparent is a color (fully transparent black). hwb() is another legacy-friendly way to express the same RGB gamut.

🚀 Real-World Use Cases

  • Design tokens — one brand hex drives buttons, borders, and surfaces.
  • Hover / active states — scale lightness instead of hard-coding hex.
  • Overlayscolor.change($c, $alpha: …) for translucent layers.
  • Accent pairscolor.complement or mixes with white/black.
  • Theming — swap the root brand color and regenerate the palette.

🧠 How Compilation Works

1

Parse the color

Read hex, name, or function form and its color space.

Parse
2

Transform if needed

Run scale / mix / change in the requested space.

Compute
3

Serialize for CSS

Emit a compatible form (hex, rgb, hsl, hwb, …).

Write
4

CSS ships

Browsers see plain CSS colors—Sass math stays at compile time.

⚠️ Common Pitfalls

  • Using deprecated lighten() / darken() — prefer color.scale / color.adjust.
  • Unquoted channel namesred is a color; use "red" when an API asks for a channel.
  • Assuming every compiler supports oklch/lab — need recent Dart Sass.
  • Mixing strings that look like colors"blue" is a string, not a color.
  • Hand-maintaining huge palettes — derive from one brand token instead.

💡 Best Practices

✅ Do

  • Store brand colors in variables
  • Use @use "sass:color" for transforms
  • Prefer color.scale for relative lighten/darken
  • Quote channel names; leave spaces unquoted when APIs ask for them
  • Keep a small set of source tokens and derive the rest

❌ Don’t

  • Rely on global darken() / lighten() in new code
  • Paste dozens of near-duplicate hex values
  • Pass color names where a quoted channel string is required
  • Assume wide-gamut spaces work on every Sass version
  • Forget alpha when you need translucent overlays

Key Takeaways

Knowledge Unlocked

Five things to remember about Sass colors

Write clearly, transform with sass:color, and derive palettes from tokens.

5
Core concepts
🔄 02

Spaces

legacy + modern

Model
🧮 03

sass:color

scale / mix

API
👁️ 04

Alpha

change / hex

Opacity
05

Derive

from one brand

Theme

❓ Frequently Asked Questions

Use hex codes (#f2ece4), CSS color names (midnightblue), or functions like rgb(), hsl(), hwb(), and—on modern Dart Sass—lab(), oklch(), and color().
rgb, hsl, and hwb are legacy spaces that share the classic RGB gamut. Older Sass color functions freely work across these three. Newer spaces need recent Dart Sass.
Load @use "sass:color" and prefer color.scale(), color.mix(), and color.change() over deprecated globals like darken() or lighten().
Channel names like "red" must be quoted so Sass does not parse them as color values. Color spaces should be unquoted strings to match CSS (for example oklch).
Yes on modern Sass: #b37399aa is an 8-digit hex with alpha. Older LibSass may not support that syntax.
Sass can transform in another space internally, but it returns a color in the same space you gave it unless you call color.to-space() (when available).
Did you know?

Official Sass docs note that even when you transform a color in a perceptual space like Oklch, the returned value stays in the original space unless you explicitly convert with color.to-space()—handy for keeping CSS output predictable.

Conclusion

Sass colors are first-class values you can write many ways and reshape with sass:color. Start from clear tokens, prefer modern module helpers, and let the compiler produce the final CSS color forms.

Continue with Sass Lists or color.scale().

Next: Sass Lists

Learn space/comma lists, indexes, append, and @each.

Sass Lists →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful