Sass color.red()

Beginner
11 min read
Updated: Nov 2026
5 examples
Deprecated reader

Definition and Usage

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

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

No longer recommended.

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

Official samples.

color.red(#e1d7d2) → 225. 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.red(#e1d7d2); // 225
color.red(white);   // 255
color.red(black);   // 0

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

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

Migrate to color.channel

Side-by-side mapping:

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

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

SCSS Examples

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

Example 1 — Warm Hex Red Channel (Official Docs)

A soft taupe hex reports red 225.

SCSS
@use "sass:color";

@debug color.red(#e1d7d2); // 225

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

How It Works

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

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

The extremes of the 8-bit red scale.

SCSS
@use "sass:color";

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

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

How It Works

  1. White maxes every RGB channel → red 255.
  2. Black zeros every channel → red 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. Red is the lowest channel (51) in this cool brand.
  2. Matches the blue-leaning look of #336699.
  3. All three readers are deprecated siblings.
  4. Migrate to color.channel with "red" / "green" / "blue".

Example 4 — Detect a Warm Bias with Red vs Green

Compare channels on shorthand #c30 (#cc3300).

SCSS
@use "sass:color";

.ember {
  --red: #{color.red(#c30)};
  --bias: #{if(color.red(#c30) > color.green(#c30), "warm", "cool")};
}

How It Works

  1. Red is a plain number, so comparisons work in Sass.
  2. #c30 expands to #cc3300.
  3. Red 204 > green 51 → label warm.
  4. On 1.79+, swap both calls to color.channel and keep the if().

Example 5 — Global red() with as *

Older stylesheets sometimes import the module into the current namespace.

SCSS
@use "sass:color" as *;

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

How It Works

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

Edge Cases & Pitfalls

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

read

Readers do not change red

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

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 red

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

migrate

Quote the channel name

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

Sass Support

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

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

Compile with the Dart Sass CLI.

Key Takeaways

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

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

Migrate Notes

Practical checklist:

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

Frequently Asked Questions

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

Next: Sass rgb()

Build colors from red, green, and blue channels.

rgb() →

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