Sass string.quote() Function

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
sass:string · Dart Sass 1.23+

What You’ll Learn

string.quote() belongs to the built-in sass:string module. It returns a value as a quoted Sass string—handy for font-family, content, and other CSS that needs quotes in the output. This page covers quoted vs unquoted strings, vs string.unquote, and five compiled examples.

01

Concept

Add CSS quotes

02

Module

@use "sass:string"

03

Returns

Quoted string

04

Args

$string

05

vs unquote

Quotes on / off

06

Practice

5 examples

What Is string.quote()?

Official docs: returns $string as a quoted string. In Sass, strings come in two flavors—quoted ("Helvetica") and unquoted (Helvetica). Both can hold the same characters; quotes change how the value is written into CSS.

  • Unquoted input becomes quoted: string.quote(Helvetica)"Helvetica".
  • Already-quoted input stays quoted: string.quote("Helvetica")"Helvetica".
  • See also string.unquote() when you need the opposite.
💡
Beginner tip

Think of quote as wrapping gift paper around a name so CSS treats it as a string literal. Font names and content text often need that wrapping in the final CSS file.

📝 Syntax

styles.scss
@use "sass:string";

// Recommended
string.quote($string)

// Legacy global name
quote($string)

Parameters

ParameterTypeRequiredDescription
$stringStringYesQuoted or unquoted Sass string to return as quoted.

Return value

TypeResult
String (quoted)The same characters, marked as a quoted Sass string

📦 Loading sass:string

styles.scss
// Recommended — namespaced (Dart Sass 1.23+)
@use "sass:string";
$name: string.quote(Helvetica); // "Helvetica"

// Optional — bring members into scope
@use "sass:string" as *;
$name: quote(Helvetica);

// Legacy global
$name: quote(Helvetica);

🎨 Official Patterns

CallResult
quote(Helvetica)"Helvetica"
quote("Helvetica")"Helvetica"

Both calls end as quoted strings. The useful difference is the input: unquoted identifiers become safely quoted for CSS output.

⚖️ quote vs unquote

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

🛠 Compatibility

This is about Sass compilers, not browsers. Quoting happens at compile time.

Implementationquote
Dart SassYes — prefer string.quote (module since 1.23.0)
LibSassLegacy quote may exist; no @use "sass:string"
Ruby SassLegacy quote may exist; no @use "sass:string"

Prefer current Dart Sass so the module API matches the official docs.

⚡ Quick Reference

GoalCode
Import string@use "sass:string";
Quote an identifierstring.quote(Helvetica)
font-familyfont-family: string.quote(Roboto), sans-serif;
content textcontent: string.quote(New);
Inspect quotesmeta.inspect(string.quote($s))
Remove quotesstring.unquote(…)

Examples Gallery

Each example uses string.quote at compile time (Dart Sass 1.23+). Open View Compiled CSS for verified output.

📚 Getting Started

Official docs samples, then real CSS properties.

Example 1 — Official Quote Samples

Quote unquoted and already-quoted Helvetica values.

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

meta.inspect shows the quotes clearly. Both inputs compile to the same quoted string type.

Example 2 — Quote a Font Family

Emit a quoted family name in font-family.

styles.scss
@use "sass:string";

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

How It Works

The unquoted Sass identifier Helvetica becomes a quoted CSS font name in the output.

📈 Practical Patterns

Unquote contrast, content text, and font loops.

Example 3 — Quote vs Unquote

Same characters, different quote state.

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

Round-trip: quote wraps the value; unquote removes the wrapping. Inspect shows the difference.

Example 4 — Quoted content

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

styles.scss
@use "sass:string";

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

@include label(New);

How It Works

CSS content needs a string. Quoting the mixin argument guarantees valid quoted output.

Example 5 — Quote Fonts in a Loop

Build several rules from a list of family names.

styles.scss
@use "sass:string";

$names: Helvetica, Roboto, Georgia;

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

How It Works

Each unquoted list item becomes a quoted font-family value, while the interpolated class name stays unquoted.

🚀 Real-World Use Cases

  • Font stacks — quote family names from design tokens.
  • Generated content — build safe content strings in mixins.
  • Design-system APIs — accept unquoted identifiers and emit quoted CSS.
  • Debugging — pair with meta.inspect to see quote state.
  • Token pipelines — normalize mixed quoted/unquoted inputs before output.

🧠 How Compilation Works

1

Pass a string

Call string.quote(Helvetica) or string.quote("Helvetica").

Source
2

Sass marks it quoted

Characters stay the same; the value becomes a quoted string.

Compile
3

Use in CSS properties

Assign to font-family, content, or custom properties.

Emit
4

CSS ships

Browsers see quoted values like "Helvetica".

⚠️ Common Pitfalls

  • Passing non-stringsquote expects a string; interpolated multi-word unquoted values can fail.
  • Confusing with JS quotes — this is Sass string state for CSS output, not runtime JavaScript.
  • Unnecessary quoting — many CSS keywords stay unquoted; quote when the CSS needs a string.
  • Forgetting inspect — without meta.inspect, quote state can be hard to see in custom properties.
  • Old compilers without modules — use Dart Sass 1.23+ for @use "sass:string".

💡 Best Practices

✅ Do

  • Use @use "sass:string" and string.quote()
  • Quote font names and content text when needed
  • Pass a real string value (quoted or unquoted identifier)
  • Use meta.inspect while learning quote state
  • Prefer Dart Sass 1.23+

❌ Don’t

  • Pass numbers, colors, or lists to quote
  • Assume quote changes the characters—it mainly changes quote state
  • Unquote blindly; official docs warn it can produce invalid CSS
  • Expect browsers to evaluate the Sass call
  • Rely on LibSass for the module API

Key Takeaways

Knowledge Unlocked

Five things to remember about string.quote()

Turn a Sass string into a quoted value so CSS gets the quotes it needs.

5
Core concepts
📦 02

Module

sass:string

@use
🔗 03

Result

quoted string

Output
📚 04

Idempotent

already quoted OK

Detail
05

Alt

unquote to remove

Compare

❓ Frequently Asked Questions

string.quote($string) returns $string as a quoted Sass string. Example: string.quote(Helvetica) becomes "Helvetica".
Official docs: 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.
Did you know?

Official Sass docs use Helvetica for both quoted and unquoted inputs to show that string.quote normalizes either form into a quoted string for CSS-friendly output.

Conclusion

string.quote() returns a quoted Sass string so your compiled CSS gets the quotes it needs for fonts, content, and similar values. Quoting an already-quoted string is safe; reach for string.unquote only when you intentionally need the opposite.

Continue with string.slice() or the Sass introduction.

Next: slice strings

Learn string.slice() to extract inclusive substrings by index.

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.

5 people found this page helpful