Sass color.alpha()

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

Definition and Usage

color.alpha($color) returns the alpha channel of a legacy color as a number between 0 and 1. Aliases: global alpha($color) and opacity($color) / color.opacity($color).

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

No longer recommended.

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

Official samples.

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

IE special case.

Global alpha(opacity=20) returns the unquoted string alpha(opacity=20) for old Internet Explorer filter syntax — it does not read a color.

Syntax

SCSS
@use "sass:color";

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

// IE filter echo (global only)
alpha(opacity=20);                           // alpha(opacity=20)

// Prefer today (Dart Sass 1.79+)
color.channel(#e1d7d2, "alpha");             // 1

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

Migrate to color.channel

Side-by-side mapping:

Legacy / currentPrefer (1.79+)
color.alpha($c)color.channel($c, "alpha")
color.opacity($c) / opacity($c)color.channel($c, "alpha")
alpha($c) (global)color.channel($c, "alpha")
alpha(opacity=20)Leave as IE filter string if needed; avoid in new CSS

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

SCSS Examples

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

Example 1 — Opaque Hex Returns 1 (Official Docs)

A normal hex color has full opacity.

SCSS
@use "sass:color";

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

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

How It Works

  1. Hex without alpha is treated as fully opaque.
  2. color.alpha reports 1.
  3. Interpolation writes the number into a custom property.
  4. Same result via color.channel(#e1d7d2, "alpha") on 1.79+.

Example 2 — Partial Opacity with opacity() (Official Docs)

The opacity() alias reads the same 0–1 number.

SCSS
@use "sass:color";

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

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

How It Works

  1. RGBA color carries a fourth channel of 0.4.
  2. color.opacity is an alias of the alpha reader.
  3. Global opacity() behaves the same for color args.
  4. Result is the unitless number 0.4.

Example 3 — IE alpha(opacity=20) String (Official Docs)

This call does not read a color — it echoes the IE filter function.

SCSS
@debug alpha(opacity=20); // alpha(opacity=20)

.legacy-ie {
  filter: #{alpha(opacity=20)};
}

How It Works

  1. IE filter syntax is a special global case.
  2. Sass returns an unquoted string, not a number.
  3. Compiled CSS keeps alpha(opacity=20).
  4. Skip this in modern stylesheets.

Example 4 — Transparent, Mid, and Opaque Values

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

SCSS
@use "sass:color";

.range {
  --zero: #{color.alpha(rgba(3, 51, 102, 0))};
  --mid: #{color.alpha(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. Global opacity() matches color.alpha() for colors.

Example 5 — Branch on Opacity

Use the alpha number in simple if() checks when building tokens.

SCSS
@use "sass:color";

$brand: rgba(#336699, 0.8);

.report {
  --alpha: #{color.alpha($brand)};
  --opaque: #{if(color.alpha($brand) >= 1, "yes", "no")};
  --half: #{if(color.alpha($brand) < 0.5, "faint", "solid-enough")};
}

How It Works

  1. Alpha is a plain number, so comparisons work in Sass.
  2. 0.8 >= 1 is false → no.
  3. 0.8 < 0.5 is false → solid-enough.
  4. On 1.79+, swap in color.channel($brand, "alpha") and keep the logic.

Edge Cases & Pitfalls

Most alpha-reader bugs are writing vs reading, IE syntax, or modern color spaces.

read

Readers do not change opacity

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

ie

alpha(opacity=…) is not a color read

That form returns a string for old filters. Do not expect a 0–1 number.

space

Legacy colors for color.alpha

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

migrate

Quote the channel name

Write color.channel($c, "alpha") with a quoted string — not an unquoted identifier.

Sass Support

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

APIStatus
color.alpha() / opacity()Deprecated reader — still works on legacy colors
color.channel($c, "alpha")Preferred on Dart Sass 1.79+
alpha(opacity=…)IE filter string special case
LibSass / Ruby SassGlobal opacity() / alpha() 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").
  • Aliases: opacity() / color.opacity() for color args.
  • IE alpha(opacity=) returns a string, not a number.

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

Migrate Notes

Practical checklist:

migrate.txt
1. Find color.alpha($c) / opacity($c) in legacy SCSS
2. Require Dart Sass 1.79+ for color.channel
3. Replace with color.channel($c, "alpha")
4. Leave alpha(opacity=…) alone only if IE filters remain
5. Use adjust/change/scale when you need to write alpha

Frequently Asked Questions

color.alpha($color) returns the alpha channel as a number between 0 and 1. Example: color.alpha(#e1d7d2) is 1; color.opacity(rgb(210, 225, 221, 0.4)) is 0.4.
Yes. Official Sass docs list it under Deprecated Functions and say it is no longer recommended because it is redundant with color.channel($color, "alpha").
For a color argument they are aliases: both return 0–1. opacity($color) is the same idea as color.alpha($color). Prefer the modern color.channel form in new code.
That is a special Internet Explorer filter syntax. Sass returns the unquoted string alpha(opacity=20) instead of reading a color’s alpha.
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.alpha($color) with color.channel($color, "alpha") after @use "sass:color" on Dart Sass 1.79+. Keep color.alpha only when maintaining older compilers or legacy SCSS.

Next: Sass opacity()

Same 0–1 reader under the opacity alias name.

opacity() →

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