color.grayscale() belongs to the built-in sass:color module. It turns a color into gray while keeping the same lightness—at compile time. This page covers legacy HSL desaturation vs Oklch chroma removal, how it differs from CSS filter: grayscale(), related helpers, and five compiled examples.
01
Concept
Gray, same lightness
02
Module
@use "sass:color"
03
Legacy
HSL sat → 0%
04
Modern
Oklch chroma → 0%
05
Vs CSS
filter: grayscale()
06
Practice
5 examples
Concept
What Is color.grayscale()?
Grayscale means “keep this color’s lightness, remove its chroma / saturation.” Official docs say it returns a gray with the same lightness as $color. You still get a real CSS color value—just without hue punch.
color.grayscale(#6b717f) → #757575
color.grayscale(#336699) → #666666
color.grayscale(#4caf50) → #7e7e7e
💡
Beginner tip
Think of turning the color dial to zero while leaving brightness alone. A light blue becomes a light gray; a dark red becomes a dark gray. The gray scale follows the original lightness.
Foundation
📝 Syntax
Load the color module, then pass one color:
styles.scss
@use "sass:color";
color.grayscale($color)
// Global alias:
// grayscale($color)
Parameters
Parameter
Type
Description
$color
Color
The color to convert to gray (required).
Return value
Type
Meaning
Color
A gray color with the same lightness as $color (same color space family behavior as documented below).
Modules
📦 Loading sass:color
Prefer the module API. Official docs also document the global name grayscale() for older stylesheets.
styles.scss
// Recommended — namespaced
@use "sass:color";
$muted: color.grayscale(#6b717f);
// Optional — bring members into the current namespace
@use "sass:color" as *;
$muted: grayscale(#6b717f);
// Optional — custom namespace
@use "sass:color" as c;
$muted: c.grayscale(#6b717f);
// Legacy global name
$muted: grayscale(#6b717f);
⚠️
Put @use first
Keep @use "sass:color"; near the top of the file. Built-in modules need Dart Sass (about 1.23+). Prefer color.grayscale() so it never looks like the CSS filter function.
Rules
🎨 How Sass Removes Color
Official docs split behavior by whether the color is in a legacy space:
Color kind
What grayscale does
Legacy (hex, RGB, HSL, HWB, …)
Sets HSL saturation to 0%
Non-legacy (e.g. oklch)
Sets Oklch chroma to 0%
styles.scss
@use "sass:color";
@debug color.grayscale(#6b717f); // #757575
// Modern spaces (needs a Dart Sass build that understands them)
@debug color.grayscale(oklch(50% 80% 270deg)); // oklch(50% 0% 270deg)
Compare
📋 Sass grayscale() vs CSS filter: grayscale()
Same English word, different jobs. Mixing them up is a common beginner mistake.
Sass color.grayscale()
CSS filter: grayscale()
When it runs
Compile time
In the browser
What you get
A gray color value in CSS
A visual filter on the element
Typical use
color, background, tokens
Photos, icons, whole UI chrome
Support
🛠 Compatibility
This is about Sass compilers, not browsers. Compiled CSS receives a finished gray color—no color.grayscale() call remains.
Feature
Dart Sass
Notes
@use "sass:color" / color.grayscale
1.23+
Preferred module API
Legacy hex/RGB/HSL inputs
Widely available
Saturation set to 0%
Modern spaces (oklch, …)
Newer Dart Sass
Chroma set to 0%; needs a compiler that accepts those colors
Global grayscale()
Long-standing
Prefer module form in new SCSS
LibSass / Ruby Sass
No modern module API
May expose global grayscale(); prefer Dart Sass
Cheat Sheet
⚡ Quick Reference
Goal
Code
Import color
@use "sass:color";
Gray a hex
color.grayscale(#6b717f)
Muted brand token
color.grayscale($brand)
Related adjust (legacy)
color.adjust($c, $saturation: -100%)
CSS filter (different)
filter: grayscale(1);
Legacy global
grayscale(#6b717f)
Family
📋 grayscale vs Related Helpers
Several tools can mute color. Pick the one that matches your intent.
Helper
Job
color.grayscale()
Dedicated “make gray, keep lightness” helper
color.adjust(..., $saturation: -100%)
Manual HSL desaturation for legacy colors
color.change(..., $saturation: 0%)
Set saturation exactly to 0%
color.scale(..., $saturation: -100%)
Scale saturation toward zero relatively
Hands-On
Examples Gallery
Each example uses @use "sass:color". Open View Compiled CSS to see what Dart Sass emits.
📚 Getting Started
Official-style grayscale and everyday brand muting.
Each brand keeps its relative brightness as gray. Darker or lighter originals become darker or lighter neutrals—useful for disabled and secondary UI states.
📈 Practical Patterns
Theme tokens, CSS filter contrast, and the global alias.
Example 3 — Disabled Theme from One Brand
Keep the live brand colorful; desaturate copies for inactive UI.
One brand token produces a muted twin for disabled styles. You do not maintain a second hand-picked gray hex in the design system.
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 gray color value
color: color.grayscale(#336699);
}
.photo.is-muted {
// CSS: runtime filter on the element (not a Sass color helper)
filter: grayscale(1);
}
Use @use "sass:color" and color.grayscale() in new SCSS
Derive muted tokens from brand colors
Keep CSS filter: grayscale() for photos/UI chrome effects
Check contrast after muting interactive text
Prefer Dart Sass for the module API
❌ Don’t
Expect the browser to re-run color.grayscale
Treat CSS filters as design-token generators
Hand-maintain dozens of gray hexes you can derive
Rely on LibSass for sass:color
Skip accessibility checks on muted UI
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about color.grayscale()
Keep lightness, remove colorfulness—compile-time grays from brand tokens.
5
Core concepts
📝01
Call
grayscale($color)
API
📦02
Module
sass:color
@use
🎨03
Does
sat/chroma → 0
Mute
⚡04
Keeps
lightness
Tone
✓05
Not CSS
filter: grayscale()
Different
❓ Frequently Asked Questions
color.grayscale($color) returns a gray color with the same lightness as $color. Example: color.grayscale(#6b717f) is #757575.
Add @use "sass:color"; then call color.grayscale($brand). Prefer the module form in new SCSS. The global alias is grayscale().
Official docs: for legacy colors it sets HSL saturation to 0%. For non-legacy colors it sets Oklch chroma to 0%.
No. Sass color.grayscale() compiles to a finished gray color (hex/rgb). CSS filter: grayscale() is a runtime visual effect on an element or image.
color.adjust($c, $saturation: -100%) can also mute legacy colors, but color.grayscale() is the dedicated helper and also covers modern spaces by zeroing Oklch chroma.
The module form needs Dart Sass with @use (about 1.23+). LibSass/Ruby Sass may expose a global grayscale() but lack the modern module API.
Did you know?
Official Sass docs give two paths in one helper: legacy colors lose HSL saturation, while modern colors lose Oklch chroma. That is why color.grayscale(oklch(50% 80% 270deg)) becomes oklch(50% 0% 270deg)—same lightness and hue angle, zero chroma.
color.grayscale() is the clearest way to ask Sass for a same-lightness gray. Use it for muted tokens and disabled UI, remember the CSS filter is a different tool, and prefer @use "sass:color" on Dart Sass.