color.channel() belongs to the built-in sass:color module. It reads one channel from a color and returns a number—hue, lightness, red, alpha, and more—at compile time. This page covers quoted channel names, return units, optional $space, how it relates to older getters like color.red() / color.hue(), and five examples (Dart Sass 1.79+).
01
Concept
Read one channel
02
Module
@use "sass:color"
03
Names
Quoted strings
04
Units
deg · % · unitless
05
Vs
red() / hue()
06
Practice
5 examples
Concept
What Is color.channel()?
Channel means “open this color and tell me one dial’s current number.” Unlike adjust / change / scale, it does not return a new color—it returns a number you can compare, interpolate, or feed into other Sass math.
Think of a color as a mixer board. color.channel($c, "lightness") reads the lightness dial. color.change($c, $lightness: 30%) turns that dial to 30%. Reading and writing are separate helpers.
Foundation
📝 Syntax
Load the color module, then pass the color, a quoted channel name, and an optional space:
The color stays HSL, but $space: oklch asks for hue after conversion, and $space: rgb asks for the RGB red component. Same source color, different rulers.
channel feeds compile-time decisions and rgba() construction. Hex colors live in RGB space, so lightness needs $space: hsl. Because that lightness is 40% (not greater than 45%), the text color becomes white.
Example 5 — channel() vs Older Getters
Same reads, two APIs—useful while upgrading toward 1.79+.
For same-space reads, the numbers match. Prefer color.channel() on Dart Sass 1.79+ when you want one API for every space—including cross-space $space queries.
Applications
🚀 Real-World Use Cases
Contrast helpers — pick black or white text from lightness.
Conditional themes — branch mixins when saturation is below a threshold.
Rebuild colors — feed RGB channels into rgba() or other constructors.
Cross-space debugging — print oklch hue for a hex brand color during migration.
API cleanup — replace many color.red/hue calls with one reader.
🧠 How Compilation Works
1
Write SCSS
Call color.channel($color, "hue") after @use.
Source
2
Resolve space
Use the color’s space, or convert when $space is set.
Space
3
Read the dial
Return a number with deg, %, or no unit.
Number
4
✓
Plain CSS ships
Browsers see numbers or finished colors—not a Sass call.
Watch Out
⚠️ Common Pitfalls
Unquoted channel names — use "hue", not bare hue, for $channel.
Old Dart Sass — color.channel needs 1.79+; otherwise use color.red() / color.hue().
Expecting a color — channel returns a number; mutators return colors.
Wrong space — hex defaults to RGB, so "lightness" needs $space: hsl; HSL colors need $space: rgb to read "red".
Missing channels look like zero — use color.is-missing() when zero is ambiguous.
Pro Tips
💡 Best Practices
✅ Do
Use Dart Sass 1.79+ for color.channel()
Quote channel names: "lightness", "alpha"
Pass $space when reading across color spaces
Store brand tokens once, read channels for guards and CSS variables
Keep older getters only when you must support pre-1.79 compilers
❌ Don’t
Confuse readers (channel) with writers (change/adjust)
Forget quotes on $channel
Expect browsers to evaluate color.channel
Ignore the 1.79+ requirement when CI still runs older Dart Sass
Treat a missing channel’s 0 as a real measurement without checking
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about color.channel()
One reader for every dial—quoted names, careful units, Dart Sass 1.79+.
5
Core concepts
📝01
Call
channel($c, "hue")
API
📦02
Needs
Dart Sass 1.79+
Version
🎨03
Returns
number + units
Read
⚡04
Space
$space: rgb
Convert
✓05
Siblings
red() / hue()
Getters
❓ Frequently Asked Questions
color.channel($color, $channel, $space: null) returns the numeric value of one channel. Example: color.channel(hsl(80deg 30% 50%), "hue") is 80deg.
Pass a quoted string such as "red", "hue", "lightness", or "alpha". Unquoted names are not correct for $channel.
color.channel() and its $space argument need Dart Sass 1.79+. On older Dart Sass, use space-specific getters like color.red(), color.hue(), or color.lightness().
Hue in hsl/hwb/lch/oklch returns deg. Saturation, lightness, whiteness, and blackness return %. Other channels (including RGB and alpha) are usually unitless.
Official docs say channel() returns 0 (with an appropriate unit when needed). Use color.is-missing() when you need to detect missing channels explicitly.
channel reads a number. adjust and change return a new color by shifting or replacing channels.
Did you know?
Official Sass docs note that color.channel() returns 0 (sometimes with a unit) when a channel is missing, and they point you to color.is-missing() when you need to tell “really zero” apart from “not present.” That matters more as modern color spaces enter design systems.
color.channel() is the modern way to read a single color channel as a number. Quote the channel name, mind return units, use $space for cross-space reads, and run Dart Sass 1.79+. Pair it with color.change() / color.adjust() when you need to write colors instead of inspect them.