color.to-gamut() returns a visually similar color that fits the gamut of $space (defaults to $color’s own space). If the color is already in-gamut, it is returned as-is. The result always stays in $color’s original space. Load it with @use "sass:color" on Dart Sass 1.79+.
Official docs: $method is mandatory (local-minde or clip) until CSS settles a default algorithm. There is no separate global alias.
Official samples.
color.to-gamut(#036, $method: local-minde) → #036 (already in gamut). Wide oklch(60% 70% 20deg) mapped into the rgb gamut differs for local-minde vs clip.
Always pass $method.
Omitting it is an error on purpose so Sass can later default to whatever CSS chooses.
Syntax
Syntax
SCSS
@use "sass:color";
// Dart Sass 1.79+ — $method is required
color.to-gamut(#036, $method: local-minde);
color.to-gamut(
oklch(60% 70% 20deg),
$space: rgb,
$method: local-minde
);
color.to-gamut(
oklch(60% 70% 20deg),
$space: rgb,
$method: clip
);
// Module only — no separate global to-gamut()
Pattern: convert wide-gamut tokens with color.to-space() when needed → map into a display gamut with to-gamut.
Reference
Methods & $space
Official method choices:
Argument
Meaning
$method: local-minde
CSS Colors 4 recommended path — search Oklch chroma for a close in-gamut color
$method: clip
Clamp each channel to the gamut min/max
$space
Unquoted space whose gamut you map into (default: the color’s own space)
Return space
Always $color’s original space — not necessarily $space
to-gamut vs to-space.
to-space changes the writing space (and may leave values out-of-gamut). to-gamut keeps the writing space and pulls channels into a chosen gamut.
Maps into a gamut while keeping the original color space.
$method is required — prefer local-minde for CSS Colors 4 guidance.
Use to-space when you also need a different writing space.
Module only on Dart Sass 1.79+ — no global to-gamut().
One line: when a wide-gamut token must fit a display gamut, call color.to-gamut with an explicit method.
Practice
Compile Notes
Practical checklist:
checklist.txt
1. Require Dart Sass 1.79+
2. @use "sass:color"
3. Always pass $method: local-minde or clip
4. Pass $space for the target gamut (unquoted)
5. Use color.to-space() only when you also need a new writing space
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.