Sass color.blackness()

Beginner
10 min read
Updated: Nov 2026
5 examples
Deprecated reader

Definition and Usage

color.blackness($color) returns the HWB blackness of a legacy color as a percentage between 0% and 100% (Dart Sass 1.28+). Global alias: blackness($color).

In the HWB (Hue–Whiteness–Blackness) model, blackness is how much black is mixed into the pure hue. Official docs mark the helper deprecated — prefer color.channel($color, "blackness") on Dart Sass 1.79+.

No longer recommended.

Because color.blackness() is redundant with color.channel(), migrate readers to the channel API in new code.

Official samples.

color.blackness(#e1d7d2) ≈ 11.76%. white → 0%. black → 100%.

Pair with whiteness.

Read both HWB mix channels with color.whiteness() (also deprecated; same color.channel migration).

Syntax

SCSS
@use "sass:color";

// Deprecated reader (Dart Sass 1.28+)
color.blackness(#e1d7d2); // 11.7647058824%
color.blackness(white);   // 0%
color.blackness(black);   // 100%

// Prefer today (Dart Sass 1.79+)
color.channel(#e1d7d2, "blackness");
color.channel($c, "blackness", $space: hwb);

Pattern: recognize color.blackness in old files → rewrite with color.channel($c, "blackness").

Migrate to color.channel

Side-by-side mapping:

Legacy / currentPrefer (1.79+)
color.blackness($c)color.channel($c, "blackness")
blackness($c) (global)color.channel($c, "blackness")
color.whiteness($c)color.channel($c, "whiteness")
Force HWB spacecolor.channel($c, "blackness", $space: hwb)

To change blackness, use writers like color.adjust / color.change with $blackness — not the reader.

SCSS Examples

Examples use color.blackness() on Dart Sass 1.28+. Open View Compiled CSS for verified output (matches official Sass docs samples where noted).

Example 1 — Warm Hex Blackness (Official Docs)

A soft taupe hex reports a small blackness percentage.

SCSS
@use "sass:color";

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

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

How It Works

  1. Legacy hex converts into HWB coordinates.
  2. Blackness channel is a percentage (~11.76%).
  3. Interpolation writes it into a custom property.
  4. Same read via color.channel(#e1d7d2, "blackness") on 1.79+.

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

The extremes of the blackness scale.

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

  1. White has no black mix → 0%.
  2. Black is entirely blackness → 100%.
  3. Handy check that your reader matches the official scale.
  4. Migration path should produce the same extremes.

Example 3 — Brand Blue Blackness

Measure how much black sits in a classic UI blue.

SCSS
@use "sass:color";

$brand: #336699;

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

How It Works

  1. #336699 converts to HWB.
  2. Blackness lands at 40%.
  3. Darkened from a pure hue, but far from ink black.
  4. Useful when auditing brand tokens for inkiness.

Example 4 — Pair Blackness with Whiteness

See both HWB mix channels for the official taupe sample.

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

  1. Whiteness dominates this soft tone.
  2. Blackness is small (~11.76%).
  3. Sum stays under 100%, leaving room for the hue.
  4. Migrate both to color.channel with "whiteness" / "blackness".

Example 5 — Branch on High Blackness

Use the percentage in a simple token report for a mid grey.

SCSS
@use "sass:color";

$grey: #6b717f;

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

How It Works

  1. Blackness is a % number, so comparisons work in Sass.
  2. #6b717f is slightly over 50%.
  3. if() labels it inky.
  4. On 1.79+, swap to color.channel($grey, "blackness") and keep the logic.

Edge Cases & Pitfalls

Most blackness-reader bugs are writing vs reading, version gaps, or modern color spaces.

read

Readers do not darken colors

color.blackness only returns a %. To change blackness, use color.adjust / color.change with $blackness.

version

Needs Dart Sass 1.28+

color.channel needs 1.79+. Stay on color.blackness until you can upgrade both.

space

Legacy colors only for this helper

Official docs require rgb / hsl / hwb. Prefer color.channel(..., $space: hwb) for modern spaces.

migrate

Quote the channel name

Write color.channel($c, "blackness") with a quoted string.

Sass Support

color.blackness() is a Dart Sass reader. Prefer color.channel when your toolchain allows.

APIStatus
color.blackness()Dart Sass 1.28+ (deprecated reader)
color.channel($c, "blackness")Preferred on Dart Sass 1.79+
LibSass / Ruby SassNot supported for this helper
BrowsersN/A — only see compiled CSS values

Compile with the Dart Sass CLI.

Key Takeaways

  • Reads HWB blackness as a percentage from 0% to 100%.
  • Deprecated in favor of color.channel($c, "blackness").
  • Pair with whiteness to understand HWB mix channels.
  • Dart Sass 1.28+ for blackness; 1.79+ for channel.

One line: use color.blackness to understand old HWB reads — write new ones with color.channel.

Migrate Notes

Practical checklist:

migrate.txt
1. Find color.blackness($c) in legacy SCSS
2. Confirm Dart Sass 1.28+ (reader) or 1.79+ (channel)
3. Replace with color.channel($c, "blackness")
4. Add $space: hwb when reading non-legacy colors
5. Use adjust/change when you need to write blackness

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.

Next: Sass color.blue()

Read the RGB blue channel as a 0–255 number.

color.blue() →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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.

8 people found this page helpful