color.to-space($color, $space) converts a color into another writing space. $space must be an unquoted name such as oklch, hsl, or display-p3. Load it with @use "sass:color" on Dart Sass 1.79+.
Official fun fact: this is the only Sass color function that returns a color in a different space than the one passed in. Paint usually stays the same — check with color.same().
If the destination gamut is narrower, the result can sit outside that gamut. Pair with color.to-gamut() when you need an in-gamut neighbor.
Syntax
Syntax
SCSS
@use "sass:color";
// Dart Sass 1.79+ — $space is an unquoted name
color.to-space(#036, oklch);
color.to-space(#036, display-p3);
color.to-space(#036, hsl);
color.to-space(grey, lch);
// Module only — no separate global to-space()
Pattern: convert with to-space for a preferred writing format → map with to-gamut when the destination gamut is too small.
Reference
Space & Gamut
How conversion behaves:
Idea
Meaning
$space
Unquoted destination name (oklch, rgb, display-p3, …)
Return space
Always the requested $space — unlike to-gamut
Missing channels
May appear when source is missing or destination channel is powerless
Legacy destinations
Never invent a new missing channel (older-browser-safe)
Narrower gamut
Result can be out-of-gamut — follow with to-gamut if needed
to-space vs to-gamut.
to-space rewrites the space name. to-gamut keeps the writing space and only pulls values into a chosen gamut.
Rewrites the writing space — the only Sass color helper that changes space.
Pass unquoted names like oklch and display-p3.
Use to-gamut when a narrower gamut leaves values out of range.
Module only on Dart Sass 1.79+ — no global to-space().
One line: when you need a color stored in another space, call color.to-space($color, $space).
Practice
Compile Notes
Practical checklist:
checklist.txt
1. Require Dart Sass 1.79+
2. @use "sass:color"
3. Pass an unquoted $space (oklch, hsl, display-p3, …)
4. Verify paint with color.same() when needed
5. Follow with color.to-gamut() if the destination gamut is too narrow
Frequently Asked Questions
color.to-space($color, $space) converts a color into another color space. $space must be an unquoted name like oklch or display-p3. Example: color.to-space(#036, oklch) returns an oklch color that paints like #036.
Usually the color looks the same, just stored differently. color.same(#036, color.to-space(#036, oklch)) is true. A narrower destination gamut can leave values out-of-gamut — use color.to-gamut() afterward if needed.
to-space changes the writing space. to-gamut keeps the writing space and maps channels into a chosen gamut. Official fun fact: to-space is the only Sass color function that returns a color in a different space than the one passed in.
to-space can produce missing channels when a channel is missing on the source or powerless in the destination. Converting into a legacy space never invents a new missing channel.