Home Sass Color color.green() Sass color.green() Definition
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
Syntax @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").
Code
SCSS Examples Examples use color.green(). Open View Compiled CSS for verified output (matches official Sass docs samples where noted).
1. Hex 2. White / black 3. RGB report 4. Lush bias 5. Global alias Example 1 — Warm Hex Green Channel (Official Docs) A soft taupe hex reports green 215.
@use "sass:color";
@debug color.green(#e1d7d2); // 215
.swatch {
--green: #{color.green(#e1d7d2)};
} .swatch {
--green: 215;
} How It Works Legacy hex is read in RGB.Green channel is the unitless number 215.Interpolation writes it into a custom property.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.
@use "sass:color";
@debug color.green(white); // 255
@debug color.green(black); // 0
.extremes {
--white: #{color.green(white)};
--black: #{color.green(black)};
} .extremes {
--white: 255;
--black: 0;
} How It Works White maxes every RGB channel → green 255.Black zeros every channel → green 0.Handy check that your reader matches the official scale.Migration path should produce the same extremes.Example 3 — Full RGB Report for a Brand Hex Read red, green, and blue together for #336699.
@use "sass:color";
$brand: #336699;
.rgb-report {
--red: #{color.red($brand)};
--green: #{color.green($brand)};
--blue: #{color.blue($brand)};
} .rgb-report {
--red: 51;
--green: 102;
--blue: 153;
} How It Works Green sits in the middle (102) between red and blue.Matches the cool brand look of #336699.All three readers are deprecated siblings.Migrate to color.channel with "red" / "green" / "blue".Example 4 — Detect a Lush Bias with Green vs Red Compare channels on shorthand #0a3 (#00aa33).
@use "sass:color";
.deep {
--green: #{color.green(#0a3)};
--bias: #{if(color.green(#0a3) > color.red(#0a3), "lush", "warm")};
} .deep {
--green: 170;
--bias: lush;
} How It Works Green is a plain number , so comparisons work in Sass.#0a3 expands to #00aa33.Green 170 > red 0 → label lush.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.
@use "sass:color" as *;
.panel {
--green: #{green(#e1d7d2)};
} How It Works as * brings members into the current scope.green() matches color.green().Result is still official 215.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.
Toolchain
Sass Support color.green() remains for compatibility. New readers should use color.channel on Dart Sass 1.79+.
API Status color.green() / green()Deprecated reader — still works on legacy colors color.channel($c, "green")Preferred on Dart Sass 1.79+ LibSass / Ruby Sass Global green() may exist — no modern module path Browsers N/A — only see compiled CSS values
Compile with the Dart Sass CLI .
Remember
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
Migrate Notes Practical checklist:
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 What does Sass color.green() do? 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.
Is color.green() deprecated? 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").
What range does color.green() return? A unitless number from 0 to 255, matching classic 8-bit RGB green.
Does color.green() work on oklch colors? 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+.
How do red, green, and blue readers relate? 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.
How do I migrate old color.green() calls? 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 Developer, cloud engineer, and technical writer
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
Helpful Share Copy link Suggestion