Sass
CSS preprocessor

Sass color.same() Function

Beginner
⏱️ 12 min read
📚 Updated: Jul 2026
🎯 5 Examples
sass:color · Dart Sass 1.79+

What You’ll Learn

color.same() belongs to the built-in sass:color module. It answers: do these two colors look the same when painted? This page covers visual equality in xyz, how it differs from ==, missing channels treated as zero, the Dart Sass 1.79+ requirement, and five examples.

01

Concept

Visual equality

02

Module

@use "sass:color"

03

Space

Compares in xyz

04

Vs

== operator

05

Missing

Treated as zero

06

Practice

5 examples

What Is color.same()?

Same means “these would paint identically,” not “these are written the same way in SCSS.” Official docs return whether $color1 and $color2 visually render as the same color. A hex brand and its color.to-space(..., oklch) twin can still be same.

  • 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
💡
Beginner tip

Reach for same after space conversions or when tokens may include none / missing channels. Reach for == when you care that the Sass values are identical as written/stored.

📝 Syntax

Load the color module, then pass two colors:

styles.scss
@use "sass:color";

// Dart Sass 1.79+
color.same($color1, $color2)

Parameters

ParameterTypeDescription
$color1ColorFirst color to compare (required).
$color2ColorSecond color to compare (required).

Return value

TypeMeaning
Booleantrue if both colors visually render the same; otherwise false.

📦 Loading sass:color

There is no separate global same() built-in. Use the module form on Dart Sass 1.79+.

