Sass
CSS preprocessor

Sass color.alpha() Function

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

What You’ll Learn

color.alpha() belongs to the built-in sass:color module (Deprecated Functions). It returns a color’s opacity as a number from 0 to 1 at compile time. This page covers the opacity() alias, the IE alpha(opacity=…) special case, the legacy-color rule, migration to color.channel(), and five compiled examples.

01

Concept

Read opacity 0–1

02

Status

Deprecated

03

Aliases

opacity() / alpha()

04

Legacy only

rgb / hsl / hwb

05

Migrate

color.channel()

06

Practice

5 examples

What Is color.alpha()?

Alpha means opacity. Official docs: color.alpha() returns the alpha channel of $color as a number between 0 (fully transparent) and 1 (fully opaque). It does not change the color—it only reads how see-through it is.

  • color.alpha(#e1d7d2)1 (opaque hex)
  • color.opacity(rgb(210, 225, 221, 0.4))0.4
  • color.alpha(rgba(3, 51, 102, 0))0
💡
Beginner tip

Think of a glass of colored water. 1 is solid paint; 0.4 is milky; 0 is invisible. Use color.alpha (or better, color.channel) when mixins or conditionals need that number—for example, “only add a shadow if this token is mostly opaque.”

📝 Syntax

Load the color module, or use the global aliases:

styles.scss
@use "sass:color";

// Deprecated — still works on legacy colors
color.alpha($color)
opacity($color)   // global alias
alpha($color)     // global alias

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

Parameters

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

Return value

TypeMeaning
Number 01Usual case: the color’s opacity (unitless).
Unquoted stringSpecial case: alpha(opacity=20) returns that IE filter string unchanged.

📦 Loading sass:color & Migrating

Official heads-up: because color.alpha() is redundant with color.channel(), prefer the channel reader in new SCSS.

styles.scss
@use "sass:color";

// Old (deprecated, still available)
$a: color.alpha(rgba(#036, 0.4)); // 0.4

// New — preferred on Dart Sass 1.79+
$a: color.channel(rgba(#036, 0.4), "alpha"); // 0.4

// Global aliases (legacy codebases)
$a: opacity(rgba(#036, 0.4));
$a: alpha(rgba(#036, 0.4));
⚠️
Version note for color.channel

color.channel() needs Dart Sass 1.79+. On older compilers (for example 1.69), keep color.alpha() / opacity() until you can upgrade—then migrate.

🎨 The IE alpha(opacity=…) Special Case

Official docs call out a historical quirk: global alpha(opacity=20) does not read a color. Sass supports the old Internet Explorer filter syntax and returns an unquoted string alpha(opacity=20).

  • Useful only when emitting legacy IE filter / -ms-filter CSS.
  • Do not confuse it with color.alpha($color), which returns 01.
  • New projects should avoid IE filter strings entirely.
💡
Related helper

For full #AARRGGBB IE filter colors, see color.ie-hex-str()—also a legacy / deprecated use case.

📋 color.alpha vs color.channel

Same number for opacity—different futures.

HelperJobStatus
color.alpha() / opacity()Read alpha on legacy colorsDeprecated / not recommended
color.channel($c, "alpha")Read alpha (and any other channel)Preferred modern API (1.79+)
color.adjust(..., $alpha: …)Change opacity relativelyWriter, not a reader

🛠 Compatibility

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

FeatureDart SassNotes
color.alpha() / opacity()Yes (deprecated)Legacy colors only
alpha(opacity=…) IE formYesReturns unquoted string
color.channel(…, "alpha")1.79+Official recommended replacement
LibSass / Ruby SassGlobals likelyMay lack modern @use / channel

⚡ Quick Reference

GoalCode
Opaque hexcolor.alpha(#e1d7d2)1
Partial opacitycolor.opacity(rgb(210, 225, 221, 0.4))0.4
Fully transparentcolor.alpha(rgba(3, 51, 102, 0))0
IE filter stringalpha(opacity=20)alpha(opacity=20)
Modern readcolor.channel($c, "alpha")
Change opacitycolor.adjust($c, $alpha: -0.2) or color.scale

Examples Gallery

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

📚 Getting Started

Official docs samples for opaque and translucent colors.

Example 1 — Opaque Hex Returns 1 (Official Docs)

A normal hex color has full opacity.

styles.scss
@use "sass:color";

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

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

How It Works

Hex colors without an alpha channel are treated as fully opaque, so color.alpha reports 1.

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

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

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

Whether you write color.alpha or color.opacity (module) / opacity (global), the result is the fourth channel of the rgba color: 0.4.

📈 Practical Patterns

IE special case, full range, and simple opacity logic.

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

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

styles.scss
@debug alpha(opacity=20); // alpha(opacity=20)

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

How It Works

Sass recognizes the Internet Explorer syntax and returns an unquoted string so the 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.

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

Any legacy color with an alpha channel reports a unitless number in the closed interval 01. Global opacity() matches color.alpha() for color arguments.

Example 5 — Branch on Opacity in a Mixin-Friendly Report

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

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

Because alpha is a plain number, you can compare it in Sass. On Dart Sass 1.79+, swap color.alpha($brand) for color.channel($brand, "alpha") and keep the same logic.

🚀 Real-World Use Cases

  • Reading legacy SCSS — recognize color.alpha / opacity() in older themes.
  • Safe migrations — replace with color.channel($c, "alpha") on Dart Sass 1.79+.
  • Token audits — flag colors that are fully transparent or nearly opaque.
  • Conditional mixins — skip shadows or borders when alpha is too low.
  • IE maintenance only — understand alpha(opacity=…) when editing old filter CSS.

🧠 How Compilation Works

1

Write SCSS

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

Source
2

Read alpha

Sass inspects the color’s opacity channel (legacy spaces).

Inspect
3

Emit a number

You get a unitless value from 0 to 1 (or an IE string).

Number
4

CSS sees the value

Custom properties and calc get finished numbers—not a Sass call.

⚠️ Common Pitfalls

  • Using it in new code — prefer color.channel($c, "alpha").
  • Confusing IE syntaxalpha(opacity=20) is a string, not 0.2.
  • Modern color spaces$color must be legacy for color.alpha.
  • Expecting a color back — this helper reads a number; use adjust / change to write opacity.
  • Assuming channel on old Sass — needs 1.79+; keep alpha until you upgrade.

💡 Best Practices

✅ Do

  • Migrate to color.channel($c, "alpha") on Dart Sass 1.79+
  • Use @use "sass:color" and namespaced calls when possible
  • Compare alpha numbers in mixins for token rules
  • Document when a token is intentionally translucent
  • Treat IE alpha(opacity=…) as legacy-only

❌ Don’t

  • Add new color.alpha() calls in greenfield projects
  • Pass modern oklch colors into color.alpha
  • Assume alpha(opacity=20) means 0.2
  • Expect the browser to re-run Sass at runtime
  • Use a reader when you meant to change opacity

Key Takeaways

Knowledge Unlocked

Five things to remember about color.alpha()

Deprecated opacity reader—migrate to color.channel.

5
Core concepts
⚠️ 02

Status

Deprecated

Docs
🎨 03

Returns

0 … 1 number

Read
📦 04

Alias

opacity() too

Global
05

Replace

channel(..., "alpha")

Migrate

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

Official Sass docs keep color.alpha() around for compatibility, but the modern story is one general reader: color.channel() can fetch alpha, red, hue, lightness, and more with the same API—so a dedicated alpha helper became redundant.

Conclusion

color.alpha() (and opacity()) read a legacy color’s opacity as a number from 0 to 1. Treat them as deprecated documentation: prefer color.channel($color, "alpha") for new SCSS on Dart Sass 1.79+.

Continue with color.opacity(), color.channel(), or color.adjust().

Next: color.opacity()

You learned deprecated color.alpha()—next is the opacity-named twin.

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

5 people found this page helpful