Sass color.channel() Function

Beginner
⏱️ 13 min read
📚 Updated: Jul 2026
🎯 5 Examples
sass:color · Dart Sass 1.79+

What You’ll Learn

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

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.

  • color.channel(hsl(80deg 30% 50%), "hue")80deg
  • color.channel(#6b717f, "red")107
  • color.channel(hsl(80deg 30% 50%), "red", $space: rgb)140.25
💡
Beginner tip

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.

📝 Syntax

Load the color module, then pass the color, a quoted channel name, and an optional space:

styles.scss
@use "sass:color";

// Dart Sass 1.79+
color.channel($color, $channel, $space: null)

Parameters

ParameterTypeDescription
$colorColorThe color to inspect (required).
$channelQuoted stringChannel name, e.g. "red", "hue", "lightness", "alpha".
$spaceUnquoted stringOptional color space to read in (defaults to $color’s space). Examples: rgb, hsl, oklch.

Return value

Channel familyTypical unit
hue in hsl / hwb / lch / oklchdeg
saturation, lightness, whiteness, blackness (and related %)%
RGB channels, alpha, and most othersUnitless number
Missing channel0 (possibly with a unit)—see color.is-missing()

📦 Loading sass:color

There is no separate global channel() built-in like adjust-color / change-color. Use the module form on Dart Sass 1.79+.

styles.scss
// Recommended — namespaced (Dart Sass 1.79+)
@use "sass:color";
$h: color.channel(hsl(80deg 30% 50%), "hue");

// Optional — bring members into the current namespace
@use "sass:color" as *;
$h: channel(hsl(80deg 30% 50%), "hue");

// Optional — custom namespace
@use "sass:color" as c;
$h: c.channel(hsl(80deg 30% 50%), "hue");
⚠️
Version gate

If Dart Sass reports Undefined function for color.channel, upgrade to 1.79+, or use older getters such as color.hue() / color.red() for the meantime.

🎨 Common Channel Names

Official docs require a quoted string for $channel. Here are the names beginners use most often:

SpaceChannel strings
RGB"red", "green", "blue", "alpha"
HSL"hue", "saturation", "lightness", "alpha"
HWB"hue", "whiteness", "blackness", "alpha"
Modern (1.79+)Also channels for lab, oklch, etc., when you pass $space

🛠 Compatibility

This is about Sass compilers, not browsers. Compiled CSS receives numbers or finished colors—no color.channel() call remains.

FeatureDart SassNotes
color.channel() / $space1.79+Unified channel reader across spaces
color.red() / green() / blue() / alpha()Earlier module APISpace-specific getters still useful
color.hue() / saturation() / lightness()Earlier module APIHSL-oriented readers
LibSass / Ruby SassNo modern module APIPrefer Dart Sass

⚡ Quick Reference

GoalCode
Import color@use "sass:color";
Read huecolor.channel($c, "hue")
Read lightness (from hex)color.channel($c, "lightness", $space: hsl)
Read redcolor.channel($c, "red")
Read in another spacecolor.channel($c, "red", $space: rgb)
Older HSL gettercolor.hue($c)
Older RGB gettercolor.red($c)

📋 channel vs Getters vs Mutators

Readers return numbers. Mutators return colors. Pick the tool that matches the job.

HelperReturnsJob
color.channel()NumberRead any named channel (1.79+)
color.red() / hue() / …NumberRead one space-specific channel
color.adjust() / change() / scale()ColorProduce a new color

📋 Older Getters → color.channel()

On Dart Sass 1.79+, you can often rewrite space-specific getters with one API.

Older module callModern write
color.red($c)color.channel($c, "red")
color.green($c)color.channel($c, "green")
color.blue($c)color.channel($c, "blue")
color.alpha($c)color.channel($c, "alpha")
color.hue($c)color.channel($c, "hue", $space: hsl) when $c is hex/RGB
color.saturation($c)color.channel($c, "saturation", $space: hsl) for hex/RGB
color.lightness($c)color.channel($c, "lightness", $space: hsl) for hex/RGB

Examples Gallery

Examples target Dart Sass 1.79+. Open View Compiled CSS to see the numbers Sass emits into custom properties or rules.

📚 Getting Started

Official-style HSL reads and RGB inspection.

Example 1 — Read HSL Channels

Pull hue, saturation, and lightness from an HSL color (official docs style).

styles.scss
@use "sass:color";

$swatch: hsl(80deg 30% 50%);

@debug color.channel($swatch, "hue");        // 80deg
@debug color.channel($swatch, "saturation"); // 30%
@debug color.channel($swatch, "lightness");  // 50%

.token {
  --hue: #{color.channel($swatch, "hue")};
  --sat: #{color.channel($swatch, "saturation")};
  --light: #{color.channel($swatch, "lightness")};
}

How It Works

Because the color already lives in HSL, reading "hue" returns 80deg, and the percentage channels keep their % units.

Example 2 — Read RGB Channels from Hex

Inspect the red, green, blue, and alpha dials of a hex color.

styles.scss
@use "sass:color";

$ink: #6b717f;

.channels {
  --red: #{color.channel($ink, "red")};
  --green: #{color.channel($ink, "green")};
  --blue: #{color.channel($ink, "blue")};
  --alpha: #{color.channel($ink, "alpha")};
}

How It Works

Hex #6b717f is an RGB color, so "red" / "green" / "blue" return unitless 0–255 style numbers. Fully opaque colors report alpha 1.

📈 Practical Patterns

Cross-space reads, contrast guards, and older getters.

Example 3 — Read a Channel in Another Space

Pass $space to convert and read (official docs examples).

styles.scss
@use "sass:color";

$swatch: hsl(80deg 30% 50%);

@debug color.channel($swatch, "hue", $space: oklch); // 124.279238779deg
@debug color.channel($swatch, "red", $space: rgb);   // 140.25

.cross {
  --oklch-hue: #{color.channel($swatch, "hue", $space: oklch)};
  --rgb-red: #{color.channel($swatch, "red", $space: rgb)};
}

How It Works

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.

Example 4 — Contrast Guard from Lightness

Choose text color by reading brand lightness.

styles.scss
@use "sass:color";

$brand: #336699;

.button {
  background: $brand;
  // Lightness of #336699 is 40% — pick light text
  color: if(color.channel($brand, "lightness", $space: hsl) > 45%, #111, #fff);
  box-shadow: 0 0 0 4px rgba(
    color.channel($brand, "red"),
    color.channel($brand, "green"),
    color.channel($brand, "blue"),
    0.2
  );
}

How It Works

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

styles.scss
@use "sass:color";

$swatch: hsl(80deg 30% 50%);
$ink: #6b717f;

.names {
  // Modern unified reader (1.79+)
  --channel-hue: #{color.channel($swatch, "hue")};
  --channel-red: #{color.channel($ink, "red")};

  // Older space-specific getters (widely available)
  --getter-hue: #{color.hue($swatch)};
  --getter-red: #{color.red($ink)};
}

How It Works

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.

🚀 Real-World Use Cases

  • Contrast helpers — pick black or white text from lightness.
  • Design tokens — expose hue / saturation / alpha as CSS custom properties.
  • 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.

⚠️ Common Pitfalls

  • Unquoted channel names — use "hue", not bare hue, for $channel.
  • Old Dart Sasscolor.channel needs 1.79+; otherwise use color.red() / color.hue().
  • Expecting a colorchannel 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.

💡 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

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

Conclusion

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.

Continue with color.complement(), color.change(), or the CSS introduction.

Explore color.complement() Next

Rotate hue 180deg for complementary accents with the sass:color module.

Sass color.complement() →

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