color.to-space() belongs to the built-in sass:color module. It converts a color into another color space. This page covers unquoted $space names, missing channels, how it differs from to-gamut, the Dart Sass 1.79+ requirement, and five examples.
01
Concept
Space conversion
02
Module
@use "sass:color"
03
$space
Unquoted name
04
Unique
Changes space
05
Vs
to-gamut()
06
Practice
5 examples
Concept
What Is color.to-space()?
To-space means “rewrite this color in another coordinate system.” Official docs: converts $color into the given $space. A hex brand can become oklch, hsl, or display-p3 while usually keeping the same paint. Official fun fact: this is the only Sass color function that returns a color in a different space than the one passed in.
Most other helpers (adjust, scale, mix) change channels but return a color in the same space you started with. Use to-space when you explicitly want the space itself to change.
Foundation
📝 Syntax
Load the color module, then pass a color and an unquoted destination space:
Destination space name, e.g. oklch, hsl, display-p3, lch, rgb.
Return value
Type
Meaning
Color
The same paint (when possible) expressed in $space. May be out-of-gamut for narrower destinations.
Modules
📦 Loading sass:color
There is no separate global to-space() built-in. Use the module form on Dart Sass 1.79+.
styles.scss
// Recommended — namespaced (Dart Sass 1.79+)
@use "sass:color";
$ok: color.to-space(#036, oklch);
// Optional — bring members into the current namespace
@use "sass:color" as *;
$ok: to-space(#036, oklch);
// Optional — custom namespace
@use "sass:color" as c;
$ok: c.to-space(#036, oklch);
⚠️
Version gate
If Dart Sass reports Undefined function for color.to-space, upgrade to 1.79+.
Details
🎨 Missing Channels & Legacy Destinations
Official docs call out two important behaviors:
Conversion can produce missing channels when the source already has a missing analogous channel, or when a channel is powerless in the destination (for example grey → lch with hue none).
When $space is a legacy space (rgb / hsl / hwb), Sass never invents a new missing channel—so the result stays compatible with older browsers.
Compare
📋 to-space vs to-gamut
These helpers often travel together, but they answer different needs.
Helper
Job
Space of the result
color.to-space()
Convert into another color space
The destination $space
color.to-gamut()
Fit a target gamut with a similar look
Same as the input color
💡
Official pairing
Docs note that converting into a narrower gamut with to-space can leave an out-of-gamut color. Follow with to-gamut when you need an in-gamut twin.
Support
🛠 Compatibility
This is about Sass compilers, not browsers. Compiled CSS receives a finished color in the destination space—no color.to-space() call remains.
Feature
Dart Sass
Notes
color.to-space()
1.79+
Only color helper that changes the returned space
Related color.space()
1.79+
Read the space name after conversion
Related color.to-gamut()
1.79+
Map out-of-gamut results after conversion
LibSass / Ruby Sass
✗
No modern module color-space API
Cheat Sheet
⚡ Quick Reference
Goal
Code
Import color
@use "sass:color";
Hex → oklch
color.to-space(#036, oklch)
Hex → display-p3
color.to-space(#036, display-p3)
Grey → lch
color.to-space(grey, lch)
Check new space
color.space(color.to-space($c, oklch))
Visual equality
color.same($c, color.to-space($c, oklch))
Hands-On
Examples Gallery
Examples target Dart Sass 1.79+. Open View Compiled CSS to see converted colors (verified against modern Dart Sass; official docs samples noted).
📚 Getting Started
Convert a hex brand into modern and legacy spaces.
Example 1 — Hex Brand into Oklch, HSL, and Display P3
Each conversion keeps the brand look while changing how channels are stored. display-p3 is useful for wide-gamut monitors; oklch is great for perceptual adjustments afterward.
In LCH, a grey has no chroma, so hue is powerless and may be represented as none. Pair with color.is-missing() when you need a boolean check for that hue.
📈 Practical Patterns
Missing-channel carryover, space checks, and gamut follow-up.
Example 3 — Missing Channels Can Carry Across Spaces
Official docs sample: lch(none …) into oklch keeps missing lightness.
Analogous missing channels travel with the conversion. That is useful for CSS relative-color workflows, and surprising if you expected every channel to become a concrete number.
Example 4 — Confirm Space Change + Visual Equality
to-space(..., rgb) changes the stored space to rgb. to-gamut keeps the original oklch space while fitting the rgb gamut—two different tools for two different goals.
Applications
🚀 Real-World Use Cases
Token migrations — move hex brands into oklch for perceptual edits.
Wide-gamut export — convert into display-p3 for modern displays.
Legacy output — convert into rgb / hsl before emitting older CSS.
Audit pipelines — pair with space and same after conversion.
Missing-channel workflows — preserve or detect none after space changes.
Teaching color spaces — show that space conversion is not gamut mapping.
🧠 How Compilation Works
1
Write SCSS
Call color.to-space($c, oklch) after @use.
Source
2
Pick destination
Pass an unquoted space name such as display-p3 or hsl.
Space
3
Convert channels
Sass rewrites the color into the destination coordinates.
Convert
4
✓
New-space color ships
CSS receives oklch / hsl / display-p3—not a Sass call.
Watch Out
⚠️ Common Pitfalls
Quoting the space name — pass oklch, not "oklch".
Confusing with to-gamut — conversion changes space; gamut mapping keeps the input space.
Assuming every conversion is in-gamut — narrower destinations may need to-gamut.
Surprise none channels — greys and powerless channels can become missing.
Calling on older Dart Sass — needs 1.79+; expect Undefined function earlier.
Pro Tips
💡 Best Practices
✅ Do
Use @use "sass:color" and color.to-space() on Dart Sass 1.79+
Verify with color.space() and color.same() during migrations
Convert to oklch before perceptual channel edits
Follow with to-gamut when targeting a narrower gamut
Document which space each design token is supposed to live in
❌ Don’t
Expect the browser to re-run color.to-space
Treat space conversion as automatic gamut safety
Quote space names
Assume LibSass/Ruby Sass support this API
Ignore missing-channel results on greys and powerless hues
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about color.to-space()
Explicit space conversion—the only helper that changes the returned space.
5
Core concepts
📝01
Call
to-space($c, $space)
API
📦02
Module
sass:color
@use
🎨03
Does
change color space
Convert
⚡04
$space
unquoted name
Arg
✓05
Needs
Dart Sass 1.79+
Version
❓ Frequently Asked Questions
color.to-space($color, $space) converts a color into another color space. Example: color.to-space(#036, oklch) returns an oklch color that paints like #036.
Pass an unquoted space name such as oklch, hsl, display-p3, lch, or rgb.
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 you out-of-gamut—use color.to-gamut() afterward if needed.
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.
No. Use the module form color.to-space() after @use "sass:color".
Did you know?
Official Sass docs call color.to-space() the only color function that returns a color in a different space than the one passed in. Every other modern color helper keeps the original space on the way out—even when it temporarily computes in another space.
color.to-space() is the explicit space converter for modern Sass colors. Use it to migrate tokens, unlock perceptual spaces, and pair with to-gamut when the destination gamut is narrower—on Dart Sass 1.79+.