color.to-gamut() belongs to the built-in sass:color module. It maps a color into the gamut (displayable range) of a target space while keeping a visually similar result. This page covers mandatory $method (local-minde vs clip), optional $space, the Dart Sass 1.79+ requirement, and five examples.
01
Concept
Gamut mapping
02
Module
@use "sass:color"
03
Method
Mandatory
04
Options
local-minde / clip
05
Space
Optional $space
06
Practice
5 examples
Concept
What Is color.to-gamut()?
Gamut means “the colors this space can actually show.” A vivid oklch accent can sit outside the smaller rgb (sRGB) gamut. Official docs: to-gamut returns a visually similar color that fits the gamut of $space. If the color is already in-gamut, it is returned unchanged. The result always stays in $color’s original space.
Think of squeezing a wide-gamut paint chip onto an sRGB monitor. You keep the hue feeling as close as possible, but you pull chroma back until it fits.
Foundation
📝 Syntax
Load the color module, then pass a color, optional space, and a required method:
The color to map (required). Result stays in this color’s space.
$space
Unquoted string
Gamut to map into (defaults to $color’s space), e.g. rgb, display-p3.
$method
Unquoted string
Required.local-minde (CSS Colors 4 recommendation) or clip.
Return value
Type
Meaning
Color
A visually similar in-gamut color in $color’s original space (or the original color if already in-gamut).
Modules
📦 Loading sass:color
There is no separate global to-gamut() built-in. Use the module form on Dart Sass 1.79+.
styles.scss
// Recommended — namespaced (Dart Sass 1.79+)
@use "sass:color";
$safe: color.to-gamut(#036, $method: local-minde);
// Optional — bring members into the current namespace
@use "sass:color" as *;
$safe: to-gamut(#036, $method: local-minde);
// Optional — custom namespace
@use "sass:color" as c;
$safe: c.to-gamut(#036, $method: local-minde);
⚠️
Version gate
If Dart Sass reports Undefined function for color.to-gamut, upgrade to 1.79+. Always pass $method.
Methods
⚖️ local-minde vs clip
Official docs describe two mapping strategies. Prefer local-minde for most design work unless you specifically want hard channel clamping.
Method
How it works
When to use
local-minde
CSS Colors 4 recommendation: binary-searches Oklch chroma until a clipped-to-gamut match is as close as possible to the reduced-chroma variant.
Default choice for perceptual mapping
clip
Clamps each channel to the gamut minimum or maximum when out of range.
Simple hard limits / comparisons
⚠️
Heads up from the docs
The CSS working group and browser vendors are still discussing the recommended gamut-mapping algorithm. Until they settle, Sass keeps $methodmandatory so a future default can match CSS.
Compare
📋 to-gamut vs to-space
These helpers often work together, but they do different jobs.
Helper
Job
Space of the result
color.to-gamut()
Keep similar look; fit a target gamut
Same as input $color
color.to-space()
Convert into another color space
The destination $space
💡
Official pairing
Docs note that to-space into a narrower gamut can leave you with 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—no color.to-gamut() call remains.
Feature
Dart Sass
Notes
color.to-gamut()
1.79+
$method mandatory (local-minde / clip)
Related color.to-space()
1.79+
May produce out-of-gamut results; pair with to-gamut
The mapped accent remains an oklch value (input space), but it now fits the rgb gamut for safer shipping to sRGB-first UIs. The hex border is already in-gamut, so it passes through.
After to-space — convert, then gamut-map when the destination is narrower.
Method A/B checks — compare local-minde vs clip for critical brand hues.
Print / screen handoff — pull colors into a known gamut before export.
Teaching color spaces — show that space conversion and gamut mapping are different steps.
🧠 How Compilation Works
1
Write SCSS
Call color.to-gamut($c, $method: …) after @use.
Source
2
Pick gamut + method
Choose $space (optional) and required local-minde or clip.
Method
3
Map or pass through
Already in-gamut colors stay put; others get a similar in-gamut twin.
Map
4
✓
Color ships in original space
Browsers receive a finished color—still in $color’s space.
Watch Out
⚠️ Common Pitfalls
Omitting $method — it is mandatory; Sass will not guess until CSS settles a default.
Expecting a space change — to-gamut keeps the input space; use to-space to convert.
Assuming methods match — local-minde and clip can produce different mapped colors.
Calling on older Dart Sass — needs 1.79+; expect Undefined function earlier.
Looking for a global to-gamut() — there is none; use the module form.
Pro Tips
💡 Best Practices
✅ Do
Use @use "sass:color" and color.to-gamut() on Dart Sass 1.79+
Prefer $method: local-minde for perceptual mapping
Pass $space: rgb when preparing sRGB-first CSS
Keep one method consistent across a token set
Pair with to-space when you also need a space conversion
❌ Don’t
Expect the browser to re-run color.to-gamut
Skip $method hoping for a default
Mix clip and local-minde randomly in one theme
Assume LibSass/Ruby Sass support this API
Confuse gamut mapping with changing the color space name
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about color.to-gamut()
Fit a gamut, keep the space, always pass $method.
5
Core concepts
📝01
Call
to-gamut($c, …)
API
📦02
Module
sass:color
@use
🎨03
Does
gamut mapping
Fit
⚡04
Method
mandatory
Required
✓05
Needs
Dart Sass 1.79+
Version
❓ Frequently Asked Questions
color.to-gamut($color, $space: null, $method: null) returns a visually similar color that fits the gamut of $space. If the color is already in-gamut, it is returned as-is. Example: color.to-gamut(#036, $method: local-minde) is #036.
Official docs: the CSS working group is still discussing the recommended gamut-mapping algorithm. Until that settles, Sass makes $method mandatory so a future default can match CSS. Pass local-minde or clip.
local-minde is the CSS Colors 4 recommended method (binary search in Oklch chroma). clip simply clamps each channel to the gamut min/max.
No. It always returns a color in $color’s original space. $space only chooses which gamut to map into.
No. Use the module form color.to-gamut() after @use "sass:color".
Did you know?
Official Sass docs keep $method mandatory on purpose: once CSS picks a default gamut-mapping algorithm, Sass can adopt the same default without silently changing old stylesheets that never declared a method.
color.to-gamut() is the gamut-mapping helper for modern Sass colors. Pass a mandatory $method, optionally target a gamut with $space, and remember the result stays in the input color’s space—on Dart Sass 1.79+.