Sass color.hue()

Beginner
11 min read
Updated: Nov 2026
5 examples
Compiled CSS

Definition and Usage

color.hue($color) returns the HSL hue of a legacy color as a number between 0deg and 360deg. Global alias: hue($color).

Official Sass docs mark it deprecated — prefer color.channel($color, "hue") on Dart Sass 1.79+. Pair with color.saturation() and color.lightness() when auditing a full HSL triple.

No longer recommended.

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

Official samples.

color.hue(#e1d7d2) → 20deg. #f2ece4 → 34.2857142857deg. #dadbdf → 228deg.

Legacy colors only.

$color must be in a legacy space (rgb, hsl, or hwb). For modern spaces, use color.channel(..., $space: hsl).

Syntax

SCSS
@use "sass:color";

// Deprecated reader
color.hue(#e1d7d2); // 20deg
color.hue(#f2ece4); // 34.2857142857deg
color.hue(#dadbdf); // 228deg

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

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

Migrate to color.channel

Side-by-side mapping:

Legacy / currentPrefer (1.79+)
color.hue($c)color.channel($c, "hue")
hue($c) (global)color.channel($c, "hue")
color.saturation($c) / color.lightness($c)color.channel($c, "saturation") / "lightness"
Force HSL spacecolor.channel($c, "hue", $space: hsl)

To rotate hue, use writers like color.adjust($c, $hue: …, $space: hsl) or the deprecated adjust-hue() — not the reader. For opposite hue, see color.complement().

SCSS Examples

Examples use color.hue(). Open View Compiled CSS for verified output (matches official Sass docs samples where noted).

Example 1 — Warm Hex Hue (Official Docs)

A soft taupe hex reports hue 20deg.

SCSS
@use "sass:color";

@debug color.hue(#e1d7d2); // 20deg

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

How It Works

  1. Legacy hex is mapped into HSL.
  2. Hue angle is 20deg (warm / orange-red band).
  3. Interpolation writes it into a custom property.
  4. Same read via color.channel(#e1d7d2, "hue") on 1.79+.

Example 2 — Cream and Cool Grays (Official Docs)

Two more official samples: a cream near orange-yellow, and a cool bluish gray.

SCSS
@use "sass:color";

@debug color.hue(#f2ece4); // 34.2857142857deg
@debug color.hue(#dadbdf); // 228deg

.palette {
  --cream: #{color.hue(#f2ece4)};
  --cool: #{color.hue(#dadbdf)};
}

How It Works

  1. Even soft neutrals carry a tiny hue.
  2. Cream sits near 34deg (warm).
  3. Cool gray sits near blue at 228deg.
  4. Useful when you sort tokens by warmth.

Example 3 — Primary Named Colors on the Wheel

Classic CSS names land on tidy wheel positions.

SCSS
@use "sass:color";

.wheel {
  --red: #{color.hue(red)};
  --lime: #{color.hue(lime)};
  --blue: #{color.hue(blue)};
}

How It Works

  1. Red is 0deg on the HSL wheel.
  2. Lime is 120deg; blue is 240deg.
  3. Landmarks make warm vs cool comparisons easier.
  4. Same idea after migrating to color.channel(..., "hue").

Example 4 — Hue From an HSL Color

When the input is already HSL, the hue dial matches what you wrote.

SCSS
@use "sass:color";

.card {
  --from-hsl: #{color.hue(hsl(200deg, 50%, 40%))};
  --brand: #{color.hue(#336699)};
}

How It Works

  1. hsl(200deg, …) reads back as 200deg.
  2. Brand hex #336699 lands nearby at 210deg.
  3. Both sit in the cool cyan–blue band.
  4. On 1.79+, use color.channel for the same numbers.

Example 5 — Global hue() with as *

Older stylesheets sometimes import the module into the current namespace.

SCSS
@use "sass:color" as *;

.panel {
  --hue: #{hue(#e1d7d2)};
}

How It Works

  1. as * brings members into the current scope.
  2. hue() matches color.hue().
  3. Result is still official 20deg.
  4. Prefer namespaced color.hue, then color.channel, when modernizing.

Edge Cases & Pitfalls

Most hue-reader bugs are writing vs reading, modern spaces, or forgetting the deg unit.

read

Readers do not rotate hue

color.hue only returns a number. To rotate, use color.adjust / adjust-hue with $hue.

space

Legacy colors only for this helper

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

unit

Result includes deg

Hue is still a Sass number, but it carries the deg unit — keep that in mind for math and comparisons.

migrate

Quote the channel name

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

Sass Support

color.hue() remains for compatibility. New readers should use color.channel on Dart Sass 1.79+.

APIStatus
color.hue() / hue()Deprecated reader — still works on legacy colors
color.channel($c, "hue")Preferred on Dart Sass 1.79+
LibSass / Ruby SassGlobal hue() may exist — no modern module path
BrowsersN/A — only see compiled CSS values

Compile with the Dart Sass CLI.

Key Takeaways

  • Reads HSL hue as a number from 0deg to 360deg.
  • Deprecated in favor of color.channel($c, "hue").
  • Siblings: color.saturation() and color.lightness().
  • Writers use adjust / adjust-hue / complement — not this reader.

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

Migrate Notes

Practical checklist:

migrate.txt
1. Find color.hue($c) / hue($c) in legacy SCSS
2. Require Dart Sass 1.79+ for color.channel
3. Replace with color.channel($c, "hue")
4. Add $space: hsl when reading non-legacy colors
5. Use adjust / complement when you need to write hue

Frequently Asked Questions

color.hue($color) returns the HSL hue of a legacy color as a number between 0deg and 360deg. Example: color.hue(#e1d7d2) is 20deg; color.hue(#f2ece4) is about 34.29deg; color.hue(#dadbdf) is 228deg.
Yes. Official Sass docs list it under Deprecated Functions and say it is no longer recommended because it is redundant with color.channel($color, "hue").
A number from 0deg to 360deg (with the deg unit). It is still a Sass number—meta.type-of reports number.
Official docs require a legacy color space (rgb, hsl, or hwb). Convert first, or use color.channel($color, "hue", $space: hsl) on Dart Sass 1.79+.
color.hue(), color.saturation(), and color.lightness() are sibling deprecated readers for the three HSL channels. Prefer color.channel with "hue", "saturation", or "lightness" in new code.
Replace color.hue($color) with color.channel($color, "hue") after @use "sass:color" on Dart Sass 1.79+. Keep color.hue only when maintaining older compilers or legacy SCSS.

Next: Sass lighten()

Deprecated helper that adds HSL lightness — prefer color.scale / adjust.

lighten() →

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