Sass color.opacity()

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

Definition and Usage

color.opacity($color) returns the alpha channel of a legacy color as a number between 0 and 1. It is an alias of color.alpha($color) (and the global opacity($color) form).

Official Sass docs mark it deprecated — prefer color.channel($color, "alpha") on Dart Sass 1.79+.

No longer recommended.

Because color.opacity() / color.alpha() are redundant with color.channel(), migrate opacity reads to the channel API in new code.

Official samples.

color.opacity(rgb(210, 225, 221, 0.4)) → 0.4. color.alpha(#e1d7d2) → 1.

Not the CSS property.

Sass color.opacity() reads one color token at compile time. CSS opacity fades a whole element (and its children) in the browser.

Syntax

SCSS
@use "sass:color";

// Deprecated readers (still work on legacy colors)
color.opacity(rgb(210, 225, 221, 0.4));      // 0.4
color.alpha(#e1d7d2);                        // 1
opacity(rgba(#036, 0.5));                    // 0.5

// Prefer today (Dart Sass 1.79+)
color.channel(rgb(210, 225, 221, 0.4), "alpha"); // 0.4

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

Migrate to color.channel

Side-by-side mapping:

Legacy / currentPrefer (1.79+)
color.opacity($c)color.channel($c, "alpha")
opacity($c) (global)color.channel($c, "alpha")
color.alpha($c) / alpha($c)color.channel($c, "alpha")
CSS opacity: …Leave as a browser property — not a Sass color reader

To change opacity, use writers like color.adjust($c, $alpha: …), color.scale($c, $alpha: …), or color.change($c, $alpha: …) — not color.opacity.

SCSS Examples

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

Example 1 — Partial Opacity (Official Docs)

The docs highlight color.opacity on a translucent rgb color.

SCSS
@use "sass:color";

@debug color.opacity(rgb(210, 225, 221, 0.4)); // 0.4

.mint {
  --opacity: #{color.opacity(rgb(210, 225, 221, 0.4))};
}

How It Works

  1. RGBA color carries a fourth channel of 0.4.
  2. color.opacity reads that channel as a unitless number.
  3. Interpolation writes 0.4 into a custom property.
  4. Same result via color.alpha or color.channel(…, "alpha").

Example 2 — Opaque Hex Returns 1

A normal hex color has full opacity — same sample the docs use with color.alpha.

SCSS
@use "sass:color";

@debug color.opacity(#e1d7d2); // 1

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

How It Works

  1. Hex without alpha is treated as fully opaque.
  2. color.opacity reports 1.
  3. Identical to color.alpha(#e1d7d2).
  4. On 1.79+, prefer color.channel(#e1d7d2, "alpha").

Example 3 — Global opacity() Alias

Without @use, the built-in global name still reads 0–1 for a color.

SCSS
.panel {
  --opacity: #{opacity(rgba(#036, 0.5))};
}

How It Works

  1. Global opacity() is listed beside color.alpha in the docs.
  2. Color argument yields the same 0–1 number.
  3. No module import is required for this legacy form.
  4. New code should still migrate to color.channel.

Example 4 — Transparent, Mid, and Half Values

Compare 0, 0.75, and 0.5 in one report block.

SCSS
@use "sass:color";

.range {
  --zero: #{color.opacity(rgba(3, 51, 102, 0))};
  --mid: #{color.opacity(hsla(210, 100%, 20%, 0.75))};
  --half: #{opacity(rgba(#036, 0.5))};
}

How It Works

  1. Any legacy color with alpha reports a unitless 0…1 number.
  2. Fully transparent is 0.
  3. HSLA mid values keep their alpha channel.
  4. Module and global forms agree for color arguments.

Example 5 — Prefer color.channel

Same opacity read, modern API — drop the deprecated reader name.

SCSS
@use "sass:color";

$brand: rgba(#336699, 0.8);

// Old: color.opacity($brand)
.report {
  --opacity: #{color.channel($brand, "alpha")};
  --opaque: #{if(color.channel($brand, "alpha") >= 1, "yes", "no")};
}

How It Works

  1. Quote the channel name: "alpha".
  2. Result is still a plain number, so comparisons work.
  3. 0.8 >= 1 is false → no.
  4. Requires Dart Sass 1.79+ for color.channel.

Edge Cases & Pitfalls

Most opacity-reader bugs are CSS confusion, writing vs reading, or modern color spaces.

css

Sass opacity ≠ CSS opacity

color.opacity($brand) answers how see-through a color token is. It does not emit opacity: 0.5; for an element.

read

Readers do not change opacity

color.opacity only returns a number. To fade a color, use color.adjust / color.change / color.scale.

ie

IE alpha(opacity=…) is not opacity()

That special filter string belongs to global alpha(). See the color.alpha page — opacity() does not use that form.

space

Legacy colors for color.opacity

Official docs require rgb / hsl / hwb. Prefer color.channel for modern spaces on Dart Sass 1.79+.

Sass Support

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

APIStatus
color.opacity() / opacity()Deprecated reader — still works on legacy colors
color.alpha()Same deprecated reader (alias)
color.channel($c, "alpha")Preferred on Dart Sass 1.79+
LibSass / Ruby SassGlobal opacity() only — no modern module path

Compile with the Dart Sass CLI.

Key Takeaways

  • Reads opacity as a unitless number from 0 to 1.
  • Deprecated in favor of color.channel($c, "alpha").
  • Alias of color.alpha() for color arguments.
  • Not CSS opacity — compile-time color read only.

One line: use color.opacity to understand old code — write new opacity reads with color.channel.

Migrate Notes

Practical checklist:

migrate.txt
1. Find color.opacity($c) / opacity($c) in legacy SCSS
2. Require Dart Sass 1.79+ for color.channel
3. Replace with color.channel($c, "alpha")
4. Do not confuse with CSS opacity on elements
5. Use adjust/change/scale when you need to write alpha

Frequently Asked Questions

color.opacity($color) returns the alpha channel as a number between 0 and 1. Example: color.opacity(rgb(210, 225, 221, 0.4)) is 0.4; opaque hex like #e1d7d2 reports 1.
Yes. Official Sass docs list opacity() with color.alpha() under Deprecated Functions because it is redundant with color.channel($color, "alpha").
Yes for a color argument. They are aliases that both return 0–1. Official samples use color.opacity() and color.alpha() interchangeably.
Sass color.opacity() reads one color’s alpha at compile time and returns a number. The CSS opacity property fades a whole element (and its children) in the browser.
Official docs require a legacy color space (rgb, hsl, or hwb). Convert first with color.to-space(), or read alpha with color.channel on Dart Sass 1.79+.
Replace color.opacity($color) with color.channel($color, "alpha") after @use "sass:color" on Dart Sass 1.79+. Keep opacity() only when maintaining older compilers or legacy SCSS.

Next: Sass color.blackness()

Read HWB blackness as 0%–100% on legacy colors.

blackness() →

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