Sass rgba()

Beginner
12 min read
Updated: Nov 2026
5 examples
Global constructor

Definition and Usage

rgba() is a global Sass color constructor. It builds an RGB color with an alpha channel, or sets a new alpha on an existing color with rgba($color, $alpha).

Official Sass docs list it under Global Functions with rgb() as aliases in modern Dart Sass. It is not deprecated.

Official samples.

rgba(95%, 92.5%, 89.5%, 0.2) → rgba(242, 236, 228, 0.2). rgb(#f2ece4, 50%) / rgba(#f2ece4, 50%) → rgba(242, 236, 228, 0.5). rgba(rgba(0, 51, 102, 0.5), 1) → #003366.

No @use required.

rgba() stays global so it can extend CSS. For module-style alpha writes, prefer color.change($c, $alpha: …).

Syntax

SCSS
// Classic four-channel form
rgba($red, $green, $blue, $alpha)
rgb($red, $green, $blue, $alpha: 1)   // same idea in Dart Sass

// CSS Color Level 4 (Dart Sass 1.15+)
rgba($red $green $blue / $alpha)
rgb($red $green $blue / $alpha)

// Set alpha on an existing color
rgba($color, $alpha)
rgb($color, $alpha)

Channels: unitless 0–255 or percentages 0%–100%. Alpha: unitless 0–1 or a percentage (Dart Sass).

Forms & Aliases

Pick a signature by what you already have:

NeedPrefer
RGB + alpha (numbers)rgba(0, 51, 102, 0.5)
Level 4 look (literals)rgba(0 51 102 / 50%)
Channels are variablesrgba($r, $g, $b, $a) — avoid slash form
Keep channels, set opacityrgba($brand, 0.5) or color.change($brand, $alpha: 0.5)
Same API, shorter namergb(…) — alias in Dart Sass
Slash + variables.

Official docs warn that Sass slash rules make rgba($r $g $b / $alpha) awkward when $b or $alpha is a variable. Use commas instead.

SCSS Examples

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

Example 1 — Classic Four-Channel rgba()

The form most stylesheets still use every day.

SCSS
.panel {
  background: rgba(0, 51, 102, 0.5);
  border-color: rgba(107, 113, 127, 0.5);
}

How It Works

  1. Four numbers set red, green, blue, and alpha.
  2. Alpha 0.5 means half-opaque.
  3. Sass evaluates known numbers at compile time.
  4. Same result via rgb(0, 51, 102, 0.5) in Dart Sass.

Example 2 — Percentage Channels + Alpha (Official Docs)

Channels can be percentages; alpha stays unitless or percent.

SCSS
@debug rgba(95%, 92.5%, 89.5%, 0.2); // rgba(242, 236, 228, 0.2)

.cream {
  background: rgba(95%, 92.5%, 89.5%, 0.2);
}

How It Works

  1. Percent RGB maps onto the 0–255 scale.
  2. Alpha 0.2 keeps the cream translucent.
  3. Matches the official Sass docs sample.
  4. Opaque twin without alpha is #f2ece4.

Example 3 — rgba($color, $alpha) (Official Docs)

Keep brand channels; only replace opacity — or restore full opacity.

SCSS
@debug rgba(#f2ece4, 50%); // rgba(242, 236, 228, 0.5)
@debug rgba(rgba(0, 51, 102, 0.5), 1); // #003366

.overlay {
  background: rgba(#f2ece4, 50%);
}

.solid {
  color: rgba(rgba(0, 51, 102, 0.5), 1);
}

How It Works

  1. Two-argument form takes a color plus a new alpha.
  2. Percent alpha works in Dart Sass (50% → 0.5).
  3. Alpha 1 restores a fully opaque navy.
  4. Module twin: color.change($c, $alpha: 0.5).

Example 4 — Level 4 Slash Alpha

Same navy at 50% using space + slash syntax.

SCSS
.panel {
  background: rgba(0 51 102 / 50%);
}

How It Works

  1. Spaces separate R, G, and B.
  2. Slash introduces the alpha channel.
  3. 50% means half-opaque.
  4. Compiled CSS uses classic rgba() for broad support.

Example 5 — Prefer Commas with Variables

When channels live in variables, use the comma signature.

SCSS
$r: 0;
$g: 51;
$b: 102;
$a: 0.75;

.card {
  // Prefer commas when any channel is a variable
  background: rgba($r, $g, $b, $a);
  border-color: rgba($r, $g, $b, 1);
}

How It Works

  1. Variables hold each channel and alpha.
  2. Comma form avoids slash-as-division ambiguity.
  3. With alpha < 1, Sass emits rgba(…).
  4. Alpha 1 can emit opaque navy as hex.

Edge Cases & Pitfalls

Most rgba() bugs are slash + variables, percent alpha on old compilers, or confusing constructors with writers.

slash

Avoid slash form with variables

Use rgba($r, $g, $b, $a). The Level 4 slash form is fine for literals.

libsass

Older compilers are stricter

LibSass expects alpha on rgba() (required) and forbids it on rgb(). Percent alpha needs Dart Sass.

var

var() stays for the browser

rgba(0 51 102 / var(--opacity)) returns an unquoted string so CSS variables resolve at runtime.

write

rgba() builds; opacify() adjusts

Do not confuse the constructor with deprecated writers like opacify() / transparentize().

Sass Support

rgba() / rgb() are current global constructors. Level 4 space/slash forms need Dart Sass 1.15+.

APIStatus
rgba() / rgb() (Dart Sass)Current aliases — all listed signatures
Space / slash syntaxDart Sass 1.15+
Percent alphaDart Sass (not LibSass)
LibSass / Ruby SassStricter: alpha required on rgba, forbidden on rgb (plus rgba($color, $alpha))
color.change($c, $alpha: …)Module alternative for alpha writes

Compile with the Dart Sass CLI.

Key Takeaways

  • Global constructor — builds RGB + alpha at compile time.
  • Not deprecated — listed under Global Functions.
  • Alias of rgb() in modern Dart Sass.
  • Use commas when channels are variables; slash is for literals.

One line: use rgba() to build translucent RGB tokens — prefer commas with variables, and color.change when you already live in sass:color.

Compile Notes

Practical checklist:

checklist.txt
1. Build translucent colors with rgba($r, $g, $b, $a)
2. Use Level 4 rgba(... / $alpha) for literals if you like that look
3. Prefer commas whenever variables are involved
4. Use rgba($color, $alpha) to keep channels and set opacity
5. Or color.change($color, $alpha: ...) inside @use "sass:color"

Frequently Asked Questions

rgba() builds an RGB color with an alpha channel, or replaces the alpha of an existing color. Example: rgba(95%, 92.5%, 89.5%, 0.2) is rgba(242, 236, 228, 0.2); rgba(#f2ece4, 50%) is rgba(242, 236, 228, 0.5).
In modern Dart Sass, yes—rgba() is an alias of rgb(). Both accept the same signatures, including rgba($color, $alpha) and the Level 4 slash form.
No. Official Sass docs list rgba()/rgb() under Global Functions as CSS-compatible color constructors. They are not in the Deprecated Functions list.
When you already use @use "sass:color" and only need to set alpha (or other channels) on a token. color.change(#6b717f, $alpha: 0.5) matches rgba(#6b717f, 0.5).
Yes in Dart Sass: rgba(#f2ece4, 50%) compiles to rgba(242, 236, 228, 0.5). LibSass does not support percent alpha.
If you pass special CSS functions like var() for a channel, Sass returns an unquoted string with the same signature so the browser can resolve it at runtime.

Next: Sass saturate()

Deprecated fixed saturation increase — prefer color.scale.

saturate() →

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