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
Concept
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:
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).
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
🏷️ Unquoted Strings
Unquoted strings follow CSS identifier syntax and may include interpolation anywhere. They compile without surrounding quotes.
Looks like text
Actually parsed as
bold, -webkit-flex
Unquoted string
red, navy
Color
null
Null
true / false
Boolean
and / or / not
Boolean 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
🔒 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.
Indexes
🔢 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.
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.
Watch Out
⚠️ Common Pitfalls
Assuming color names are strings — red 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.
Pro Tips
💡 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
Summary
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
📄01
Two kinds
quoted / bare
Basics
✅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.
Sass strings cover quoted CSS text and unquoted identifiers. Prefer quotes by default, interpolate carefully, and remember that string indexes start at 1.