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
Concept
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.
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.
Foundation
📝 Syntax
styles.scss
@use "sass:string";
// Recommended
string.quote($string)
// Legacy global name
quote($string)
Parameters
Parameter
Type
Required
Description
$string
String
Yes
Quoted or unquoted Sass string to return as quoted.
Return value
Type
Result
String (quoted)
The same characters, marked as a quoted Sass string
Modules
📦 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);
Details
🎨 Official Patterns
Call
Result
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.
Compare
⚖️ quote vs unquote
Helper
Typical result
Use when
string.quote
"Helvetica"
You need quotes in the compiled CSS
string.unquote
Helvetica
You need an unquoted value (use carefully)
Support
🛠 Compatibility
This is about Sass compilers, not browsers. Quoting happens at compile time.
Implementation
quote
Dart Sass
Yes — prefer string.quote (module since 1.23.0)
LibSass
Legacy quote may exist; no @use "sass:string"
Ruby Sass
Legacy quote may exist; no @use "sass:string"
Prefer current Dart Sass so the module API matches the official docs.
Cheat Sheet
⚡ Quick Reference
Goal
Code
Import string
@use "sass:string";
Quote an identifier
string.quote(Helvetica)
font-family
font-family: string.quote(Roboto), sans-serif;
content text
content: string.quote(New);
Inspect quotes
meta.inspect(string.quote($s))
Remove quotes
string.unquote(…)
Hands-On
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.
Each unquoted list item becomes a quoted font-family value, while the interpolated class name stays unquoted.
Applications
🚀 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".
Watch Out
⚠️ Common Pitfalls
Passing non-strings — quote 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".
Pro Tips
💡 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
Summary
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
📝01
API
quote($string)
Call
📦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.
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.