Sass string.quote()

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

Definition and Usage

string.quote($string) returns $string as a quoted Sass string. Already-quoted input stays quoted. Load with @use "sass:string".

Official sample idea.

string.quote(Helvetica) and string.quote("Helvetica") both become "Helvetica".

Why quote?

Useful for font-family names, content strings, and normalizing mixed token inputs.

Opposite helper.

string.unquote() removes quotes and can produce strings that are not valid CSS—use carefully.

Syntax

SCSS
@use "sass:string";

string.quote($string) //=> quoted string

string.quote(Helvetica); // "Helvetica"
string.quote("Helvetica"); // "Helvetica"

// Common CSS uses:
font-family: string.quote(Roboto), sans-serif;
content: string.quote(New);

// Global alias (legacy): quote($string)
// Prefer string.quote after @use "sass:string"

Pattern: pass any string → get a quoted string → emit safe CSS for fonts and content.

Quote vs Unquote

Same characters, different quote state:

HelperTypical resultUse when
string.quote"Helvetica"You need quotes in the CSS output
string.unquoteHelveticaYou need an unquoted identifier (use carefully)

SCSS Examples

Examples use @use "sass:string". Open View Compiled CSS for verified Dart Sass output (matches official Sass docs samples where shown).

Example 1 — Official Quote Samples

Unquoted and already-quoted inputs both become quoted strings.

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

.probe {
  --from-unquoted: #{meta.inspect(string.quote(Helvetica))};
  --from-quoted: #{meta.inspect(string.quote("Helvetica"))};
  --type: #{meta.type-of(string.quote(Helvetica))};
}

How It Works

  1. Unquoted Helvetica becomes quoted.
  2. Already quoted stays quoted.
  3. type-of reports string.
  4. Matches the official Sass docs samples.

Example 2 — Quote a Font Family

Emit a quoted family name in font-family.

SCSS
@use "sass:string";

.heading {
  font-family: string.quote(Helvetica), sans-serif;
}

How It Works

  1. Unquoted identifier enters the call.
  2. quote wraps it for CSS.
  3. sans-serif stays as the fallback.
  4. Common pattern for design tokens.

Example 3 — Quote vs Unquote

Same characters, different quote state.

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

$raw: Helvetica;
$q: string.quote($raw);
$u: string.unquote($q);

.compare {
  --quoted: #{meta.inspect($q)};
  --unquoted: #{meta.inspect($u)};
}

How It Works

  1. quote wraps the value.
  2. unquote removes the wrapping.
  3. inspect shows the difference clearly.
  4. Round-trip is useful for debugging.

Example 4 — Quoted content

Pass an unquoted label into a mixin that quotes it for CSS.

SCSS
@use "sass:string";

@mixin label($name) {
  .badge {
    content: string.quote($name);
  }
}

@include label(New);

How It Works

  1. CSS content needs a string.
  2. Mixin accepts an unquoted label.
  3. quote guarantees quoted output.
  4. Safe API for generated badges.

Example 5 — Quote Fonts in a Loop

Build several rules from a list of family names.

SCSS
@use "sass:string";

$names: Helvetica, Roboto, Georgia;

@each $name in $names {
  .font-#{$name} {
    font-family: string.quote($name), sans-serif;
  }
}

How It Works

  1. List items start unquoted.
  2. quote wraps each font-family value.
  3. Class names stay unquoted via interpolation.
  4. Scales design-token font stacks.

Edge Cases & Pitfalls

Most quote bugs are confusing quote state with string content.

idempotent

Already quoted stays quoted

Calling quote twice does not double-wrap characters.

inspect

Use meta.inspect to see quotes

meta.inspect makes quote state obvious in custom properties.

unquote

Unquote carefully

Removing quotes can produce CSS that is not valid.

length

Quotes are not characters

string.length is the same for quoted and unquoted forms of the same text.

Sass Support

Prefer the module form with current Dart Sass.

APIStatus
string.quote()Dart Sass 1.23+ via @use "sass:string"
Return typeQuoted string
Already quotedStays quoted
Legacy globalquote($string)

Compile with the Dart Sass CLI.

Key Takeaways

  • Returns a quoted string for CSS-friendly output.
  • Already quoted stays quoted — safe to normalize.
  • vs unquote — unquote removes quotes carefully.
  • Prefer @use "sass:string" (Dart Sass 1.23+).

One line: to force a quoted Sass string, use string.quote($string).

Compile Notes

Practical checklist:

checklist.txt
1. @use "sass:string"
2. Pass quoted or unquoted input
3. Expect a quoted string result
4. Use for font-family and content
5. Use unquote only when you truly need no quotes

Frequently Asked Questions

string.quote($string) returns $string as a quoted Sass string. Example: string.quote(Helvetica) becomes "Helvetica".
Quoting an already-quoted string still returns a quoted string. string.quote("Helvetica") is "Helvetica".
Common cases include font-family names (especially with spaces), content strings, and some identifiers that must appear with quotes in the output CSS.
quote adds/keeps CSS quotes around the value. unquote removes them and can produce strings that are not valid CSS—use unquote with caution.
Yes. quote($string) is the legacy global name. Prefer string.quote after @use "sass:string".
Dart Sass 1.23+. LibSass and Ruby Sass do not load sass:string with @use; they may still offer the legacy global name.

Next: Sass string.slice()

Extract a portion of a string with 1-based indexes.

string.slice() →

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