Sass Strings

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

Definition and Usage

Strings are sequences of Unicode characters. Sass has two kinds with the same internal type but different CSS output: quoted ("Helvetica Neue" and unquoted identifiers like bold.

Prefer quoted by default.

Use unquoted only when CSS needs an identifier. Color names, null, true/false, and and/or/not are not unquoted strings.

Interpolation strips quotes.

Injecting a quoted string with #{ } removes the quotes—handy for selectors. See interpolation.

Indexes start at 1.

1 is the first character; -1 is the last. Missing searches return null.

Syntax

SCSS
@use "sass:string";

"Helvetica Neue";          // quoted
bold;                      // unquoted identifier
"Roboto #{$variant}";      // interpolation inside quotes

string.quote(bold);        // "bold"
string.unquote(".a:hover"); // .a:hover

string.index($s, "Neue");  // 1-based index, or null
string.slice($s, -4);      // from near the end

Pattern: pick quoted or unquoted → convert with string.quote / string.unquote → search/slice with 1-based indexes.

Common Patterns

Everyday string tools:

PatternResult idea
"text" / 'text'Quoted string (CSS string)
bold / -ms-flexUnquoted identifier
string.quote() / unquote()Convert between forms
#{$quoted}Quotes removed when interpolating
string.index / slice1-based indexes (-1 = last)
\a / \1F46DCSS-style escapes

SCSS Examples

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

Example 1 — Official quote / unquote

Convert between quoted and unquoted forms.

SCSS
@use "sass:string";
@use "sass:meta";

.demo {
  content: string.quote(bold);
  --unquoted: #{meta.inspect(string.unquote(".widget:hover"))};
}

How It Works

  1. string.quote(bold) adds quotes.
  2. string.unquote removes them.
  3. meta.inspect shows the unquoted form clearly.
  4. Matches the official conversion sample idea.

Example 2 — Official Quoted Strings

Quoted strings keep their text; interpolation works inside them.

SCSS
$roboto-variant: "Mono";

.demo {
  font-family: "Helvetica Neue";
  --path: #{"C:\\Program Files"};
  --interp: #{"Roboto #{$roboto-variant}"};
}

How It Works

  1. font-family keeps CSS quotes.
  2. \\ escapes a backslash in the source.
  3. #{$roboto-variant} builds Roboto Mono.
  4. Interpolating into a custom property drops outer quotes.

Example 3 — Official Unquoted Identifiers

CSS identifiers stay unquoted; interpolation can build prefixes.

SCSS
$prefix: ms;

.box {
  font-weight: bold;
  display: -#{$prefix}-flex;
}

How It Works

  1. bold is an unquoted identifier.
  2. -#{$prefix}-flex builds -ms-flex.
  3. No quotes in the CSS output.
  4. Matches the official unquoted sample idea.

Example 4 — Official String Indexes

Indexes start at 1; negative indexes count from the end.

SCSS
@use "sass:string";

.demo {
  --helvetica: #{string.index("Helvetica Neue", "Helvetica")};
  --neue: #{string.index("Helvetica Neue", "Neue")};
  --slice: #{string.slice("Roboto Mono", -4)};
  --missing: #{string.index("Helvetica Neue", "Roboto") == null};
}

How It Works

  1. index 1 is the first character.
  2. -4 starts near the end for slice.
  3. Missing substring → null.
  4. Matches the official indexes sample.

Example 5 — Quoted Selector via Interpolation

Store a selector as a quoted string; interpolate to drop the quotes.

SCSS
$sel: ".widget:hover";

#{$sel} {
  color: #036;
}

How It Works

  1. $sel is a quoted string.
  2. #{$sel} injects without quotes.
  3. Result is a real selector.
  4. Why quoted variables work well for selector parts.

Edge Cases & Pitfalls

Most string bugs are unquoted keywords that are not strings, or 0-based index habits.

red

Color names are colors, not strings

Bare red is a color. Quote it ("red") when you mean a string key or label. See colors.

1-based

First character is index 1

Same idea as lists. Use -1 for the last character.

#{}

Interpolation removes quotes

Useful for selectors; surprising if you wanted a CSS string. Keep quotes on the property when needed.

null

string.index miss → null

Falsey—works in @if. See null.

Sass Support

Strings and sass:string are core Sass on Dart Sass.

FeatureStatus
Quoted / unquoted stringsSupported
CSS escapesSupported
Escape normalization (unquoted)Dart Sass 1.11+
sass:string moduleSupported

Compile with the Dart Sass CLI.

Key Takeaways

  • Quoted vs unquoted—same type, different CSS.
  • Prefer quoted unless CSS needs an identifier.
  • #{ } strips quotes from quoted strings.
  • Indexes start at 1; misses return null.

One line: quote text by default, unquote when CSS needs an identifier, and remember interpolation drops quotes.

Compile Notes

Practical checklist:

checklist.txt
1. Prefer "quoted" strings for most text
2. Use unquoted only for CSS identifiers
3. Convert with string.quote / string.unquote
4. Remember #{} removes quotes
5. Use 1-based indexes with string.index / slice

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.

Next: Sass Colors

Write hex, names, and modern color spaces—and keep string keys quoted.

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.

8 people found this page helpful