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
Concept
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.
Foundation
📝 Syntax
Load the color module, then pass a color, optional weight, and optional space:
How far to move toward the full negative (0%–100%). Default 100%.
$space
Color space name
Space used for the inversion (Dart Sass 1.79+). For legacy colors without $space, Sass defaults to the color’s own space.
Return value
Type
Meaning
Color
A new color between the original and its negative, controlled by $weight.
Modules
📦 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.
Control
⚖️ 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.
Weight
Result feel
0%
Same as the original color
30%
Slightly pulled toward the negative
50%
Medium-lightness gray
100% (default)
Full inverse / negative
Compare
📋 Sass invert() vs CSS filter: invert()
Same English word, different jobs—just like grayscale.
Sass color.invert()
CSS filter: invert()
When it runs
Compile time
In the browser
What you get
A finished color value in CSS
A visual filter on the element
Typical use
color, background, tokens
Photos, icons, whole UI chrome
Family
📋 invert vs complement
Both change how a color “feels opposite,” but they are not the same math.
This is about Sass compilers, not browsers. Compiled CSS receives a finished color—no color.invert() call remains.
Feature
Dart Sass
Notes
@use "sass:color" / color.invert
1.23+
Preferred module API
$weight
Widely available
0%–100% blend toward the negative
$space
1.79+
Invert in an explicit color space (e.g. rgb, display-p3)
Global invert()
Long-standing
Prefer module form in new SCSS
LibSass / Ruby Sass
No modern module API
May 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+.
Cheat Sheet
⚡ Quick Reference
Goal
Code
Import color
@use "sass:color";
Full invert
color.invert(#b37399)
Partial invert
color.invert($c, $weight: 30%)
Mid gray
color.invert($c, $weight: 50%)
Explicit space (1.79+)
color.invert($c, $space: rgb)
CSS filter (different)
filter: invert(1);
Legacy global
invert(#b37399)
Hands-On
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).
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);
}
Module and global full inverts match. A second full invert undoes the first for this opaque color—handy when teaching negatives.
Applications
🚀 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.
Watch Out
⚠️ Common Pitfalls
Confusing CSS filter — filter: 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.
Pro Tips
💡 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
Summary
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
📝01
Call
invert($color)
API
📦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.
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.