Sass Strings

Beginner
⏱️ 14 min read
📚 Updated: Jul 2026
🎯 5 Examples
Quoted & unquoted

What You’ll Learn

Sass strings are sequences of Unicode characters. This page covers quoted vs unquoted strings, escapes, interpolation, 1-based indexes, quote / unquote, and five compiled examples.

01

Quoted

"…"

02

Unquoted

Identifiers

03

Escapes

\ & Unicode

04

Interpolate

Quotes drop

05

Indexes

Start at 1

06

Practice

5 examples

What Are Sass Strings?

Official docs: strings are sequences of characters (Unicode code points). Sass supports two kinds whose internal structure is the same but which render differently:

  • Quoted strings"Helvetica Neue" (CSS string values)
  • Unquoted strings (identifiers) — bold (CSS keywords / names)

Together they cover the different kinds of text that appear in CSS. Convert with string.quote() and string.unquote() from @use "sass:string".

💡
Beginner tip

Default to quoted strings. Use unquoted strings when you specifically need a CSS identifier (font weight keywords, vendor prefixes, custom property names).

📝 Syntax

styles.scss
$family: "Helvetica Neue"; // quoted
$weight: bold;             // unquoted identifier
$prefix: ms;               // unquoted
$vendor: -#{$prefix}-flex; // -ms-flex

📄 Quoted Strings

Write quoted strings between single or double quotes. They support interpolation and standard escapes. Sass guarantees the compiled CSS string has the same contents (exact quote style may vary by implementation).

  • Escape a backslash as \\
  • Escape the active quote as \" or \'
  • Escape a newline as \a (backslash, a, trailing space)
💡
Fun fact

When a quoted string is injected via interpolation (#{$var}), its quotes are removed. That is how .#{$widget} with $widget: "my-widget" becomes a real selector without extra quotes.

🏷️ Unquoted Strings

Unquoted strings follow CSS identifier syntax and may include interpolation anywhere. They compile without surrounding quotes.

Looks like textActually parsed as
bold, -webkit-flexUnquoted string
red, navyColor
nullNull
true / falseBoolean
and / or / notBoolean operators

Official docs also treat some special CSS tokens as unquoted strings, including url(…), Unicode ranges like U+4??, some hash tokens, standalone %, and !important.

🔒 Escapes

All Sass strings support standard CSS escapes: write \ before a character, or \ plus a hexadecimal Unicode code point (optional trailing space). For characters that are already allowed in strings, the Unicode escape produces the same string as typing the character itself.

🔢 String Indexes

Official docs: string functions use indexes that refer to characters. Index 1 is the first character (not 0). Negative indexes count from the end: -1 is the last character, -2 the second-to-last, and so on.

styles.scss
@use "sass:string";

@debug string.index("Helvetica Neue", "Neue"); // 11
@debug string.slice("Roboto Mono", -4);        // "Mono"

⚡ Quick Reference

GoalCode
Quoted string"Helvetica Neue"
Unquoted identifierbold
Add quotesstring.quote(bold)
Remove quotesstring.unquote(".widget:hover")
Find substringstring.index($s, "Neue")
Slice from endstring.slice($s, -4)
Build a selector.#{$widget} → quotes stripped

Examples Gallery

Each example shows how Sass treats text at compile time. Open View Compiled CSS for verified output.

📚 Getting Started

Convert quote styles and inject quoted text into selectors.

Example 1 — string.quote() & string.unquote()

Official-docs style conversion between quoted and unquoted forms.

styles.scss
@use "sass:string";
@use "sass:meta";

.demo {
  --u: #{meta.inspect(string.unquote(".widget:hover"))};
  --q: #{meta.inspect(string.quote(bold))};
  --t1: #{meta.type-of(string.unquote(".widget:hover"))};
  --t2: #{meta.type-of(string.quote(bold))};
}

How It Works

Both results are still type string. The difference is whether CSS output includes surrounding quotes.

Example 2 — Quoted Interpolation & Selectors

Build a font name with #{}, then inject a quoted class name into a selector.

styles.scss
@use "sass:meta";

$widget: "my-widget";
$roboto-variant: "Mono";

.quoted {
  font-family: "Helvetica Neue", sans-serif;
  --font: #{meta.inspect("Roboto #{$roboto-variant}")};
}

.#{$widget} {
  color: navy;
}

How It Works

Inside another quoted string, interpolation keeps a quoted result. In .#{$widget}, quotes are stripped so the selector is valid CSS.

📈 Identifiers, Escapes & Indexes

Vendor prefixes, escape normalization, and 1-based indexing.

Example 3 — Unquoted Identifiers (and Lookalikes)

Build a vendor prefix, then prove that red / null / true are not strings.

styles.scss
@use "sass:meta";

$prefix: ms;

