rgb() is a global Sass color constructor documented with rgb() / rgba() under Built-In Modules. It creates RGB colors (opaque or with alpha), or sets a new alpha on an existing color with rgb($color, $alpha). This page covers classic and Level 4 signatures, the rgba() alias, when to prefer color.change(), and five compiled examples.
01
Kind
Global constructor
02
Status
Current (not deprecated)
03
Alias
rgba()
04
Level 4
Slash / spaces
05
Module twin
color.change()
06
Practice
5 examples
Concept
What Is rgb()?
In CSS, rgb() means “red, green, blue.” Sass evaluates it at compile time when the arguments are known numbers or colors, so your stylesheet can use the same familiar constructor designers know from CSS.
rgb(0 51 102) → rgb(0, 51, 102) (often written #036 in docs)
rgb(95%, 92.5%, 89.5%) → rgb(242, 236, 228)
rgb(#f2ece4, 50%) → rgba(242, 236, 228, 0.5)
💡
Beginner tip
Think of rgb() as “make a color from channels.” Need opacity on a brand hex without rewriting R/G/B? Use rgb($brand, 0.5)—same power as rgba($brand, 0.5) in modern Dart Sass.
Foundation
📝 Syntax
No @use is required—rgb() is global (like CSS). Official docs list these equivalent forms (also available as rgba()):
styles.scss
// Classic channels (alpha optional)
rgb($red, $green, $blue, $alpha: 1)
rgba($red, $green, $blue, $alpha)
// CSS Color Level 4 (Dart Sass 1.15+)
rgb($red $green $blue)
rgb($red $green $blue / $alpha)
// Set alpha on an existing color
rgb($color, $alpha)
rgba($color, $alpha)
Parameters
Parameter
Type
Description
$red / $green / $blue
Number
Channel values: unitless 0–255, or percentages 0%–100%.
$alpha
Number
Optional opacity: unitless 0–1, or a percentage 0%–100% (Dart Sass).
$color
Color
Used only in the two-argument form: keep channels, replace alpha.
Return value
Type
Meaning
Color
An RGB color (emitted as rgb(…), rgba(…), hex, or similar).
Unquoted string
When an argument is a special CSS function such as var()—Sass leaves the call for the browser.
Details
🎨 Classic Commas vs Level 4 Slash
Modern CSS (and Dart Sass 1.15+) allows space-separated channels and a slash before alpha. Both styles compile to the same colors.
Style
Example
Notes
Commas
rgb(0, 51, 102, 0.5)
Best when any channel is a variable
Spaces + slash
rgb(0 51 102 / 50%)
CSS Color Level 4 look; Dart Sass 1.15+
Opaque spaces
rgb(0 51 102)
No alpha needed
⚠️
Slash + variables
Official docs warn that Sass slash rules make rgb($r $g $b / $alpha) awkward when $b or $alpha is a variable. Prefer rgb($r, $g, $b, $alpha).
Compare
📋 rgb() vs rgba()
In modern Dart Sass they are aliases. Pick the name that matches your team’s habit; the math is the same. See the dedicated rgba() page for opacity-first examples.
Modern Dart Sass
LibSass / older rules
Relationship
rgb ≡ rgba
Stricter: alpha required on rgba, forbidden on rgb
Runtime themes — keep var(--opacity) inside rgb() for live control.
Bridge to modules — same idea as color.change(..., $alpha:).
🧠 How Compilation Works
1
Write SCSS
Call rgb(…) with channels, optional alpha, or var().
Source
2
Dart Sass decides
Known numbers become a color; special CSS args stay as a string.
Compile
3
Channels resolved
Percentages map to 0–255; optional alpha becomes opacity.
RGB
4
✓
CSS ships
Browsers see rgb/rgba, hex, or a var() call.
Watch Out
⚠️ Common Pitfalls
Slash form with variables — prefer commas for $blue / $alpha variables.
LibSass name rules — older engines may reject alpha on rgb(); use rgba() there.
Expecting runtime Sass — number alphas are baked at compile time.
Confusing with channel readers — color.red() reads a channel; rgb() builds a color.
Assuming deprecation — rgb() is current; helpers like opacify are the deprecated ones.
Pro Tips
💡 Best Practices
✅ Do
Use rgb($token, $alpha) for translucent variants of one brand color
Prefer comma form when any channel is a variable
Use Level 4 slash syntax for literal values if your team likes modern CSS
Reach for color.change inside module-heavy files
Treat rgb() and rgba() as interchangeable on Dart Sass
❌ Don’t
Hand-copy R/G/B every time you need a new opacity of the same token
Rely on slash syntax with variables without testing the compile
Assume LibSass supports every modern signature
Confuse constructors with deprecated adjust helpers
Expect the browser to understand Sass-only module calls
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about rgb()
Global RGB constructor—optional alpha, Level 4 friendly.
5
Core concepts
📝01
Call
rgb(…) / rgba(…)
API
✓02
Status
Not deprecated
Docs
🎨03
Level 4
spaces / slash
CSS
⚡04
Token form
rgb($c, $a)
Alpha
🛠05
Module twin
color.change
sass:color
❓ Frequently Asked Questions
rgb() builds an RGB color from red, green, and blue channels, optionally with alpha. Example: rgb(0 51 102) is rgb(0, 51, 102); rgb(#f2ece4, 50%) is rgba(242, 236, 228, 0.5).
In modern Dart Sass, yes—they are aliases and accept the same signatures. Historically rgba required alpha and rgb forbade it; LibSass still follows those stricter name rules.
No. Official Sass docs list rgb()/rgba() 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 rgb(#6b717f, 0.5).
Sass slash-parsing rules make rgb($r $g $b / $alpha) awkward when $b or $alpha is a variable. Official docs recommend rgb($r, $g, $b, $alpha) instead.
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.
Did you know?
CSS Color Module Level 4 treats rgba() as an alias of rgb(). Modern Dart Sass mirrors that, so rgb($color, 0.5) and rgba(0, 51, 102) are both valid—while LibSass still prefers the older split between the two names.
rgb() is Sass’s CSS-friendly way to build RGB colors—opaque or with alpha—and to stamp opacity onto a token with rgb($color, $alpha). It is a current global constructor (aliased with rgba()), not a deprecated color helper. Prefer commas when channels are variables, and reach for color.change($color, $alpha: …) when you already live in sass:color.