Sass String Operators

Beginner
8 min read
Updated: Nov 2026
5 examples
Dart Sass

Definition and Usage

Sass has a few operators that generate strings. The useful one is + (concatenate). Binary - is a legacy joiner—prefer interpolation.

Official sample idea.

"Helvetica" + " Neue" is "Helvetica Neue"; sans- + serif is unquoted sans-serif.

Quote rule for +.

If either side is a quoted string, the result is quoted; otherwise it stays unquoted.

Prefer #{ }.

Official guidance: interpolation is often cleaner than relying on these operators.

Syntax

SCSS
$a + $b          // concatenate (prefer this over binary -)
$a - $b          // legacy: unquoted "$a-$b"  — prefer #{$a}-#{$b}
/ $value         // unary: unquoted "/..."
- $value         // unary: unquoted "-..."

"Helvetica" + " Neue"; // "Helvetica Neue"
sans- + serif;         // sans-serif
"Elapsed time: " + 10s; // "Elapsed time: 10s"

// Clearer alternative:
#{$prefix}-#{$name}

Pattern: join text with + (or #{}) → get a quoted or unquoted string → use in CSS.

+ vs - vs #{ }

When to use each approach:

FormUse when
+Simple concatenation; quote state follows either-quoted rule
Binary -Legacy only — prefer #{$a}-#{$b}
#{$value}Clearest way to inject values into identifiers / strings
Unary / / -Historical; rarely needed in new code

SCSS Examples

Open View Compiled CSS for verified Dart Sass output (matches official Sass docs samples where shown).

Example 1 — Official String Samples

Quoted +, unquoted +, and legacy binary -.

SCSS
@use "sass:meta";

.probe {
  --a: #{meta.inspect("Helvetica" + " Neue")};
  --b: #{meta.inspect(sans- + serif)};
  --c: #{meta.inspect(sans - serif)};
}

How It Works

  1. Quoted + quoted stays quoted.
  2. Unquoted + stays unquoted.
  3. Binary - inserts a hyphen (legacy).
  4. Matches the official Sass docs samples.

Example 2 — Concatenate Non-Strings

Most CSS-writable values work on the right (or as the quoted left).

SCSS
@use "sass:meta";

.mixed {
  --a: #{meta.inspect("Elapsed time: " + 10s)};
  --b: #{meta.inspect(true + " is a boolean value")};
}

How It Works

  1. Quoted left forces a quoted result.
  2. 10s is written into the string.
  3. true becomes the text true.
  4. Numbers/colors cannot be the left-hand value.

Example 3 — Unary / and -

Historical operators that prefix a value with / or -.

SCSS
@use "sass:meta";

.unary {
  --a: #{meta.inspect(/ 15px)};
  --b: #{meta.inspect(- moz)};
}

How It Works

  1. Unary / builds /15px.
  2. Unary - builds -moz.
  3. Both results are unquoted strings.
  4. Rare in modern stylesheets.

Example 4 — Build content with +

Quoted left side keeps a quoted CSS string for content.

SCSS
$mod: primary;

.btn-#{$mod} {
  content: "btn-" + $mod;
}

How It Works

  1. #{ } builds the class name.
  2. "btn-" + concatenates the label.
  3. Quoted result is valid for content.
  4. Same idea works for other stringy CSS values.

Example 5 — Prefer Interpolation

Build text without leaning on + or legacy -.

SCSS
$a: "Helvetica";
$b: " Neue";

.font {
  font-family: #{$a}#{$b}, sans-serif;
}

How It Works

  1. #{ } injects each piece.
  2. Quotes from the variables are stripped in the injection.
  3. Readable for names and identifiers.
  4. Official preference over string operators alone.

Edge Cases & Pitfalls

Most string-operator bugs are left-hand types or legacy -.

left

Numbers/colors cannot lead +

Put the string on the left: "size: " + 10px, not 10px + " wide".

legacy

Avoid binary - for joining

Use #{$a}-#{$b} instead of $a - $b.

quotes

Either-quoted forces quoted

One quoted operand makes the whole + result quoted.

vs math

+ on numbers is math

10px + 5px adds lengths. See numeric operators.

Sass Support

String operators are core SassScript on Dart Sass.

OperatorStatus
Binary +Concatenate; quote if either side is quoted
Binary -Legacy hyphen join — prefer interpolation
Unary / / -Historical prefix strings
Preferred alternative#{$value} interpolation

Compile with the Dart Sass CLI.

Key Takeaways

  • + concatenates; quote state follows either-quoted.
  • Binary - is legacy — prefer #{}.
  • Non-strings OK (except number/color on the left).
  • Interpolation is clearer for most string building.

One line: concatenate with +, or prefer #{$value} when clarity matters more.

Compile Notes

Practical checklist:

checklist.txt
1. Use + for simple concatenation
2. Remember either-quoted => quoted result
3. Avoid binary -; use #{$a}-#{$b}
4. Keep numbers/colors off the left of +
5. Prefer interpolation for readable string building

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 -.
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.

Next: Sass Boolean Operators

Combine conditions with not, and, and or.

Boolean →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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