.unquoted {
  font-weight: bold;
  display: -#{$prefix}-flex;
  --a: #{meta.inspect(bold)};
  --b: #{meta.inspect(-webkit-flex)};
  --c: #{meta.inspect(--123)};
  --d: #{meta.type-of(red)};
  --e: #{meta.type-of(null)};
  --f: #{meta.type-of(true)};
}

How It Works

Interpolation builds -ms-flex. Color names and keywords are special values, which is why quoting text is usually safer.

Example 4 — Escapes in Quoted & Unquoted Strings

Escape quotes and paths; see how unquoted escapes normalize in Dart Sass.

styles.scss
@use "sass:string";
@use "sass:meta";

.escapes {
  --quote: #{meta.inspect("\"")};
  --path: #{meta.inspect("C:\\Program Files")};
  --nl-len: #{meta.inspect(string.length("line1\a line2"))};
  --bang: #{meta.inspect(\21)};
  --esc-len: #{meta.inspect(string.length(\7Fx))};
}

How It Works

\a inserts a newline (length counts it). Unquoted \21 normalizes to \!; \7Fx becomes five characters after normalization.

Example 5 — Indexes Start at 1

Find substrings and slice from the end with negative indexes.

styles.scss
@use "sass:string";
@use "sass:meta";

.indexes {
  --i1: #{meta.inspect(string.index("Helvetica Neue", "Helvetica"))};
  --i2: #{meta.inspect(string.index("Helvetica Neue", "Neue"))};
  --slice: #{meta.inspect(string.slice("Roboto Mono", -4))};
  --missing: #{meta.inspect(string.index("Roboto", "x"))};
}

How It Works

"Helvetica" starts at index 1. string.slice(..., -4) grabs the last four characters. A miss returns null (falsey for @if).

🚀 Real-World Use Cases

  • Font stacks — quoted family names with spaces.
  • Dynamic selectors — interpolate quoted class/BEM names.
  • Vendor prefixes — build unquoted -ms- / -webkit- identifiers.
  • Content / paths — escaped quotes and Windows-style paths.
  • Parsing helpersstring.index / slice inside functions.

🧠 How Compilation Works

1

Parse the text

Decide quoted vs unquoted; apply escapes and special-token rules.

Parse
2

Interpolate

Insert values; strip quotes when injecting into surrounding CSS.

Inject
3

Normalize escapes

Dart Sass normalizes unquoted escapes so equivalent CSS means match.

Normalize
4

CSS ships

Quoted CSS strings or bare identifiers appear in the output file.

⚠️ Common Pitfalls

  • Assuming color names are stringsred is a color.
  • 0-based indexes — Sass string indexes start at 1.
  • Unexpected quotes in selectors — remember interpolation strips them.
  • Using unquoted true / null as text — quote them if you need strings.
  • Building numbers with #{$n}px — that makes a string, not a number.

💡 Best Practices

✅ Do

  • Prefer quoted strings by default
  • Use @use "sass:string" for quote / index / slice helpers
  • Interpolate quoted names into selectors when generating classes
  • Escape backslashes in Windows-style paths
  • Treat null from string.index as “not found”

❌ Don’t

  • Assume every identifier-looking token is a string
  • Start counting characters at 0
  • Leave quotes on when you need a bare CSS keyword
  • Use string tricks to fake numbers with units
  • Forget trailing space after \a newline escapes

Key Takeaways

Knowledge Unlocked

Five things to remember about Sass strings

Quoted vs unquoted, safe escapes, and indexes that start at one.

5
Core concepts
02

Prefer quotes

safer default

Habit
🔀 03

#{} strips

quotes drop

Inject
🔢 04

Indexes

start at 1

API
05

Lookalikes

color / bool

Parse

❓ Frequently Asked Questions

Strings are sequences of Unicode characters. Sass has quoted strings (like "Helvetica Neue") and unquoted strings/identifiers (like bold). Internally they are the same type; they render differently in CSS.
Prefer quoted strings unless you are writing a CSS property that needs an unquoted identifier. Color names, null, true/false, and and/or/not are not parsed as unquoted strings.
Use string.quote() to add quotes and string.unquote() to remove them. Load them with @use "sass:string".
No. Index 1 is the first character. Negative indexes count from the end: -1 is the last character.
When a quoted string is injected via #{…}, its quotes are removed. That makes it easy to build selectors from quoted variables.
It returns null, which is falsey—handy inside @if conditions.
Did you know?

Official Sass docs recommend quoted strings in most cases because many identifier-looking tokens—color names, null, booleans, and boolean operators—are parsed as other value types.

Conclusion

Sass strings cover quoted CSS text and unquoted identifiers. Prefer quotes by default, interpolate carefully, and remember that string indexes start at 1.

Continue with Sass Colors or string operators.

Next: Sass Colors

Learn hex, HSL, color spaces, and sass:color transforms.

Sass Colors →

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