Sass color.green()

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

Definition and Usage

color.green($color) returns the RGB green channel of a legacy color as a unitless number between 0 and 255. Global alias: green($color).

Official Sass docs mark it deprecated — prefer color.channel($color, "green") on Dart Sass 1.79+. Pair with color.red() and color.blue() when auditing a full RGB triple.

No longer recommended.

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

Official samples.

color.green(#e1d7d2) → 215. white → 255. black → 0.

Legacy colors only.

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

Syntax

SCSS
@use "sass:color";

// Deprecated reader
color.green(#e1d7d2); // 215
color.green(white);   // 255
color.green(black);   // 0

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

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

Migrate to color.channel

Side-by-side mapping:

Legacy / currentPrefer (1.79+)
color.green($c)color.channel($c, "green")
green($c) (global)color.channel($c, "green")
color.red($c) / color.blue($c)color.channel($c, "red") / "blue"
Force RGB spacecolor.channel($c, "green", $space: rgb)

To change green, use writers like color.adjust($c, $green: …) or color.change($c, $green: …) — not the reader.

SCSS Examples

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

Example 1 — Warm Hex Green Channel (Official Docs)

A soft taupe hex reports green 215.

SCSS
@use "sass:color";

@debug color.green(#e1d7d2); // 215

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

How It Works

  1. Legacy hex is read in RGB.
  2. Green channel is the unitless number 215.
  3. Interpolation writes it into a custom property.
  4. Same read via color.channel(#e1d7d2, "green") on 1.79+.

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

The extremes of the 8-bit green scale.

SCSS
@use "sass:color";

@debug color.green(white); // 255
@debug color.green(black); // 0

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

How It Works

  1. White maxes every RGB channel → green 255.
  2. Black zeros every channel → green 0.
  3. Handy check that your reader matches the official scale.
  4. Migration path should produce the same extremes.

Example 3 — Full RGB Report for a Brand Hex

Read red, green, and blue together for #336699.

SCSS
@use "sass:color";

$brand: #336699;

.rgb-report {
  --red: #{color.red($brand)};
  --green: #{color.green($brand)};
  --blue: #{color.blue($brand)};
}

How It Works

  1. Green sits in the middle (102) between red and blue.
  2. Matches the cool brand look of #336699.
  3. All three readers are deprecated siblings.
  4. Migrate to color.channel with "red" / "green" / "blue".

Example 4 — Detect a Lush Bias with Green vs Red

Compare channels on shorthand #0a3 (#00aa33).

SCSS
@use "sass:color";

.deep {
  --green: #{color.green(#0a3)};
  --bias: #{if(color.green(#0a3) > color.red(#0a3), "lush", "warm")};
}

How It Works

  1. Green is a plain number, so comparisons work in Sass.
  2. #0a3 expands to #00aa33.
  3. Green 170 > red 0 → label lush.
  4. On 1.79+, swap both calls to color.channel and keep the if().

Example 5 — Global green() with as *

Older stylesheets sometimes import the module into the current namespace.

SCSS
@use "sass:color" as *;

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

How It Works

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

Edge Cases & Pitfalls

Most green-reader bugs are writing vs reading, modern spaces, or confusing CSS named color.

read

Readers do not change green

color.green only returns a number. To shift green, use color.adjust / color.change with $green.

space

Legacy colors only for this helper

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

name

Not the CSS keyword green

color.green($c) reads a channel. The named color green is a different value entirely.

migrate

Quote the channel name

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

Sass Support

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

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

Compile with the Dart Sass CLI.

Key Takeaways

  • Reads RGB green as a unitless number from 0 to 255.
  • Deprecated in favor of color.channel($c, "green").
  • Siblings: color.red() and color.blue().
  • Writers use adjust/change with $green — not this reader.

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

Migrate Notes

Practical checklist:

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

Frequently Asked Questions

color.green($color) returns the RGB green channel as a number between 0 and 255. Example: color.green(#e1d7d2) is 215; color.green(white) is 255; color.green(black) 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, "green").
A unitless number from 0 to 255, matching classic 8-bit RGB green.
Official docs require a legacy color space (rgb, hsl, or hwb). Convert first, or use color.channel($color, "green", $space: rgb) on Dart Sass 1.79+.
color.red(), color.green(), and color.blue() are sibling deprecated readers for the three RGB channels. Prefer color.channel with "red", "green", or "blue" in new code.
Replace color.green($color) with color.channel($color, "green") after @use "sass:color" on Dart Sass 1.79+. Keep color.green only when maintaining older compilers or legacy SCSS.

Next: Sass color.hue()

Read the HSL hue dial — prefer color.channel in new code.

color.hue() →

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