Sass String Operators

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
+ & legacy - · #{}

What You’ll Learn

Sass string operators build strings at compile time. The main tool is + for concatenation. You will also see the legacy binary -, historical unary / and -, quote rules, and why interpolation is often clearer—plus five compiled examples.

01

Concat

+

02

Quotes

Quoted / unquoted

03

Legacy

Binary -

04

Unary

/ & -

05

Prefer

#{} interpolation

06

Practice

5 examples

What Are String Operators?

Official docs: Sass supports a few operators that generate strings. They run when Sass compiles—not in the browser.

  • + joins two values into one string.
  • Binary - joins with a hyphen (legacy—prefer interpolation).
  • Unary / and - prefix a value (historical).
  • They work with more than strings: booleans, times, and other CSS-writable values.
  • Numbers and colors cannot be the left-hand value of +.
💡
Beginner tip

For most new code, write #{$family} #{$weight} or #{$prefix}-#{$name} instead of chaining operators. Official docs say interpolation is often cleaner and clearer.

📝 Syntax

styles.scss
// Concatenation (preferred operator)
$a + $b

// Legacy hyphen join (prefer interpolation)
$a - $b

// Clearer modern style
#{$a}#{$b}
#{$a}-#{$b}

Operators

OperatorNameResult
+concatenationBoth values in one string (quoted if either side is quoted)
- (binary)legacy hyphen joinUnquoted string with - between the values
/ (unary)historical prefixUnquoted string starting with /
- (unary)historical prefixUnquoted string starting with -

Official samples

ExpressionResult
"Helvetica" + " Neue""Helvetica Neue"
sans- + serifsans-serif (unquoted)
sans - serifsans-serif (legacy)

❛ Quoted vs Unquoted Results

Official docs: if either value is a quoted string, the result will be quoted; otherwise, it will be unquoted.

LeftRightResult style
QuotedQuoted / unquoted / otherQuoted string
UnquotedQuotedQuoted string
UnquotedUnquotedUnquoted string

Use meta.inspect() while learning—it shows quote marks clearly in the compiled custom property.

📦 Not Just Strings

Official docs: these operators can be used with any values that can be written to CSS, with a few exceptions.

  • Numbers cannot be the left-hand value (they have numeric operators).
  • Colors cannot be the left-hand value (they used to have their own operators).
  • Putting the string on the left is the safe pattern: "Elapsed time: " + 10s.
ExpressionResult
"Elapsed time: " + 10s"Elapsed time: 10s"
true + " is a boolean value""true is a boolean value"

⚠️ Legacy Binary -

Official docs: binary - returns an unquoted string that contains both expressions’ values, separated by -. It is a legacy operator—interpolation should generally be used instead.

styles.scss
// Legacy
@font-face {
  font-family: sans - serif; // works, but legacy
}

// Clearer
$a: sans;
$b: serif;
.font {
  font-family: #{$a}-#{$b};
}
💡
Do not confuse with numeric minus

When the left side is a number, - is subtraction (10px - 2px, not string joining. Keep string joins on identifiers or use #{}.

➖ Unary / and -

Official docs: for historical reasons, Sass also supports / and - as unary operators that take only one value.

ExpressionResult
/ 15px/15px
- moz-moz

These exist mainly for old vendor-prefix and slash patterns. Prefer writing the literal string or using interpolation in new code.

✨ Prefer Interpolation

Official docs: it’s often cleaner and clearer to use interpolation to create strings, rather than relying on these operators.

styles.scss
$mod: dark;
$side: top;

.theme-#{$mod} {
  color: #111;
}

.pad {
  margin-#{$side}: 1rem;
}

$family: "Roboto";
$weight: "Bold";
.title {
  font-family: #{$family} #{$weight}, sans-serif;
}
  • Works in selectors, property names, and values.
  • Avoids quote-rule surprises from +.
  • Pairs well with string.quote / string.unquote when needed.

⚡ Quick Reference

GoalCode
Concatenate$a + $b
Join with hyphen (modern)#{$a}-#{$b}
Join with hyphen (legacy)$a - $b
Dynamic selector.theme-#{$mod}
Dynamic propertymargin-#{$side}: 1rem
Inspect quotesmeta.inspect($a + $b)
String on the left"Label: " + $value

Examples Gallery

Each example builds strings at compile time. Open View Compiled CSS for verified output (quotes shown with meta.inspect where helpful).

📚 Getting Started

Official concatenation and legacy hyphen samples.

Example 1 — Basic Concatenation

Quoted join, unquoted join, and legacy binary -.

styles.scss
@use "sass:meta";

.ops {
  --q: #{meta.inspect("Helvetica" + " Neue")};
  --u1: #{meta.inspect(sans- + serif)};
  --u2: #{meta.inspect(sans - serif)};
}

How It Works

Quoted inputs keep quotes. Unquoted identifiers stay unquoted. sans - serif uses the legacy hyphen joiner and matches sans- + serif here.

Example 2 — Mixed Types