styles.scss
// Recommended — namespaced (Dart Sass 1.79+)
@use "sass:color";
$ok: color.same(#036, #036);

// Optional — bring members into the current namespace
@use "sass:color" as *;
$ok: same(#036, #036);

// Optional — custom namespace
@use "sass:color" as c;
$ok: c.same(#036, #036);
⚠️
Version gate

If Dart Sass reports Undefined function for color.same, upgrade to 1.79+.

🎨 How Visual Equality Works

Official docs: colors are equivalent when they represent the same color value in the xyz color space—even if they live in different spaces in your SCSS.

Situationcolor.same()
Identical hextrue
Nearby but different hex (#036 vs #037)false
Same paint, different space (hex vs oklch via to-space)true
Missing channel vs zero (e.g. hsl(none …) vs 0deg)true (missing ≡ zero)

📋 color.same() vs ==

Both return booleans, but they answer different questions.

CheckQuestionTypical case
color.same($a, $b)Would these look the same when painted?Hex brand vs its oklch twin after to-space
$a == $bAre these the same Sass color value / representation?Strict token identity in one space
💡
Official guidance

Docs call out that same is unlike ==: different spaces can still be visually equal when their xyz values match.

🛠 Compatibility

This is about Sass compilers, not browsers. The boolean is resolved at compile time—CSS never sees a color.same() call.

FeatureDart SassNotes
color.same()1.79+Part of the modern color-spaces work
Related color.to-space()1.79+Often used to produce cross-space twins for comparison
LibSass / Ruby SassNo modern module color-space API

⚡ Quick Reference

GoalCode
Import color@use "sass:color";
Identical hexcolor.same(#036, #036)true
Different hexcolor.same(#036, #037)false
Cross-space twincolor.same(#036, color.to-space(#036, oklch))true
Missing ≡ zerocolor.same(hsl(none 50% 50%), hsl(0deg 50% 50%))true
Branch in SCSSif(color.same($a, $b), …, …)

Examples Gallery

Examples target Dart Sass 1.79+. Open View Compiled CSS to see the booleans Sass emits (official docs results).

📚 Getting Started

Official docs samples for identical, different, and cross-space colors.

Example 1 — Identical vs Nearby Hex

Exact match is true; a one-step hex change is false (official docs).

styles.scss
@use "sass:color";

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

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

How It Works

Visual equality is exact for these solid colors. #037 is close to #036 but not the same paint.

Example 2 — Same Paint in a Different Space

Hex vs oklch twin via color.to-space() (official docs).

styles.scss
@use "sass:color";

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

@debug color.same($brand, $brand-oklch); // true

.report {
  --cross-space: #{color.same($brand, $brand-oklch)};
}

How It Works

Converting to oklch changes how the color is stored, not what it looks like. same compares in xyz, so the twin still matches.

📈 Practical Patterns

Missing channels, mixin guards, and same vs ==.

Example 3 — Missing Channel Treated as Zero

none hue vs 0deg counts as the same (official docs).

styles.scss
@use "sass:color";

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

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

How It Works

Official docs: missing channels are treated as equivalent to zero for same. That keeps visual comparisons predictable when CSS none shows up after conversions.

Example 4 — Guard Duplicate Tokens

Skip emitting a second custom property when two tokens already match visually.

styles.scss
@use "sass:color";

@mixin token-note($a, $b) {
  &::after {
    content: if(
      color.same($a, $b),
      "same",
      "different"
    );
  }
}

.pair-match {
  @include token-note(#036, #036);
}

.pair-diff {
  @include token-note(#036, #037);
}

How It Works

Real design-system mixins might omit a redundant CSS variable or warn when two “different” names secretly paint the same.

Example 5 — Prefer same After Space Conversion

Cross-space twins: use visual equality when you care about the painted result.

styles.scss
@use "sass:color";

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

.compare {
  // Visual equality across spaces
  --same: #{color.same($hex, $oklch)};

  // Strict Sass equality may disagree after to-space
  // Prefer color.same() when "looks the same" is the goal
  --still-same-paint: #{color.same($hex, $oklch)};
}

How It Works

After to-space, you often care whether the UI still shows the same brand color. Official docs recommend same for that visual check instead of relying only on ==.

🚀 Real-World Use Cases

  • Token dedupe — detect when two named tokens already paint identically.
  • Space migrations — assert a hex brand matches its oklch twin after to-space.
  • Mixin guards — skip redundant CSS custom properties.
  • Missing-channel safety — treat none like zero for visual checks.
  • Theme audits — flag “different” names that secretly share the same paint.
  • Teaching color spaces — show representation vs appearance.

🧠 How Compilation Works

1

Write SCSS

Call color.same($a, $b) after @use.

Source
2

Normalize missing

Treat missing channels as zero for the comparison.

Channels
3

Compare in xyz

Check whether both colors share the same xyz value.

Visual
4

Boolean ships in CSS

Browsers receive true/false—not a Sass call.

⚠️ Common Pitfalls

  • Using only == after to-space — representation can differ while paint matches; prefer same for visual checks.
  • Assuming near hexes match#036 and #037 are different colors.
  • Calling on older Dart Sass — needs 1.79+; expect Undefined function earlier.
  • Looking for a global same() — there is none; use the module form.
  • Forgetting missing ≡ zeronone can make same return true against a zero channel.

💡 Best Practices

✅ Do

  • Use @use "sass:color" and color.same() on Dart Sass 1.79+
  • Prefer same when comparing across spaces
  • Pair with color.to-space() during migrations
  • Document whether a check is visual or representational
  • Upgrade the compiler before shipping modern color helpers

❌ Don’t

  • Expect the browser to re-run color.same
  • Treat same and == as interchangeable
  • Assume LibSass/Ruby Sass support this API
  • Ignore Undefined function errors—upgrade instead
  • Compare colors without clarifying visual vs stored equality

Key Takeaways

Knowledge Unlocked

Five things to remember about color.same()

Visual equality in xyz—not the same as ==.

5
Core concepts
📦 02

Module

sass:color

@use
🎨 03

Does

visual equality

xyz
04

Unlike

== operator

Strict
05

Needs

Dart Sass 1.79+

Version

❓ 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".
Did you know?

Official Sass docs compare colors in the xyz space for color.same(). That is why a hex token and its color.to-space(..., oklch) twin can still report true—the paint matches even when the SCSS representations do not.

Conclusion

color.same() is the visual equality check for modern Sass colors. Use it when tokens may live in different spaces, when missing channels should count as zero, and when == would be too strict—on Dart Sass 1.79+.

Continue with color.scale(), color.adjust(), or the CSS introduction.

Explore color.scale() Next

Fluidly scale color channels by percentage with the sass:color module.

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

5 people found this page helpful