Sass
CSS preprocessor

Sass color.red() Function

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
Deprecated
sass:color · Dart Sass

What You’ll Learn

color.red() belongs to the built-in sass:color module (Deprecated Functions). It returns a legacy color’s RGB red channel as a unitless number from 0 to 255 at compile time. This page covers the RGB idea, siblings green / blue, migration to color.channel(), and five compiled examples.

01

Concept

RGB red 0–255

02

Status

Deprecated

03

Siblings

green() / blue()

04

Legacy only

rgb / hsl / hwb

05

Migrate

color.channel()

06

Practice

5 examples

What Is color.red()?

Red here means the first channel in classic RGB—how much red light the color mixes in. Official docs: color.red() returns that channel as a number between 0 and 255. It only reads the value; it does not tint the color red.

  • color.red(#e1d7d2)225
  • color.red(white)255
  • color.red(black)0
💡
Beginner tip

Think of a hex like #336699 as three dials: red 51, green 102, blue 153. color.red turns only the red dial into a number you can store, compare, or log—handy in mixins and design-token audits.

📝 Syntax

Load the color module, then pass a legacy color:

styles.scss
@use "sass:color";

// Deprecated — still works on legacy colors
color.red($color)

// Optional — bring members into scope
@use "sass:color" as *;
red($color)

// Recommended migration (Dart Sass 1.79+)
color.channel($color, "red")

Parameters

ParameterTypeDescription
$colorColorMust be in a legacy color space (rgb, hsl, or hwb).

Return value

TypeMeaning
Unitless numberRGB red from 0 to 255.

📦 Loading sass:color & Migrating

Prefer the namespaced form. Bare red() only works after @use "sass:color" as *;—otherwise CSS may keep the call as a plain string (or collide with the named color red in confusing ways).

styles.scss
@use "sass:color";

// Old (deprecated, still available)
$r: color.red(#e1d7d2); // 225

// New — preferred on Dart Sass 1.79+
$r: color.channel(#e1d7d2, "red");

// Optional global-style import
@use "sass:color" as *;
$r: red(#e1d7d2);
⚠️
Version note for color.channel

color.channel() needs Dart Sass 1.79+. On older compilers, keep color.red() until you can upgrade—then migrate.

🎨 RGB Trio: Red, Green, Blue

Official docs also list color.green() and color.blue() the same way (deprecated readers for the other two channels). Together they rebuild the classic rgb(r, g, b) triple from any legacy color.

  • Red high, blue low → often a warmer / more fiery look
  • Red 255 → full red channel (white has all three at 255)
  • Red 0 → no red light (black is all zeros)
💡
Writing red instead of reading

To change the red channel, use color.adjust() or color.change() with $red—not color.red(), which only returns a number.

📋 color.red vs color.channel

HelperJobStatus
color.red()Read RGB red on legacy colorsDeprecated / not recommended
color.channel($c, "red")Same read (and any other channel)Preferred on Dart Sass 1.79+
color.adjust(..., $red: …)Change red by a fixed amountWriter, not a reader

🛠 Compatibility

This is about Sass compilers, not browsers. Compiled CSS receives a finished number—no color.red() call remains at runtime.

FeatureDart SassNotes
color.red() / red()Yes (deprecated)Legacy colors only
Siblings green() / blue()Yes (deprecated)Same pattern for the other RGB channels
color.channel(…, "red")1.79+Official recommended replacement
LibSass / Ruby SassGlobals likelyMay lack modern @use / channel

⚡ Quick Reference

GoalCode
Warm hexcolor.red(#e1d7d2)225
Whitecolor.red(white)255
Blackcolor.red(black)0
Brand hexcolor.red(#336699)51
Modern readcolor.channel($c, "red")
Change redcolor.adjust($c, $red: 15)

Examples Gallery

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

📚 Getting Started

Official docs samples for everyday and extreme colors.

Example 1 — Warm Hex Red Channel (Official Docs)

A soft taupe hex reports red 225.

styles.scss
@use "sass:color";

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

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

How It Works

Sass reads the RGB red channel of the legacy hex and writes the unitless number into a custom property.

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

The extremes of the 8-bit red scale.

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

White maxes every RGB channel; black zeros them. Useful for checking that your reader and migration path match the official scale.

📈 Practical Patterns

Full RGB reports, warm-tone checks, and the global alias.

Example 3 — Full RGB Report for a Brand Hex

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

styles.scss
@use "sass:color";

$brand: #336699;

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

How It Works

Red sits lowest (51) under green 102 and blue 153—a cool brand bias. All three readers are deprecated—migrate to color.channel with "red" / "green" / "blue".

Example 4 — Detect a Warm Bias with Red vs Blue

Compare channels on shorthand #f20 (#ff2200).

styles.scss
@use "sass:color";

.accent {
  --red: #{color.red(#f20)};
  --bias: #{if(color.red(#f20) > color.blue(#f20), "warm", "cool")};
}

How It Works

Because red is a plain number, you can compare it to blue in Sass. On Dart Sass 1.79+, swap both calls to color.channel and keep the same if() logic.

Example 5 — Global red() with as *

Older stylesheets sometimes import the module into the current namespace.

styles.scss
@use "sass:color" as *;

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

How It Works

With as *, red() matches color.red(). Prefer the namespaced form (then color.channel) when you modernize the file—and do not confuse the reader with the CSS named color red.

🚀 Real-World Use Cases

  • Reading legacy SCSS — recognize color.red in older RGB workflows.
  • Safe migrations — replace with color.channel($c, "red") on Dart Sass 1.79+.
  • Token audits — report full RGB triples for brand hexes.
  • Conditional mixins — treat high-red colors as warm accents.
  • Teaching RGB — show that hex is three 0–255 dials.

🧠 How Compilation Works

1

Write SCSS

Call color.red($c) or migrate to color.channel.

Source
2

Map to RGB

Sass views the legacy color in red / green / blue coordinates.

RGB
3

Read red

You get a unitless value from 0 to 255.

Number
4

CSS sees the number

Custom properties get finished values—not a Sass call.

⚠️ Common Pitfalls

  • Using it in new code — prefer color.channel($c, "red").
  • Bare red() without as * — may compile as a CSS function/color string.
  • Modern color spaces$color must be legacy for color.red.
  • Confusing with CSS red — the named color is paint; this helper returns a number.
  • Expecting a color back — this helper reads a channel; use adjust/change to write.

💡 Best Practices

✅ Do

  • Migrate to color.channel($c, "red") on Dart Sass 1.79+
  • Use @use "sass:color" and namespaced color.red()
  • Pair with green/blue when auditing full RGB
  • Compare channel numbers in mixins for token rules
  • Document when a brand intentionally leans warm

❌ Don’t

  • Add new color.red() calls in greenfield projects
  • Pass modern oklch colors into color.red
  • Call bare red() without importing the module
  • Expect the browser to re-run Sass at runtime
  • Use a reader when you meant to change red

Key Takeaways

Knowledge Unlocked

Five things to remember about color.red()

Deprecated RGB red reader—migrate to color.channel.

5
Core concepts
⚠️ 02

Status

Deprecated

Docs
🎨 03

Returns

0 … 255

RGB
🔄 04

Siblings

green() / blue()

Trio
05

Replace

channel(..., "red")

Migrate

❓ 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.
Did you know?

Official Sass docs keep dedicated RGB readers like color.red() for compatibility, but the modern story is one API: color.channel($c, "red")—the same pattern you use for green, blue, hue, lightness, and more.

Conclusion

color.red() reads a legacy color’s RGB red channel as a number from 0 to 255. Treat it as deprecated documentation: prefer color.channel($color, "red") for new SCSS on Dart Sass 1.79+.

Continue with rgb(), color.green(), or color.channel().

Next: rgb()

You learned deprecated color.red()—next, build RGB colors with rgb().

rgb() →

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