Sass string.unquote()

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

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

SCSS
@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).

Unquote vs Quote

Same characters, different quote state:

HelperTypical resultUse when
string.unquoteHelveticaYou need an unquoted identifier or raw CSS text
string.quote"Helvetica"You need quotes in the CSS output

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 Unquote Samples

Quoted identifiers and selector-like text become unquoted.

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

.probe {
  --a: #{meta.inspect(string.unquote("Helvetica"))};
  --b: #{meta.inspect(string.unquote(".widget:hover"))};
}

How It Works

  1. Quotes removed from Helvetica.
  2. Selector text stays as characters, now unquoted.
  3. inspect shows the unquoted form.
  4. Matches the official Sass docs samples.

Example 2 — Unquote vs Quote

Round-trip the same characters with both helpers.

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

$q: string.quote(Helvetica);
$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. Characters stay the same.
  4. Opposite helpers for quote-state control.

Example 3 — Unquoted Font Family

Emit an unquoted family name in font-family.

SCSS
@use "sass:string";

$family: string.unquote("Roboto");

.heading {
  font-family: $family, sans-serif;
}

How It Works

  1. Quoted token enters the call.
  2. unquote drops CSS quotes.
  3. Output is a bare identifier.
  4. Prefer quote when the family name has spaces.

Example 4 — Inject a Selector String

Turn a quoted selector string into a real rule selector.

SCSS
@use "sass:string";

#{string.unquote(".widget:hover")} {
  color: blue;
}

How It Works

  1. Quoted ".widget:hover" is data.
  2. unquote makes it interpolatable as a selector.
  3. #{} places it in the stylesheet.
  4. 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.

SCSS
@use "sass:string";

$blur: string.unquote("blur(4px)");

.card {
  filter: $blur;
}

How It Works

  1. Quoted value would emit as a CSS string.
  2. unquote emits bare function syntax.
  3. filter receives valid CSS.
  4. 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.

Sass Support

Prefer the module form with current Dart Sass.

APIStatus
string.unquote()Dart Sass 1.23+ via @use "sass:string"
Return typeUnquoted string
Already unquotedStays unquoted
Legacy globalunquote($string)

Compile with the Dart Sass CLI.

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

Compile Notes

Practical checklist:

checklist.txt
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

string.unquote($string) returns $string as an unquoted Sass string. Example: string.unquote("Helvetica") becomes Helvetica.
Yes. Official docs warn that unquote can produce strings that are not valid CSS. Use it carefully, especially with spaces or selector-like text.
quote adds or keeps CSS quotes around a value. unquote removes them so the value is emitted without surrounding quotes.
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.
Yes. unquote($string) is the legacy global name. Prefer string.unquote 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 Equality Operators

Compare Sass values with == and !=.

Equality →

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