color.blackness() belongs to the built-in sass:color module (Deprecated Functions). It returns a legacy color’s HWB blackness as a percentage from 0% to 100% at compile time. This page covers the HWB idea, the legacy-color rule, Dart Sass 1.28+ support, migration to color.channel(), and five compiled examples.
01
Concept
HWB blackness %
02
Status
Deprecated
03
Range
0% … 100%
04
Needs
Dart Sass 1.28+
05
Migrate
color.channel()
06
Practice
5 examples
Concept
What Is color.blackness()?
Blackness is the “how much black ink?” channel in the HWB (Hue–Whiteness–Blackness) model. Official docs: color.blackness() returns that channel as a number between 0% and 100%. Pure white has 0% blackness; pure black has 100%.
color.blackness(#e1d7d2) → 11.7647058824%
color.blackness(white) → 0%
color.blackness(black) → 100%
💡
Beginner tip
Picture mixing a pure hue with white paint and black paint. Whiteness lightens; blackness darkens. color.blackness only reads the black mix as a percentage—it does not darken the color. To change blackness, use color.adjust() or color.change() with $blackness.
Foundation
📝 Syntax
Load the color module, then pass a legacy color:
styles.scss
@use "sass:color";
// Deprecated — Dart Sass 1.28+
color.blackness($color)
// Optional — bring members into scope
@use "sass:color" as *;
blackness($color)
// Recommended migration (Dart Sass 1.79+)
color.channel($color, "blackness")
Parameters
Parameter
Type
Description
$color
Color
Must be in a legacy color space (rgb, hsl, or hwb).
Return value
Type
Meaning
Number with %
HWB blackness from 0% to 100%.
Modules
📦 Loading sass:color & Migrating
Prefer the namespaced form. Bare blackness() only works after @use "sass:color" as *;—otherwise CSS may keep the call as a plain string.
styles.scss
@use "sass:color";
// Old (deprecated, Dart Sass 1.28+)
$b: color.blackness(#e1d7d2); // 11.7647058824%
// New — preferred on Dart Sass 1.79+
$b: color.channel(#e1d7d2, "blackness");
// Optional global-style import
@use "sass:color" as *;
$b: blackness(#e1d7d2);
⚠️
Version notes
color.blackness() needs Dart Sass 1.28+. color.channel() needs 1.79+. On 1.28–1.78, keep color.blackness until you can upgrade.
Details
🎨 HWB: Blackness + Whiteness
HWB describes a color as a hue mixed with white and black. For many everyday hex colors, whiteness and blackness percentages add up to less than 100%—the rest is the pure hue.
Blackness high → darker, sootier look
Blackness 0% → no black mix (white is the extreme opposite case)
Blackness 100% → pure black
💡
Sibling channel
Official docs also document color.whiteness() the same way (also deprecated in favor of color.channel($c, "whiteness")). Reading both helps you understand an HWB breakdown of a brand hex.
Compare
📋 color.blackness vs color.channel
Helper
Job
Status
color.blackness()
Read HWB blackness on legacy colors
Deprecated / not recommended
color.channel($c, "blackness")
Same read (and any other channel)
Preferred on Dart Sass 1.79+
color.adjust(..., $blackness: …)
Change blackness by a fixed amount
Writer, not a reader
Support
🛠 Compatibility
This is about Sass compilers, not browsers. Compiled CSS receives a finished percentage—no color.blackness() call remains at runtime.
Feature
Dart Sass
Notes
color.blackness()
1.28+ (deprecated)
Legacy colors only; LibSass / Ruby Sass ✗
color.channel(…, "blackness")
1.79+
Official recommended replacement
Related $blackness on adjust/change/scale
1.28+
Writers for the same HWB channel
Cheat Sheet
⚡ Quick Reference
Goal
Code
Warm grey hex
color.blackness(#e1d7d2) → 11.7647058824%
White
color.blackness(white) → 0%
Black
color.blackness(black) → 100%
Brand blue
color.blackness(#336699)
Modern read
color.channel($c, "blackness")
Change blackness
color.adjust($c, $blackness: 10%)
Hands-On
Examples Gallery
Examples use color.blackness() on Dart Sass 1.28+. Open View Compiled CSS for verified output (matches official Sass docs samples where noted).
📚 Getting Started
Official docs samples for everyday and extreme colors.
Example 1 — Warm Hex Blackness (Official Docs)
A soft taupe hex reports a small blackness percentage.
Whiteness dominates this soft tone; blackness is small; their sum stays under 100%, leaving room for the hue. Both readers are deprecated—migrate to color.channel with "whiteness" / "blackness".
Example 5 — Branch on High Blackness
Use the percentage in a simple token report for a mid grey.
Because blackness is a percentage number, you can compare it in Sass. On Dart Sass 1.79+, swap to color.channel($grey, "blackness") and keep the same if() logic.
Applications
🚀 Real-World Use Cases
Reading legacy SCSS — recognize color.blackness in older HWB workflows.
Safe migrations — replace with color.channel($c, "blackness") on Dart Sass 1.79+.
Token audits — flag colors that sit too far toward black ink.
HWB teaching — pair with whiteness to explain the model.
Conditional mixins — pick light text when blackness is high.
🧠 How Compilation Works
1
Write SCSS
Call color.blackness($c) or migrate to color.channel.
Source
2
Map to HWB
Sass views the legacy color in Hue–Whiteness–Blackness.
HWB
3
Read blackness
You get a percentage from 0% to 100%.
Percent
4
✓
CSS sees the %
Custom properties get finished percentages—not a Sass call.
Watch Out
⚠️ Common Pitfalls
Using it in new code — prefer color.channel($c, "blackness").
Bare blackness() without as * — may compile as a CSS function string.
Modern color spaces — $color must be legacy for color.blackness.
Confusing with CSS blackness — this is an HWB channel reader, not a filter.
Expecting a color back — this helper reads a percentage; use adjust/change to write.
Pro Tips
💡 Best Practices
✅ Do
Migrate to color.channel($c, "blackness") on Dart Sass 1.79+
Use @use "sass:color" and color.blackness() on 1.28+
Pair with whiteness when explaining HWB
Compare percentages in mixins for token rules
Document when a brand is intentionally dark
❌ Don’t
Add new color.blackness() calls in greenfield projects
Pass modern oklch colors into color.blackness
Call bare blackness() without importing the module
Expect the browser to re-run Sass at runtime
Use a reader when you meant to change blackness
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about color.blackness()
Deprecated HWB blackness reader—migrate to color.channel.
5
Core concepts
📝01
Call
color.blackness($c)
API
⚠️02
Status
Deprecated
Docs
🎨03
Returns
0% … 100%
HWB
⚡04
Needs
Dart Sass 1.28+
Version
✓05
Replace
channel(..., "blackness")
Migrate
❓ Frequently Asked Questions
color.blackness($color) returns the HWB blackness of a legacy color as a percentage between 0% and 100%. Example: color.blackness(black) is 100%; color.blackness(white) is 0%.
Yes. Official Sass docs list it under Deprecated Functions and say it is no longer recommended because it is redundant with color.channel($color, "blackness").
In the HWB (Hue-Whiteness-Blackness) model, blackness is how much black is mixed into the pure hue. Higher blackness means a darker, inkier color.
Official docs: Dart Sass since 1.28.0. LibSass and Ruby Sass are not supported for this helper.
Official docs require a legacy color space (rgb, hsl, or hwb). Convert first, or use color.channel($color, "blackness", $space: hwb) on Dart Sass 1.79+.
Replace color.blackness($color) with color.channel($color, "blackness") after @use "sass:color" on Dart Sass 1.79+. Keep color.blackness on older 1.28–1.78 compilers until you upgrade.
Did you know?
Official Sass docs keep dedicated readers like color.blackness() for compatibility, but the modern story is one API: color.channel($c, "blackness") (and the same pattern for whiteness, hue, alpha, and more).
color.blackness() reads a legacy color’s HWB blackness as a percentage from 0% to 100% (Dart Sass 1.28+). Treat it as deprecated documentation: prefer color.channel($color, "blackness") for new SCSS on Dart Sass 1.79+.