Concatenate a string with a time or a boolean.

styles.scss
@use "sass:meta";

.ops {
  --mix1: #{meta.inspect("Elapsed time: " + 10s)};
  --mix2: #{meta.inspect(true + " is a boolean value")};
  --name: #{meta.inspect("theme-" + dark)};
}

How It Works

Keep a string on at least one side (usually the left) so Sass builds text instead of trying number or color math.

📈 Practical Patterns

Unary prefixes, font stacks, and modern interpolation.

Example 3 — Unary Prefixes

Historical unary / and - string prefixes.

styles.scss
@use "sass:meta";

.ops {
  --unary-slash: #{meta.inspect(/ 15px)};
  --unary-dash: #{meta.inspect(- moz)};
}

How It Works

Matches the official docs. Useful for reading legacy code; for new work, write /15px or -moz directly (or interpolate).

Example 4 — Font Name Building

Concatenate family pieces, then emit a font stack.

styles.scss
$family: "Roboto";
$weight: "Bold";
$prefix: ms;

.font-a {
  font-family: #{$family + " " + $weight}, sans-serif;
}

.font-b {
  font-family: #{$prefix}-segoe UI, sans-serif;
}

.btn {
  content: #{"Click" + " " + "here"};
}

How It Works

+ builds the Sass string; interpolation places it into CSS. Quotes may drop when the value is emitted as a CSS identifier or unquoted content.

Example 5 — Interpolation Patterns

Dynamic class names and property names without relying on operators.

styles.scss
@use "sass:meta";

$mod: dark;
$side: top;

.theme-#{$mod} {
  --name: #{meta.inspect("theme-" + $mod)};
  color: #111;
}

.pad {
  margin-#{$side}: 1rem;
}

How It Works

Interpolation is the modern default for selectors and property names. You can still use + inside a value when a single string token is handy.

🚀 Real-World Use Cases

  • Theme class names.theme-#{$mode}.
  • Directional propertiesmargin-#{$side}, border-#{$side}-radius.
  • Font stacks — join family tokens before emitting CSS.
  • Debug labels"Elapsed: " + $duration in comments or custom props.
  • BEM-style names#{$block}__#{$element} via interpolation.

🧠 How Compilation Works

1

Write a join

Use +, legacy -, or #{} interpolation.

Source
2

Build a Sass string

Apply quote rules and convert CSS-writable values to text.

Compile
3

Place into CSS

Emit as a value, selector piece, or property name.

Emit
4

CSS ships

Browsers only see finished text like .theme-dark.

⚠️ Common Pitfalls

  • Number on the left10s + " left" is not string concat.
  • Color on the left — put the string first instead.
  • Legacy - — prefer #{$a}-#{$b}.
  • Quote surprises — one quoted side makes the whole + result quoted.
  • Confusing with math — numeric +/- win when numbers lead.

💡 Best Practices

✅ Do

  • Prefer #{} interpolation for selectors and names
  • Use + when you truly need one concatenated string
  • Keep a string on the left when mixing types
  • Inspect quote state with meta.inspect
  • Reach for string.quote / string.unquote when needed

❌ Don’t

  • Rely on legacy binary - in new code
  • Put numbers or colors on the left of string +
  • Overuse unary / and - prefixes
  • Expect browsers to concatenate Sass strings
  • Forget that quotes affect the + result type

Key Takeaways

Knowledge Unlocked

Five things to remember about Sass string operators

Build strings at compile time—and prefer interpolation for clarity.

5
Core concepts
02

Quotes

either side quoted

Rule
⚠️ 03

Legacy

binary -

Avoid
04

Prefer

#{} interpolation

Modern
05

Left side

string first

Habit

❓ Frequently Asked Questions

Operators that build strings at compile time. The main one is + for concatenation. There is also a legacy binary - that joins values with a hyphen, plus historical unary / and -.
Official docs: if either value is a quoted string, the result is quoted; otherwise it is unquoted. Example: "Helvetica" + " Neue" is quoted; sans- + serif is unquoted.
Generally no. Official docs call binary - a legacy operator and recommend interpolation instead, such as #{$a}-#{$b}.
Yes, with most CSS-writable values. Numbers and colors cannot be the left-hand value because they have (or used to have) their own operators. Example: "Elapsed time: " + 10s works.
For historical reasons, / value returns an unquoted string starting with /, and - value returns an unquoted string starting with -. Example: / 15px → /15px, - moz → -moz.
Often yes. Official docs say it is often cleaner and clearer to use interpolation (#{$value}) to create strings rather than relying on these operators.
Did you know?

Official Sass docs recommend interpolation over string operators for clarity—even though "Helvetica" + " Neue" still works perfectly for quoted concatenation.

Conclusion

Sass string operators—especially +—build text at compile time. Know the quote rules, treat binary - as legacy, and reach for #{} interpolation when clarity matters most.

Continue with boolean operators or browse string.quote().

Next: Sass Boolean Operators

Combine conditions with not, and, and or.

Boolean operators →

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