Home Sass Color color.alpha() Sass color.alpha() Definition
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
Syntax @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").
Code
SCSS Examples Examples use color.alpha() / opacity() where noted. Open View Compiled CSS for verified output (matches official Sass docs samples).
1. Opaque 2. Partial 3. IE filter 4. Range 5. Logic Example 1 — Opaque Hex Returns 1 (Official Docs) A normal hex color has full opacity.
@use "sass:color";
@debug color.alpha(#e1d7d2); // 1
.swatch {
--alpha: #{color.alpha(#e1d7d2)};
} How It Works Hex without alpha is treated as fully opaque.color.alpha reports 1.Interpolation writes the number into a custom property.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.
@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 RGBA color carries a fourth channel of 0.4.color.opacity is an alias of the alpha reader.Global opacity() behaves the same for color args.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.
@debug alpha(opacity=20); // alpha(opacity=20)
.legacy-ie {
filter: #{alpha(opacity=20)};
} .legacy-ie {
filter: alpha(opacity=20);
} How It Works IE filter syntax is a special global case.Sass returns an unquoted string, not a number.Compiled CSS keeps alpha(opacity=20).Skip this in modern stylesheets.Example 4 — Transparent, Mid, and Opaque Values Compare 0, 0.75, and 0.5 in one report block.
@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))};
} .range {
--zero: 0;
--mid: 0.75;
--half: 0.5;
} How It Works Any legacy color with alpha reports a unitless 0…1 number.Fully transparent is 0.HSLA mid values keep their alpha channel.Global opacity() matches color.alpha() for colors.Example 5 — Branch on Opacity Use the alpha number in simple if() checks when building tokens.
@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")};
} .report {
--alpha: 0.8;
--opaque: no;
--half: solid-enough;
} How It Works Alpha is a plain number , so comparisons work in Sass.0.8 >= 1 is false → no.0.8 < 0.5 is false → solid-enough.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.
Toolchain
Sass Support color.alpha() remains for compatibility. New readers should use color.channel on Dart Sass 1.79+.
API Status 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 Sass Global opacity() / alpha() only — no modern module path
Compile with the Dart Sass CLI .
Remember
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
Migrate Notes Practical checklist:
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 What does Sass color.alpha() do? 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.
Is color.alpha() 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, "alpha").
What is the difference between alpha() and opacity()? 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.
What does alpha(opacity=20) do? That is a special Internet Explorer filter syntax. Sass returns the unquoted string alpha(opacity=20) instead of reading a color’s alpha.
Does color.alpha() work on oklch colors? 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+.
How do I migrate old color.alpha() calls? 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() → CODETOFUN NEWS
Stay Ahead in Tech Get the latest IT news, programming updates, and technology trends directly on your phone.
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