Sass color.is-legacy() Function

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

What You’ll Learn

color.is-legacy() belongs to the built-in sass:color module. It answers one boolean question: is this color in a legacy color space? This page covers which spaces count as legacy, why that matters for other color helpers, the Dart Sass 1.79+ requirement, and five examples.

01

Concept

Legacy vs modern

02

Module

@use "sass:color"

03

Legacy

rgb · hsl · hwb

04

Modern

oklch · lab · srgb

05

Needs

Dart Sass 1.79+

06

Practice

5 examples

What Is color.is-legacy()?

is-legacy means “tell me if this color still lives in the old CSS/Sass trio.” Official docs: it returns whether $color is in a legacy color space. That boolean helps when you mix classic hex tokens with modern oklch designs.

  • color.is-legacy(#b37399)true
  • color.is-legacy(hsl(90deg 30% 90%))true
  • color.is-legacy(oklch(70% 10% 120deg))false
💡
Beginner tip

Hex, rgb(), named colors like rebeccapurple, hsl(), and hwb() are legacy. Spaces such as oklch, lab, and color(srgb …) are not.

📝 Syntax

Load the color module, then pass one color:

styles.scss
@use "sass:color";

// Dart Sass 1.79+
color.is-legacy($color)

Parameters

ParameterTypeDescription
$colorColorThe color to inspect (required).

Return value

TypeMeaning
Booleantrue if the color is in rgb, hsl, or hwb; otherwise false.

📦 Loading sass:color

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

styles.scss
// Recommended — namespaced (Dart Sass 1.79+)
@use "sass:color";
$ok: color.is-legacy(#b37399);

// Optional — bring members into the current namespace
@use "sass:color" as *;
$ok: is-legacy(#b37399);

// Optional — custom namespace
@use "sass:color" as c;
$ok: c.is-legacy(#b37399);
⚠️
Version gate

If Dart Sass reports Undefined function for color.is-legacy, upgrade to 1.79+. Older compilers do not include this helper.

🎨 Which Spaces Are Legacy?

Official Sass color documentation treats these three as the legacy spaces. Hex and CSS color names count as rgb.

Spaceis-legacy?Common writings
rgbtrue#b37399, rgb(...), rebeccapurple
hsltruehsl(90deg 30% 90%)
hwbtruehwb(270 20% 40%)
oklch / lab / …falseoklch(70% 10% 120deg)
srgb (modern)falsecolor(srgb 0.4 0.2 0.6) — not the same as legacy rgb

💡 Why Legacy Matters

Legacy colors keep special historical behavior in helpers like color.adjust(), color.change(), and color.complement()—for example flexible channel mixing across rgb/hsl/hwb and optional $space defaults. Modern colors usually require explicit spaces and stricter channel rules.

SituationHow is-legacy helps
Migrating a palette to oklchFlag which tokens still need legacy-friendly helpers
Writing shared mixinsBranch: pass $space for modern colors, keep defaults for hex
Debugging channel errorsConfirm whether Sass is treating the color as legacy

🛠 Compatibility

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

FeatureDart SassNotes
color.is-legacy()1.79+Part of the modern color-spaces work
Related color.is-in-gamut()1.79+Sibling boolean about channel bounds
LibSass / Ruby SassNo modern module color-space API

⚡ Quick Reference

GoalCode
Import color@use "sass:color";
Test a hexcolor.is-legacy(#b37399)true
Test HSLcolor.is-legacy(hsl(90deg 30% 90%))true
Test oklchcolor.is-legacy(oklch(70% 10% 120deg))false
Branch in SCSSif(color.is-legacy($c), …, …)

Examples Gallery

Examples target Dart Sass 1.79+. Open View Compiled CSS to see the booleans Sass emits into custom properties or content.

📚 Getting Started

Official docs samples for hex, HSL, and oklch.

Example 1 — Official True / False Trio

Hex and HSL are legacy; oklch is not.

styles.scss
@use "sass:color";

@debug color.is-legacy(#b37399); // true
@debug color.is-legacy(hsl(90deg 30% 90%)); // true
@debug color.is-legacy(oklch(70% 10% 120deg)); // false

.flags {
  --hex: #{color.is-legacy(#b37399)};
  --hsl: #{color.is-legacy(hsl(90deg 30% 90%))};
  --oklch: #{color.is-legacy(oklch(70% 10% 120deg))};
}

How It Works

Hex lives in legacy rgb. The HSL literal is already in legacy hsl. The oklch literal is a modern space, so the flag is false.

Example 2 — Named Colors and HWB

CSS color names and HWB also count as legacy.

styles.scss
@use "sass:color";

.named {
  --purple: #{color.is-legacy(rebeccapurple)};
  --hwb: #{color.is-legacy(hwb(270 20% 40%))};
  --rgb-fn: #{color.is-legacy(rgb(102, 51, 153))};
}

How It Works

Named colors and rgb() map to legacy rgb. hwb() is the third legacy space, so all three flags are true.

📈 Practical Patterns

Modern spaces, mixin guards, and the rgb vs srgb trap.

Example 3 — Modern Spaces Return False

Lab-family and wide-gamut spaces are not legacy.

styles.scss
@use "sass:color";

.modern {
  --oklch: #{color.is-legacy(oklch(70% 10% 120deg))};
  --lab: #{color.is-legacy(lab(50% 20 30))};
  --p3: #{color.is-legacy(color(display-p3 0.7 0.2 0.3))};
}

How It Works

These colors keep their modern spaces. Helpers that assume legacy channel mixing may need an explicit $space when you operate on them.

Example 4 — Guard a Shared Mixin

Branch behavior when a token might be hex or oklch.

styles.scss
@use "sass:color";

@mixin accent-label($c) {
  &::after {
    // Compile-time branch — CSS only keeps the chosen string
    content: if(color.is-legacy($c), "legacy-token", "modern-token");
  }
}

.chip-hex {
  @include accent-label(#336699);
}

.chip-oklch {
  @include accent-label(oklch(60% 0.12 250deg));
}

How It Works

if() runs at compile time. Hex takes the legacy branch; oklch takes the modern branch. Real mixins might choose different adjust/change call shapes instead of labels.

Example 5 — Legacy rgb vs Modern srgb

Similar looking colors, different legacy flags.

styles.scss
@use "sass:color";

.trap {
  // Legacy rgb (0–255 style / hex family)
  --legacy-rgb: #{color.is-legacy(rgb(102, 51, 153))};

  // Modern srgb (0–1 style via color())
  --modern-srgb: #{color.is-legacy(color(srgb 0.4 0.2 0.6))};
}

How It Works

Official docs note that srgb is equivalent in spirit to rgb, but only rgb is legacy. Writing color(srgb …) opts into the modern space model.

🚀 Real-World Use Cases

  • Design-system migration — inventory which tokens are still legacy hex/HSL.
  • Shared mixins — choose legacy-friendly defaults vs explicit $space.
  • CI / debug dumps — emit boolean flags while auditing a palette file.
  • Docs & teaching — show rgb/hsl/hwb vs oklch with a one-line test.
  • Safe refactors — refuse certain channel ops unless the color is legacy (or vice versa).

🧠 How Compilation Works

1

Write SCSS

Call color.is-legacy($color) after @use.

Source
2

Read the color space

Sass checks whether the color is rgb, hsl, or hwb.

Inspect
3

Return a boolean

true for legacy spaces, false otherwise.

Boolean
4

Plain CSS ships

Browsers see true/false text or branched results—not a Sass call.

⚠️ Common Pitfalls

  • Old Dart Sasscolor.is-legacy needs 1.79+.
  • Confusing rgb with srgb — modern color(srgb …) is not legacy.
  • Expecting a color back — this helper returns a boolean, not a converted color.
  • Assuming “legacy” means deprecated CSS — hex/HSL are still normal; “legacy” is Sass’s space category.
  • Looking for a global alias — use color.is-legacy() from the module.

💡 Best Practices

✅ Do

  • Run Dart Sass 1.79+ before relying on is-legacy
  • Use it in mixins that support both hex and oklch tokens
  • Pair with explicit $space when working on modern colors
  • Document which brand tokens are still legacy
  • Prefer @use "sass:color"

❌ Don’t

  • Ship CI on older Dart Sass and expect this function to exist
  • Treat false as “invalid color”
  • Assume color(srgb …) behaves like legacy rgb
  • Rely on LibSass / Ruby Sass
  • Skip $space on modern colors just because hex defaults worked

Key Takeaways

Knowledge Unlocked

Five things to remember about color.is-legacy()

Boolean space check—rgb/hsl/hwb vs modern color spaces, Dart Sass 1.79+.

5
Core concepts
📦 02

Needs

Dart Sass 1.79+

Version
🎨 03

True for

rgb / hsl / hwb

Legacy
04

False for

oklch / srgb

Modern
05

Returns

boolean

Check

❓ Frequently Asked Questions

color.is-legacy($color) returns true if the color is in a legacy color space (rgb, hsl, or hwb), and false otherwise. Example: color.is-legacy(#b37399) is true; color.is-legacy(oklch(70% 10% 120deg)) is false.
Official Sass color docs treat rgb, hsl, and hwb as legacy. Hex colors and CSS color names are part of the rgb legacy space.
color.is-legacy() needs Dart Sass 1.79+. Older compilers report Undefined function.
No. The modern srgb space is not the same as legacy rgb, even though they describe similar colors. is-legacy() returns false for color(srgb ...).
Many historical Sass color behaviors (flexible channel mixing on adjust/change, default $space rules) apply specially to legacy colors. Knowing which tokens are legacy helps when migrating to oklch and friends.
No. Use the module form color.is-legacy() after @use "sass:color".
Did you know?

Official Sass docs introduce color.is-legacy() alongside color.is-in-gamut() as part of the modern color-spaces work. Legacy is not an insult to hex—it is Sass’s name for the historical rgb / hsl / hwb trio that still gets special compatibility behavior.

Conclusion

color.is-legacy() is the boolean check for whether a color still lives in rgb, hsl, or hwb. Use it while migrating palettes and writing mixins that support both hex and modern spaces—on Dart Sass 1.79+.

Continue with color.is-missing(), color.channel(), or the CSS introduction.

Explore color.is-missing() Next

Detect missing color channels with the sass:color module (Dart Sass 1.79+).

Sass color.is-missing() →

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