Sass color.blackness() Function

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
Deprecated
sass:color · Dart Sass 1.28+

What You’ll Learn

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

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.

📝 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

ParameterTypeDescription
$colorColorMust be in a legacy color space (rgb, hsl, or hwb).

Return value

TypeMeaning
Number with %HWB blackness from 0% to 100%.

📦 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.

🎨 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.

📋 color.blackness vs color.channel

HelperJobStatus
color.blackness()Read HWB blackness on legacy colorsDeprecated / 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 amountWriter, not a reader

🛠 Compatibility

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

FeatureDart SassNotes
color.blackness()1.28+ (deprecated)Legacy colors only; LibSass / Ruby Sass ✗
color.channel(…, "blackness")1.79+Official recommended replacement
Related $blackness on adjust/change/scale1.28+Writers for the same HWB channel

⚡ Quick Reference

GoalCode
Warm grey hexcolor.blackness(#e1d7d2)11.7647058824%
Whitecolor.blackness(white)0%
Blackcolor.blackness(black)100%
Brand bluecolor.blackness(#336699)
Modern readcolor.channel($c, "blackness")
Change blacknesscolor.adjust($c, $blackness: 10%)

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.

styles.scss
@use "sass:color";

@debug color.blackness(#e1d7d2); // 11.7647058824%

.swatch {
  --blackness: #{color.blackness(#e1d7d2)};
}

How It Works

Sass converts the legacy hex into HWB coordinates and writes the blackness channel as a percentage custom property.

Example 2 — White Is 0%, Black Is 100% (Official Docs)

The extremes of the blackness scale.

styles.scss
@use "sass:color";

@debug color.blackness(white); // 0%
@debug color.blackness(black); // 100%

.extremes {
  --white: #{color.blackness(white)};
  --black: #{color.blackness(black)};
}

How It Works

White has no black mix; black is entirely blackness. Handy for checking that your reader and migration path match the official scale.

📈 Practical Patterns

Brand tokens, HWB pairs, and simple darkness checks.

Example 3 — Brand Blue Blackness

Measure how much black sits in a classic UI blue.

styles.scss
@use "sass:color";

$brand: #336699;

.brand {
  --blackness: #{color.blackness($brand)};
}

How It Works

#336699 lands at 40% blackness—noticeably darkened from a pure hue, but far from ink black.

Example 4 — Pair Blackness with Whiteness

See both HWB mix channels for the official taupe sample.

styles.scss
@use "sass:color";

$tone: #e1d7d2;

.hwb-report {
  --whiteness: #{color.whiteness($tone)};
  --blackness: #{color.blackness($tone)};
  --sum: #{color.whiteness($tone) + color.blackness($tone)};
}

How It Works

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.

styles.scss
@use "sass:color";

$grey: #6b717f;

.report {
  --blackness: #{color.blackness($grey)};
  --ink: #{if(color.blackness($grey) >= 50%, "inky", "open")};
}

How It Works

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.

🚀 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.

⚠️ 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.

💡 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

Key Takeaways

Knowledge Unlocked

Five things to remember about color.blackness()

Deprecated HWB blackness reader—migrate to color.channel.

5
Core concepts
⚠️ 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).

Conclusion

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+.

Continue with color.blue(), color.channel(), or color.adjust().

Next: color.blue()

You learned deprecated color.blackness()—next is the RGB blue channel reader.

color.blue() →

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