Sass color.invert() Function

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

What You’ll Learn

color.invert() belongs to the built-in sass:color module. It builds the inverse (negative) of a color at compile time, with an optional weight that blends toward that negative. This page covers $weight, optional $space (Dart Sass 1.79+), how it differs from CSS filter: invert(), and five compiled examples.

01

Concept

Color negative

02

Module

@use "sass:color"

03

Weight

0% … 100%

04

Space

Optional (1.79+)

05

Vs CSS

filter: invert()

06

Practice

5 examples

What Is color.invert()?

Invert means “flip this color toward its photographic negative.” Official docs call the result the inverse or negative of $color. Black becomes white, and a rose pink becomes a greenish complement-style negative—not just a hue spin like complement.

  • color.invert(#b37399)#4c8c66
  • color.invert(black)white
  • color.invert(#d2dfd9)#2d2026
💡
Beginner tip

Think of a photo negative: lights become darks and hues flip. With $weight: 50% you land in the middle—a medium gray—instead of a full negative.

📝 Syntax

Load the color module, then pass a color, optional weight, and optional space:

styles.scss
@use "sass:color";

color.invert($color, $weight: 100%, $space: null)
// Global alias:
// invert($color, $weight: 100%, $space: null)

Parameters

ParameterTypeDescription
$colorColorThe color to invert (required).
$weightPercentageHow far to move toward the full negative (0%–100%). Default 100%.
$spaceColor space nameSpace used for the inversion (Dart Sass 1.79+). For legacy colors without $space, Sass defaults to the color’s own space.

Return value

TypeMeaning
ColorA new color between the original and its negative, controlled by $weight.

📦 Loading sass:color

Prefer the module API. Official docs also document the global name invert() for older stylesheets.

styles.scss
// Recommended — namespaced
@use "sass:color";
$neg: color.invert(#b37399);

// Optional — bring members into the current namespace
@use "sass:color" as *;
$neg: invert(#b37399);

// Optional — custom namespace
@use "sass:color" as c;
$neg: c.invert(#b37399);

// Legacy global name
$neg: invert(#b37399);
⚠️
Put @use first

Keep @use "sass:color"; near the top of the file. Built-in modules need Dart Sass (about 1.23+). Passing $space needs 1.79+. Prefer color.invert() so it never looks like the CSS filter function.

⚖️ Understanding $weight

Official docs: a higher weight means closer to the negative; a lower weight stays closer to $color. Weight 50% always produces a medium-lightness gray in that space.

WeightResult feel
0%Same as the original color
30%Slightly pulled toward the negative
50%Medium-lightness gray
100% (default)Full inverse / negative

📋 Sass invert() vs CSS filter: invert()

Same English word, different jobs—just like grayscale.

Sass color.invert()CSS filter: invert()
When it runsCompile timeIn the browser
What you getA finished color value in CSSA visual filter on the element
Typical usecolor, background, tokensPhotos, icons, whole UI chrome

📋 invert vs complement

Both change how a color “feels opposite,” but they are not the same math.

HelperJob
color.invert()Photographic / channel negative (optional partial weight)
color.complement()Rotate hue by 180deg in a polar space

🛠 Compatibility

This is about Sass compilers, not browsers. Compiled CSS receives a finished color—no color.invert() call remains.

FeatureDart SassNotes
@use "sass:color" / color.invert1.23+Preferred module API
$weightWidely available0%–100% blend toward the negative
$space1.79+Invert in an explicit color space (e.g. rgb, display-p3)
Global invert()Long-standingPrefer module form in new SCSS
LibSass / Ruby SassNo modern module APIMay expose global invert(); prefer Dart Sass
💡
Heads up from the docs

For historical reasons, $space is optional when $color is already in a legacy space—then it defaults to that color’s own space. Official guidance: pass $space explicitly once you are on Dart Sass 1.79+.

⚡ Quick Reference

GoalCode
Import color@use "sass:color";
Full invertcolor.invert(#b37399)
Partial invertcolor.invert($c, $weight: 30%)
Mid graycolor.invert($c, $weight: 50%)
Explicit space (1.79+)color.invert($c, $space: rgb)
CSS filter (different)filter: invert(1);
Legacy globalinvert(#b37399)

Examples Gallery

Each example uses @use "sass:color". Open View Compiled CSS to see what Dart Sass emits.

📚 Getting Started

Official-style full inverts and everyday brand negatives.

Example 1 — Full Color Negatives

Invert solid colors (matches the classic docs result for #b37399).

styles.scss
@use "sass:color";

@debug color.invert(#b37399); // #4c8c66

.swatches {
  color: color.invert(#b37399);
  outline-color: color.invert(black);   // white
  border-color: color.invert(#d2dfd9);  // #2d2026
}

How It Works

With the default weight of 100%, Sass returns the full negative. Black flips to white; light mint flips to a dark purple-brown.

Example 2 — Invert Brand Accents

Generate opposite fills from blue, green, and red tokens.

styles.scss
@use "sass:color";

.negatives {
  color: color.invert(#336699);         // #cc9966
  background: color.invert(#4caf50);    // #b350af
  outline-color: color.invert(#c65353); // #39acac
}

How It Works

Each brand becomes its channel negative. Useful for alternate themes, badges, or “dark-mode style” accents derived from the same token set.

📈 Practical Patterns

Weighted blends, CSS filter contrast, and the global alias.

Example 3 — Weight Ladder from One Brand

Full invert, mid gray, and a soft pull toward the negative.

styles.scss
@use "sass:color";

$brand: #336699;

.card {
  background: $brand;
  color: color.invert($brand);                 // full negative
  border-color: color.invert($brand, $weight: 50%);  // medium gray
  outline-color: color.invert($brand, $weight: 30%); // partial
}

How It Works

50% lands on a medium gray (Sass may emit the gray keyword). 30% keeps more of the original brand while edging toward the negative.

Example 4 — Sass Color vs CSS Filter

Use both APIs in one stylesheet—know which is which.

styles.scss
@use "sass:color";

.chip {
  // Sass: compile-time negative color value
  color: color.invert(#336699);
}

.photo.is-negative {
  // CSS: runtime filter on the element (not a Sass color helper)
  filter: invert(1);
}

How It Works

color.invert() becomes a hex in the CSS file. The filter declaration stays a CSS filter function for the browser to apply to the rendered element.

Example 5 — Module vs Global + Double Invert

Same full invert from both APIs; inverting twice restores the original.

styles.scss
@use "sass:color";

.names {
  --module: #{color.invert(#b37399)};
  --global: #{invert(#b37399)};
  --round-trip: #{color.invert(color.invert(#b37399))};
}

How It Works

Module and global full inverts match. A second full invert undoes the first for this opaque color—handy when teaching negatives.

🚀 Real-World Use Cases

  • Alternate accents — derive a negative twin from one brand hex.
  • High-contrast chips — pair a fill with its invert for text/icons (still check a11y).
  • Soft “washed” accents — use $weight: 20%–40% instead of a full flip.
  • Neutral midtones$weight: 50% for a related medium gray.
  • Theme experiments — preview negatives before locking a palette.
  • Teaching color math — show how invert differs from complement and CSS filters.

🧠 How Compilation Works

1

Write SCSS

Call color.invert($color, ...) after @use.

Source
2

Pick a space

Use $space, or default legacy colors to their own space.

Space
3

Blend with weight

Mix original and full negative using $weight.

Invert
4

Plain CSS color ships

Browsers receive hex/rgb—not a Sass call.

⚠️ Common Pitfalls

  • Confusing CSS filterfilter: invert() does not produce a Sass color token.
  • Mixing up with complement — hue +180deg is not the same as a channel negative.
  • Using $space on older Dart Sass — needs 1.79+; bare color.invert($hex) still works earlier.
  • Assuming contrast is automatic — inverted text on inverted backgrounds can still fail a11y checks.
  • Forgetting weight units — pass percentages such as 30%, not bare 30.

💡 Best Practices

✅ Do

  • Use @use "sass:color" and color.invert() in new SCSS
  • Use $weight when a soft pull looks better than a full flip
  • Pass $space explicitly on Dart Sass 1.79+
  • Keep CSS filter: invert() for photos/UI chrome effects
  • Check contrast after inverting interactive text

❌ Don’t

  • Expect the browser to re-run color.invert
  • Treat CSS filters as design-token generators
  • Confuse invert with complement when naming tokens
  • Rely on LibSass for sass:color
  • Skip accessibility checks on inverted UI

Key Takeaways

Knowledge Unlocked

Five things to remember about color.invert()

Compile-time negatives—tune with weight, don’t confuse with CSS filters.

5
Core concepts
📦 02

Module

sass:color

@use
🎨 03

Does

color negative

Invert
04

Weight

0% … 100%

Blend
05

Not CSS

filter: invert()

Different

❓ Frequently Asked Questions

color.invert($color, $weight: 100%, $space: null) returns the inverse or negative of a color. Example: color.invert(#b37399) is #4c8c66.
Weight must be between 0% and 100%. Higher values move closer to the full negative; lower values stay closer to the original. Weight 50% always produces a medium-lightness gray in that space.
Add @use "sass:color"; then call color.invert($brand) or color.invert($brand, $weight: 30%). Prefer the module form. The global alias is invert().
No. Sass color.invert() compiles to a finished color value. CSS filter: invert() is a runtime visual effect on an element or image.
Yes for a full invert (weight 100%) in the same space: color.invert(color.invert($c)) returns to the starting color for typical opaque colors.
The module form needs Dart Sass with @use (about 1.23+). The $space argument needs Dart Sass 1.79+. LibSass/Ruby Sass may expose a global invert() but lack the modern module API.
Did you know?

Official Sass docs highlight that weight 50% always produces a medium-lightness gray in the chosen space—so you can derive a related neutral from any brand color without picking a gray hex by hand. On Dart Sass 1.79+, passing $space (for example rgb or display-p3) controls which color space the inversion uses.

Conclusion

color.invert() is the clearest way to ask Sass for a color negative. Use $weight for partial blends, remember CSS filter: invert() is a different tool, and prefer @use "sass:color" on Dart Sass.

Continue with color.is-legacy(), color.complement(), or the CSS introduction.

Explore color.is-legacy() Next

Detect rgb/hsl/hwb legacy colors with the sass:color module (Dart Sass 1.79+).

Sass color.is-legacy() →

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