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
Concept
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.
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).
Kind
Examples
Legacy*
rgb, hsl, hwb
Modern RGB-like
srgb, display-p3, rec2020, …
Perceptual
lab, 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.
Advanced
❓ 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.
Module
🧮 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.
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().
Cheat Sheet
⚡ Quick Reference
Goal
Code
Hex / name
#336699 / midnightblue
HSL / HWB
hsl(270, 50%, 40%) / hwb(270, 20%, 40%)
Lighten by %
color.scale($c, $lightness: 15%)
Blend two colors
color.mix($a, $b)
Set alpha
color.change($c, $alpha: 0.5)
Read a channel
color.red($c) / color.hue($c)
Complement
color.complement($c)
Hands-On
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.
transparent is a color (fully transparent black). hwb() is another legacy-friendly way to express the same RGB gamut.
Applications
🚀 Real-World Use Cases
Design tokens — one brand hex drives buttons, borders, and surfaces.
Hover / active states — scale lightness instead of hard-coding hex.
Overlays — color.change($c, $alpha: …) for translucent layers.
Accent pairs — color.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.
Watch Out
⚠️ Common Pitfalls
Using deprecated lighten() / darken() — prefer color.scale / color.adjust.
Unquoted channel names — red 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.
Pro Tips
💡 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
Summary
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
🎨01
Many forms
hex / hsl / …
Write
🔄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.
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.