Sass
CSS preprocessor

Sass color.opacity() Function

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

What You’ll Learn

color.opacity() belongs to the built-in sass:color module (Deprecated Functions, documented with color.alpha()). It returns how opaque a legacy color is as a number from 0 to 1 at compile time. This page covers the global opacity() alias, how it differs from the CSS opacity property, its twin color.alpha(), migration to color.channel(), and five compiled examples.

01

Concept

Read opacity 0–1

02

Status

Deprecated

03

Alias

color.alpha()

04

Not CSS

vs opacity property

05

Migrate

color.channel()

06

Practice

5 examples

What Is color.opacity()?

Opacity here means the color’s own alpha channel. Official docs: with color.alpha() / opacity(), Sass returns that channel as a number between 0 (invisible) and 1 (solid). The function reads opacity—it does not fade an element like CSS opacity does.

  • color.opacity(rgb(210, 225, 221, 0.4))0.4
  • color.opacity(#e1d7d2)1
  • opacity(rgba(#036, 0.5))0.5 (global alias)
💡
Beginner tip

If you came from CSS, the name opacity feels familiar—but Sass color.opacity($brand) answers “how see-through is this color token?” not “fade this whole box.” For the CSS property, write opacity: 0.5; in the stylesheet after compile.

📝 Syntax

Load the color module, or use the global alias:

styles.scss
@use "sass:color";

// Deprecated — still works on legacy colors
color.opacity($color)
opacity($color)       // global alias
color.alpha($color)   // same number for a color argument

// 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 01The color’s opacity (unitless). Same result as color.alpha($color).

📦 Loading sass:color & Migrating

Official heads-up (shared with alpha): prefer color.channel() in new SCSS because a dedicated opacity reader is redundant.

styles.scss
@use "sass:color";

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

// Same number via the alpha alias
$o: color.alpha(rgba(#036, 0.4)); // 0.4

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

// Global alias (legacy codebases)
$o: opacity(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.opacity() / opacity() until you can upgrade—then migrate.

🎨 Sass opacity() vs CSS opacity

Same English word, different jobs. Mixing them up is a common beginner mistake.

ToolWhen it runsWhat it affects
color.opacity($color)Sass compile timeReads one color’s alpha; returns 01
CSS opacity: …In the browserFades the entire element (and usually its children)
rgba() / hsl(… / a)Color value itselfOnly that paint is translucent; siblings stay solid
💡
Related twin page

Prefer the name alpha in docs searches? See color.alpha()—same deprecated reader, including the IE alpha(opacity=…) special case that opacity() does not use.

📋 color.opacity vs color.alpha vs channel

HelperJobStatus
color.opacity() / opacity()Read opacity on legacy colorsDeprecated / not recommended
color.alpha() / alpha()Same number for a color argumentDeprecated twin (+ IE string special case)
color.channel($c, "alpha")Modern opacity (and any channel) readerPreferred on Dart Sass 1.79+

🛠 Compatibility

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

FeatureDart SassNotes
color.opacity() / opacity()Yes (deprecated)Legacy colors only
Alias color.alpha()Yes (deprecated)Same 0–1 number for color args
color.channel(…, "alpha")1.79+Official recommended replacement
LibSass / Ruby SassGlobals likelyMay lack modern @use / channel

⚡ Quick Reference

GoalCode
Partial opacitycolor.opacity(rgb(210, 225, 221, 0.4))0.4
Opaque hexcolor.opacity(#e1d7d2)1
Global aliasopacity(rgba(#036, 0.5))0.5
Transparentcolor.opacity(rgba(3, 51, 102, 0))0
Modern readcolor.channel($c, "alpha")
Change opacitycolor.adjust($c, $alpha: -0.2) or color.scale

Examples Gallery

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

📚 Getting Started

Official and everyday opacity reads on legacy colors.

Example 1 — Partial Opacity (Official Docs)

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

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

Sass reads the fourth channel of the rgb color and writes the unitless number 0.4 into CSS—handy for custom properties and design-token reports.

Example 2 — Opaque Hex Returns 1

Same sample color the docs use with color.alpha, read via opacity.

styles.scss
@use "sass:color";

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

How It Works

Hex without an alpha channel is fully opaque, so color.opacity reports 1—identical to color.alpha(#e1d7d2).

📈 Practical Patterns

Global alias, full range, and proving the alpha twin.

Example 3 — Global opacity() Alias

Older stylesheets often call opacity() without the module namespace.

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

How It Works

The global built-in matches color.opacity for color arguments. When you modernize the file, switch to @use "sass:color" and later to color.channel.

Example 4 — Transparent, Mid, and Partial Values

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

styles.scss
@use "sass:color";

.range {
  --zero: #{color.opacity(rgba(3, 51, 102, 0))};
  --mid: #{color.opacity(hsla(210, 100%, 20%, 0.75))};
  --soft: #{color.opacity(rgb(210, 225, 221, 0.4))};
}

How It Works

Any legacy color with an alpha channel reports a unitless number in the closed interval 01. Use those numbers in mixins and maps.

Example 5 — Prove opacity Equals alpha

Same brand token, both readers, plus a simple visibility check.

styles.scss
@use "sass:color";

$brand: rgba(#336699, 0.65);

.report {
  --opacity: #{color.opacity($brand)};
  --visible: #{if(color.opacity($brand) > 0.5, "visible", "ghost")};
  --same: #{if(color.opacity($brand) == color.alpha($brand), "alias", "diff")};
}

How It Works

--same: alias confirms the twin APIs. On Dart Sass 1.79+, replace both calls with color.channel($brand, "alpha") and keep the same if() logic.

🚀 Real-World Use Cases

  • Reading legacy SCSS — recognize opacity($color) in older themes.
  • Safe migrations — replace with color.channel($c, "alpha") on Dart Sass 1.79+.
  • Token audits — flag translucent brands before shipping CSS variables.
  • Conditional mixins — skip shadows when opacity is too low.
  • Teaching CSS vs Sass — contrast the function with the CSS opacity property.

🧠 How Compilation Works

1

Write SCSS

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

Source
2

Read opacity

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

Inspect
3

Emit a number

You get a unitless value from 0 to 1.

Number
4

CSS sees the value

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

⚠️ Common Pitfalls

  • Using it in new code — prefer color.channel($c, "alpha").
  • Confusing with CSS opacity — the property fades elements; the function reads a color.
  • Modern color spaces$color must be legacy for color.opacity.
  • Expecting a color back — this helper reads a number; use adjust / change to write opacity.
  • Assuming channel on old Sass — needs 1.79+; keep opacity 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 opacity numbers in mixins for token rules
  • Document when a token is intentionally translucent
  • Teach the CSS-property difference to teammates

❌ Don’t

  • Add new color.opacity() calls in greenfield projects
  • Pass modern oklch colors into color.opacity
  • Write opacity: color.opacity($c) expecting element fade magic
  • 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.opacity()

Deprecated opacity reader—twin of alpha, migrate to channel.

5
Core concepts
⚠️ 02

Status

Deprecated

Docs
🎨 03

Returns

0 … 1 number

Read
🔄 04

Twin

color.alpha()

Alias
05

Replace

channel(..., "alpha")

Migrate

❓ Frequently Asked Questions

color.opacity($color) returns the color’s alpha channel as a number between 0 and 1. Example: color.opacity(rgb(210, 225, 221, 0.4)) is 0.4.
Yes. Official Sass docs list opacity() with color.alpha() under Deprecated Functions. Prefer color.channel($color, "alpha") on Dart Sass 1.79+.
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, or use color.channel($color, "alpha") 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.
Did you know?

Official Sass docs document opacity() on the same heading as color.alpha(). The friendly “opacity” name matches how designers talk, while the modern API standardizes on the channel name "alpha" inside color.channel().

Conclusion

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

Continue with color.blackness(), color.channel(), or color.alpha().

Next: color.blackness()

You learned deprecated color.opacity()—next is the HWB blackness reader.

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

5 people found this page helpful