Sass interpolation embeds a SassScript expression into CSS with #{ }. This page covers where it works, when you should skip it, quoted-string quirks, safe number handling, and five compiled examples.
01
Syntax
#{expr}
02
Where
Selectors & more
03
Skip
Normal values
04
Strings
Quotes stripped
05
Units
Avoid #{}px
06
Practice
5 examples
Concept
What Is Sass Interpolation?
Official docs: wrap an expression in #{ } to inject its result into a chunk of CSS. Think of it as “paste this computed text here”—into a class name, a property name, a URL path, a keyframes name, or a loud comment.
Evaluates at compile time—the CSS file contains only the final text.
In SassScript, interpolation always produces an unquoted string.
Quoted strings lose their quotes when interpolated (even inside lists).
Rarely needed for plain property values—use the variable directly.
💡
Beginner tip
Ask: “Am I building CSS text (a name, a path, a selector piece)?” If yes, interpolate. If you only need a color, size, or other value, use $variable without #{ }.
Official fun fact: other than injecting into strings, interpolation is rarely necessary in SassScript. You do not need it to use a variable as a property value.
Avoid
Prefer
color: #{$accent};
color: $accent;
width: #{$width}px;
width: $width * 1px; (or store px on $width)
#{$string} only to unquote
string.unquote($string)
💡
Heads up — numbers
Interpolating a number returns an unquoted string. You lose further math and Sass’s unit safeguards. Bogus CSS like 10pxpx can slip through if $width already had units.
Details
🧮 SassScript & Quoted Strings
Inside SassScript, interpolation injects text into unquoted strings—handy for dynamic animation names or slash-separated values. The result is always an unquoted string.
One special case: quotation marks around quoted strings are removed when interpolated. That lets you store selector-like text in a quoted string and inject it into a rule. When you only want to unquote, prefer string.unquote().
Cheat Sheet
⚡ Quick Reference
Goal
Code
Dynamic class
.icon-#{$name}
Dynamic property
#{$side}: 0;
Path in URL
url("/icons/#{$name}.svg")
Keyframes name
@keyframes #{$name} { … }
Loud comment math
/* sum = #{1 + 1} */
Safe unit attach
$n * 1px (not #{$n}px)
Hands-On
Examples Gallery
Each example shows a core interpolation pattern. Open View Compiled CSS for verified output.
📚 Getting Started
Official-style mixin and everyday selector/property injection.
Example 1 — Corner Icon Mixin (Official Pattern)
Interpolate into a selector, a URL, and property names in one mixin.
Both lines output an unquoted string. Prefer string.unquote when unquoting is the only goal; keep #{ } when you are injecting into a larger piece of CSS text.
Example 4 — Dynamic @keyframes Name
Inject a name into an at-rule, then reuse the same variable for animation-name.
Modern Dart Sass also allows @media (min-width: $bp) without braces—both work. Inside the loud comment, #{"compile"} strips quotes and #{1 + 1} becomes 2.
Applications
🚀 Real-World Use Cases
BEM / theme classes — .btn-#{$variant}.
Directional properties — #{$side}-margin helpers.
Asset URLs — url("/icons/#{$name}.svg").
Generated motion — unique or parameterized @keyframes names.
Build banners — version or math inside loud comments.
🧠 How Compilation Works
1
Find #{ }
Locate interpolation in selectors, names, strings, at-rules.
Scan
2
Evaluate expression
Run SassScript inside the braces (vars, math, calls).
Compute
3
Inject as text
Paste the result (quotes stripped for quoted strings).
Inject
4
✓
CSS ships
No #{ } remains—only concrete CSS text.
Watch Out
⚠️ Common Pitfalls
color: #{$accent} — unnecessary; use $accent.
#{$n}px — stringifies numbers; prefer $n * 1px.
Trying to build $theme-#{$name} variables — illegal; use a map.
Using #{ } only to unquote — call string.unquote instead.
Expecting runtime changes — interpolation is compile-time only.
Pro Tips
💡 Best Practices
✅ Do
Interpolate when building selectors, property names, and paths
Keep units on numbers with Sass math (* 1px)
Use string.unquote when unquoting is the only goal
Pass plain variables into property values without braces
Document why a name must be dynamic (theme, side, variant)
❌ Don’t
Wrap every variable in #{ } “just in case”
Glue units with string interpolation
Invent variable names via interpolation
Lose type safety by stringifying values you still need to compute with
Forget that quoted strings lose their quotes inside #{ }
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Sass interpolation
Inject text wisely—skip it for ordinary values and units.
5
Core concepts
📝01
#{ }
inject CSS text
Basics
🎯02
Names & paths
best use cases
Where
❌03
Not for values
use $var bare
Skip
🔢04
No #{}px
use * 1px
Units
✓05
Quotes drop
or unquote()
Strings
❓ Frequently Asked Questions
Interpolation embeds a SassScript expression into CSS by wrapping it in #{ }. Example: .icon-#{$name} becomes .icon-mail when $name is mail.
Almost anywhere CSS text is written: selectors, property names, custom property values, CSS at-rules, @extend, plain CSS @import, quoted or unquoted strings, special functions, plain CSS function names, and loud comments.
No. Official docs: instead of color: #{$accent}, write color: $accent. Interpolation is for injecting values into identifiers, strings, and other CSS syntax—not ordinary SassScript values.
Interpolation returns an unquoted string, so you lose Sass math and unit checks. Prefer $width * 1px, or declare $width with px from the start.
Yes. #{"string"} injects string without quotes. Prefer string.unquote($string) when your goal is only to unquote.
In SassScript, interpolation always returns an unquoted string. That is useful for dynamic names and slash-separated values, but not for further math.
Did you know?
Official Sass docs recommend building unique animation names with interpolation plus unique-id() (or meta.unique-id()) so generated keyframes never collide when a mixin is included many times.
Sass interpolation pastes compiled SassScript into CSS text with #{ }. Use it for names and paths; skip it for ordinary values; never glue units with string interpolation.