Sass color.same()

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

Definition and Usage

color.same($color1, $color2) returns a boolean: true when the two colors visually render as the same color. Unlike ==, space differences do not matter when the values match in the xyz color space. Load it with @use "sass:color" on Dart Sass 1.79+. There is no separate global alias.

Official docs also note that missing channels are treated as equivalent to zero.

Official samples.

color.same(#036, #036) → true. color.same(#036, #037) → false. color.same(#036, color.to-space(#036, oklch)) → true. color.same(hsl(none 50% 50%), hsl(0deg 50% 50%)) → true.

Version gate.

Needs Dart Sass 1.79+. Older compilers report Undefined function.

Syntax

SCSS
@use "sass:color";

// Dart Sass 1.79+
color.same(#036, #036);                              // true
color.same(#036, #037);                              // false
color.same(#036, color.to-space(#036, oklch));       // true
color.same(hsl(none 50% 50%), hsl(0deg 50% 50%));    // true

// Module only — no separate global same()

Pattern: after converting tokens with color.to-space(), compare them with color.same instead of ==.

color.same vs ==

Side-by-side mapping:

CheckWhat it asks
color.same($a, $b)Do these visually match in xyz (even across spaces)?
$a == $bAre these the same Sass color value/representation?
Missing channelscolor.same treats them like zero
Hex vs oklch of same navycolor.same → true; == may still disagree
When to prefer same.

Theme audits, token migrations, and post-to-space checks where look matters more than the written space.

SCSS Examples

Examples target Dart Sass 1.79+. Booleans are interpolated into custom properties so you can open View Compiled CSS. @debug lines print to the compiler terminal / log.

Example 1 — Identical Hex Is true (Official Docs)

The simplest visual match: the same navy twice.

SCSS
@use "sass:color";

@debug color.same(#036, #036); // true

.match {
  --same: #{color.same(#036, #036)};
}

How It Works

  1. Both arguments are the same hex navy.
  2. color.same compares them in xyz.
  3. Result is the boolean true.
  4. Interpolation writes that flag into CSS for inspection.

Example 2 — Nearby Hex Is false (Official Docs)

One channel bump is enough to fail visual equality.

SCSS
@use "sass:color";

@debug color.same(#036, #037); // false

.diff {
  --same: #{color.same(#036, #037)};
}

How It Works

  1. #037 is not the same navy as #036.
  2. xyz comparison sees different channel values.
  3. Result is false.
  4. Handy check that your equality helper is not always true.

Example 3 — Hex vs Oklch Still Matches (Official Docs)

Convert with color.to-space — look stays the same.

SCSS
@use "sass:color";

@debug color.same(#036, color.to-space(#036, oklch)); // true

.cross {
  --same: #{color.same(#036, color.to-space(#036, oklch))};
}

How It Works

  1. to-space rewrites the navy into oklch.
  2. Spaces differ, but the color value matches in xyz.
  3. color.same returns true.
  4. == is the wrong tool for this cross-space check.

Example 4 — Missing Hue Counts as Zero (Official Docs)

none and 0deg compare as the same when missing ≡ zero.

SCSS
@use "sass:color";

@debug color.same(hsl(none 50% 50%), hsl(0deg 50% 50%)); // true

.missing {
  --same: #{color.same(hsl(none 50% 50%), hsl(0deg 50% 50%))};
}

How It Works

  1. Missing hue is written none.
  2. Official rule: missing channels count like zero.
  3. 0deg matches that zero hue.
  4. Result is true for visual equality.

Example 5 — Branch When Tokens Match

Use the boolean in a simple if() when building theme flags.

SCSS
@use "sass:color";

$brand: #036;
$converted: color.to-space($brand, oklch);

.report {
  --match: #{if(color.same($brand, $converted), "ok", "drift")};
  --vs-alt: #{if(color.same($brand, #037), "ok", "drift")};
}

How It Works

  1. Converted brand still matches visually → ok.
  2. Nearby hex fails → drift.
  3. Compile-time flags help catch theme mistakes early.
  4. Requires Dart Sass 1.79+ for color.same.

Edge Cases & Pitfalls

Most same() bugs are using == across spaces, old compilers, or expecting string equality.

vs

Do not use == for cross-space look

Hex and oklch of the same navy may fail == even when color.same is true.

version

Needs Dart Sass 1.79+

Older compilers and LibSass do not provide color.same.

missing

Missing channels count as zero

none is not a separate visual value for this helper — it matches zero.

module

No global same()

Always @use "sass:color" and call color.same.

Sass Support

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

APIStatus
color.same()Dart Sass 1.79+
Global same()Not provided
LibSass / Ruby SassUnsupported
BrowsersN/A — only see compiled boolean / CSS values

Compile with the Dart Sass CLI.

Key Takeaways

  • Visual equality via the xyz color space.
  • Better than == when spaces differ after to-space.
  • Missing channels count as zero.
  • Module only on Dart Sass 1.79+ — no global same().

One line: use color.same when you care whether two tokens look the same — not whether they were written in the same space.

Compile Notes

Practical checklist:

checklist.txt
1. Require Dart Sass 1.79+
2. @use "sass:color"
3. Prefer color.same($a, $b) over == for cross-space look
4. Remember missing channels count as zero
5. Pair with color.to-space() when migrating spaces

Frequently Asked Questions

color.same($color1, $color2) returns true if the two colors visually render as the same color. Example: color.same(#036, #036) is true; color.same(#036, #037) is false.
The == operator compares Sass color values more strictly by representation. color.same() treats colors as equal when they match in the xyz color space—even if one is hex and the other is oklch.
color.same() needs Dart Sass 1.79+. Older compilers report Undefined function.
Official docs: missing channels are treated as equivalent to zero. That is why color.same(hsl(none 50% 50%), hsl(0deg 50% 50%)) is true.
Use it when comparing tokens that may live in different spaces after color.to-space(), or when none / missing channels should count as zero for visual equality.
No. Use the module form color.same() after @use "sass:color".

Next: Sass color.scale()

Scale channels relatively toward their bounds.

color.scale() →

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