Sass color.to-gamut()

Intermediate
12 min read
Updated: Nov 2026
5 examples
Dart Sass 1.79+

Definition and Usage

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

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.

Methods & $space

Official method choices:

ArgumentMeaning
$method: local-mindeCSS Colors 4 recommended path — search Oklch chroma for a close in-gamut color
$method: clipClamp each channel to the gamut min/max
$spaceUnquoted space whose gamut you map into (default: the color’s own space)
Return spaceAlways $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.

SCSS Examples

Examples target Dart Sass 1.79+. Open View Compiled CSS for verified output (matches official Sass docs samples where noted).

Example 1 — Already In-Gamut Returns As-Is (Official Docs)

A normal hex navy needs no mapping.

SCSS
@use "sass:color";

@debug color.to-gamut(#036, $method: local-minde); // #036

.navy {
  color: color.to-gamut(#036, $method: local-minde);
}

How It Works

  1. #036 already fits the sRGB gamut.
  2. $method is still required even when nothing changes.
  3. Result is the same navy.
  4. Safe no-op when auditing mixed palettes.

Example 2 — Wide Oklch → RGB Gamut with local-minde

Official docs sample: map extreme chroma into the rgb gamut.

SCSS
@use "sass:color";

@debug color.to-gamut(oklch(60% 70% 20deg), $space: rgb, $method: local-minde);
// oklch(~61.2% ~0.247 ~22deg)

.accent {
  color: color.to-gamut(oklch(60% 70% 20deg), $space: rgb, $method: local-minde);
}

How It Works

  1. Input is written in oklch with huge chroma.
  2. $space: rgb chooses the sRGB gamut to fit.
  3. local-minde searches for a close in-gamut color.
  4. Result stays oklch — only the values move into gamut.

Example 3 — Same Color with clip (Official Docs)

Clipping is simpler and can look different from local-minde.

SCSS
@use "sass:color";

@debug color.to-gamut(oklch(60% 70% 20deg), $space: rgb, $method: clip);
// oklch(~62.5% ~0.253 ~24deg)

.accent {
  color: color.to-gamut(oklch(60% 70% 20deg), $space: rgb, $method: clip);
}

How It Works

  1. Same wide input as Example 2.
  2. clip clamps channels to the gamut bounds.
  3. Hue / chroma / lightness can land differently than local-minde.
  4. Prefer local-minde when following CSS Colors 4 guidance.

Example 4 — Side-by-Side Method Report

Store both mappings so design review can pick a look.

SCSS
@use "sass:color";

$wide: oklch(60% 70% 20deg);

.report {
  --minde: #{color.to-gamut($wide, $space: rgb, $method: local-minde)};
  --clip: #{color.to-gamut($wide, $space: rgb, $method: clip)};
}

How It Works

  1. One wide token, two methods.
  2. Custom properties keep both results for comparison.
  3. Neither rewrite changes the color’s space name (oklch).
  4. Pick one method for production tokens.

Example 5 — Convert, Then Gamut-Map

Pair with to-space when you need a different writing space too.

SCSS
@use "sass:color";

$wide: oklch(60% 70% 20deg);
$mapped: color.to-gamut($wide, $space: rgb, $method: local-minde);
$as-rgb: color.to-space($mapped, rgb);

.safe {
  --oklch: #{$mapped};
  --rgb: #{$as-rgb};
}

How It Works

  1. First pull the color into the rgb gamut while staying in oklch.
  2. Then optionally rewrite with to-space(..., rgb).
  3. Order matters: gamut-map before emitting legacy CSS when needed.
  4. Requires Dart Sass 1.79+ for both helpers.

Edge Cases & Pitfalls

Most to-gamut bugs are missing $method, confusing $space with return space, or expecting to-space behavior.

method

$method is mandatory

Always pass local-minde or clip. Leaving it out errors by design.

space

$space is the gamut, not the rewrite

The returned color stays in the original space. Use to-space when you need a different writing format.

string

Pass unquoted space names

Write $space: rgb / display-p3 — unquoted, matching CSS.

module

No global to-gamut()

Always @use "sass:color" on Dart Sass 1.79+.

Sass Support

color.to-gamut() is a modern module helper. Prefer Dart Sass 1.79+ with @use "sass:color".

APIStatus
color.to-gamut()Dart Sass 1.79+
$methodRequired: local-minde or clip
Global to-gamut()Not provided
LibSass / Ruby SassUnsupported

Compile with the Dart Sass CLI.

Key Takeaways

  • 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.

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.
color.to-gamut() needs Dart Sass 1.79+. Older compilers report Undefined function.
No. Use the module form color.to-gamut() after @use "sass:color".

Next: Sass color.to-space()

Convert a color into another writing space.

color.to-space() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful