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
Concept
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.
Foundation
📝 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
Parameter
Type
Description
$color
Color
Must be in a legacy color space (rgb, hsl, or hwb).
Return value
Type
Meaning
Number 0–1
The color’s opacity (unitless). Same result as color.alpha($color).
Modules
📦 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.
Details
🎨 Sass opacity() vs CSS opacity
Same English word, different jobs. Mixing them up is a common beginner mistake.
Tool
When it runs
What it affects
color.opacity($color)
Sass compile time
Reads one color’s alpha; returns 0–1
CSS opacity: …
In the browser
Fades the entire element (and usually its children)
rgba() / hsl(… / a)
Color value itself
Only 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.
Compare
📋 color.opacity vs color.alpha vs channel
Helper
Job
Status
color.opacity() / opacity()
Read opacity on legacy colors
Deprecated / not recommended
color.alpha() / alpha()
Same number for a color argument
Deprecated twin (+ IE string special case)
color.channel($c, "alpha")
Modern opacity (and any channel) reader
Preferred on Dart Sass 1.79+
Support
🛠 Compatibility
This is about Sass compilers, not browsers. Compiled CSS receives a finished number—no color.opacity() call remains at runtime.
Feature
Dart Sass
Notes
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 Sass
Globals likely
May lack modern @use / channel
Cheat Sheet
⚡ Quick Reference
Goal
Code
Partial opacity
color.opacity(rgb(210, 225, 221, 0.4)) → 0.4
Opaque hex
color.opacity(#e1d7d2) → 1
Global alias
opacity(rgba(#036, 0.5)) → 0.5
Transparent
color.opacity(rgba(3, 51, 102, 0)) → 0
Modern read
color.channel($c, "alpha")
Change opacity
color.adjust($c, $alpha: -0.2) or color.scale
Hands-On
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.
--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.
Applications
🚀 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.
Watch Out
⚠️ 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.
Pro Tips
💡 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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about color.opacity()
Deprecated opacity reader—twin of alpha, migrate to channel.
5
Core concepts
📝01
Call
color.opacity($c)
API
⚠️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().
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+.