Home Sass String string.unquote() Sass string.unquote() Definition
Definition and Usage string.unquote($string) returns $string as an unquoted Sass string. Already-unquoted input stays unquoted. Load with @use "sass:string".
Official sample idea. string.unquote("Helvetica") becomes Helvetica; string.unquote(".widget:hover") becomes .widget:hover.
When it helps. Inject stored CSS values (filter, complex functions) or interpolate a selector string into a rule.
Use with caution. Official docs: unquote can produce strings that are not valid CSS . Prefer string.quote() when the output must stay quoted.
Syntax
Syntax @use "sass:string";
string.unquote($string) //=> unquoted string
string.unquote("Helvetica"); // Helvetica
string.unquote(".widget:hover"); // .widget:hover
// Inject a stored CSS value:
filter: string.unquote("blur(4px)");
// Global alias (legacy): unquote($string)
// Prefer string.unquote after @use "sass:string" Pattern: start with a quoted string → unquote → emit bare CSS text (identifiers, selectors, function values).
Code
SCSS Examples Examples use @use "sass:string". Open View Compiled CSS for verified Dart Sass output (matches official Sass docs samples where shown).
1. Official 2. vs quote 3. Font 4. Selector 5. Filter Example 1 — Official Unquote Samples Quoted identifiers and selector-like text become unquoted.
@use "sass:meta";
@use "sass:string";
.probe {
--a: #{meta.inspect(string.unquote("Helvetica"))};
--b: #{meta.inspect(string.unquote(".widget:hover"))};
} .probe {
--a: Helvetica;
--b: .widget:hover;
} How It Works Quotes removed from Helvetica.Selector text stays as characters, now unquoted.inspect shows the unquoted form.Matches the official Sass docs samples.Example 2 — Unquote vs Quote Round-trip the same characters with both helpers.
@use "sass:meta";
@use "sass:string";
$q: string.quote(Helvetica);
$u: string.unquote($q);
.compare {
--quoted: #{meta.inspect($q)};
--unquoted: #{meta.inspect($u)};
} .compare {
--quoted: "Helvetica";
--unquoted: Helvetica;
} How It Works quote wraps the value.unquote removes the wrapping.Characters stay the same.Opposite helpers for quote-state control.Example 3 — Unquoted Font Family Emit an unquoted family name in font-family.
@use "sass:string";
$family: string.unquote("Roboto");
.heading {
font-family: $family, sans-serif;
} .heading {
font-family: Roboto, sans-serif;
} How It Works Quoted token enters the call.unquote drops CSS quotes.Output is a bare identifier.Prefer quote when the family name has spaces.Example 4 — Inject a Selector String Turn a quoted selector string into a real rule selector.
@use "sass:string";
#{string.unquote(".widget:hover")} {
color: blue;
} .widget:hover {
color: blue;
} How It Works Quoted ".widget:hover" is data.unquote makes it interpolatable as a selector.#{} places it in the stylesheet.Matches the official selector-like sample idea.Example 5 — Inject a CSS Function Value Store a full filter value as a string, then unquote it into CSS.
@use "sass:string";
$blur: string.unquote("blur(4px)");
.card {
filter: $blur;
} .card {
filter: blur(4px);
} How It Works Quoted value would emit as a CSS string.unquote emits bare function syntax.filter receives valid CSS.Common pattern for stored complex values. Edge Cases & Pitfalls Most unquote bugs are emitting CSS that browsers cannot parse.
caution Can produce invalid CSS Spaces, punctuation, or odd tokens may be legal Sass strings but illegal CSS values.
idempotent Already unquoted stays unquoted Calling unquote twice does not change characters further.
content content usually needs quotes Prefer string.quote for content and spaced font names.
inspect Use meta.inspect to see quote state meta.inspect makes quoted vs unquoted obvious in custom properties.
Toolchain
Sass Support Prefer the module form with current Dart Sass.
API Status string.unquote()Dart Sass 1.23+ via @use "sass:string" Return type Unquoted string Already unquoted Stays unquoted Legacy global unquote($string)
Compile with the Dart Sass CLI .
Remember
Key Takeaways Returns an unquoted string for bare CSS text.
Use carefully — can emit invalid CSS.
vs quote — quote keeps/adds quotes safely.
Prefer @use "sass:string" (Dart Sass 1.23+).
One line: to force an unquoted Sass string, use string.unquote($string).
Practice
Compile Notes Practical checklist:
1. @use "sass:string"
2. Pass a quoted (or already unquoted) string
3. Expect an unquoted result
4. Use for selectors / raw CSS function values
5. Prefer quote() whenever the CSS must stay quoted Frequently Asked Questions What does Sass string.unquote() do? string.unquote($string) returns $string as an unquoted Sass string. Example: string.unquote("Helvetica") becomes Helvetica.
Can unquote create invalid CSS? Yes. Official docs warn that unquote can produce strings that are not valid CSS. Use it carefully, especially with spaces or selector-like text.
How is it different from string.quote()? quote adds or keeps CSS quotes around a value. unquote removes them so the value is emitted without surrounding quotes.
When do I need unquote? Common cases include injecting a full CSS value string (like filter: blur(4px)), interpolating a selector string into a rule, or normalizing a value that must appear unquoted in the output.
Is there a global unquote()? Yes. unquote($string) is the legacy global name. Prefer string.unquote after @use "sass:string".
Which compilers support the module API? 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 Equality Operators Compare Sass values with == and !=.
Equality → About the author Developer, cloud engineer, and technical writer
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
Helpful Share Copy link Suggestion