Sass string.to-upper-case()

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

Definition and Usage

string.to-upper-case($string) returns a copy of $string with ASCII letters converted to upper case. Quote state is preserved. Load with @use "sass:string".

Official sample idea.

string.to-upper-case("Bold") is "BOLD"; string.to-upper-case(sans-serif) is SANS-SERIF.

Compile-time labels.

Useful for badges, constants, and forced-uppercase tokens when source casing varies.

Not CSS text-transform.

Sass changes the string in the stylesheet. text-transform: uppercase only changes how the browser paints text.

Syntax

SCSS
@use "sass:string";

string.to-upper-case($string) //=> string

string.to-upper-case("Bold"); // "BOLD"
string.to-upper-case(sans-serif); // SANS-SERIF

// Global alias (legacy): to-upper-case($string)
// Prefer string.to-upper-case after @use "sass:string"

Pattern: pass mixed-case text → get ASCII-uppercased copy → keep the same quote state.

Upper vs Lower

Same characters, opposite case helpers:

HelperTypical resultUse when
string.to-upper-case"BOLD" / SANS-SERIFForce uppercase labels or constants
string.to-lower-case"bold" / sans-serifNormalize tokens and class names

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

Quoted and unquoted inputs both uppercase ASCII letters.

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

.probe {
  --a: #{meta.inspect(string.to-upper-case("Bold"))};
  --b: #{meta.inspect(string.to-upper-case(sans-serif))};
}

How It Works

  1. Quoted "Bold" becomes "BOLD".
  2. Unquoted sans-serif stays unquoted.
  3. Hyphen is unchanged.
  4. Matches the official Sass docs samples.

Example 2 — Force an Uppercase Label

Uppercase a badge string for CSS content.

SCSS
@use "sass:string";

.badge {
  text-transform: none;
  content: string.to-upper-case("new");
}

How It Works

  1. Input is lowercase.
  2. to-upper-case rewrites at compile time.
  3. Quoted result is safe for content.
  4. text-transform: none avoids double-casing in the browser.

Example 3 — Upper vs Lower

Same mixed-case source, both directions.

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

$raw: "MiXeD Case";
$lower: string.to-lower-case($raw);
$upper: string.to-upper-case($raw);

.compare {
  --lower: #{meta.inspect($lower)};
  --upper: #{meta.inspect($upper)};
}

How It Works

  1. Space is kept in both results.
  2. to-upper-case raises every ASCII letter.
  3. to-lower-case does the opposite.
  4. Pair them when normalizing maps or labels.

Example 4 — Quote State Is Preserved

Quoted stays quoted; unquoted stays unquoted.

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

.class-name {
  --from-quoted: #{meta.inspect(string.to-upper-case("bold"))};
  --from-unquoted: #{meta.inspect(string.to-upper-case(bold))};
}

How It Works

  1. Letters change; quote flags do not.
  2. inspect makes the difference obvious.
  3. content usually needs a quoted value.
  4. Use quote() if you must force quotes afterward.

Example 5 — Uppercase Labels in a Loop

Keep lowercase class slugs while emitting uppercase content.

SCSS
@use "sass:string";

$names: "primary", "Accent", "MUTED";

@each $name in $names {
  .chip-#{string.to-lower-case($name)} {
    content: string.to-upper-case($name);
  }
}

How It Works

  1. to-lower-case stabilizes the selector slug.
  2. to-upper-case forces the visible label.
  3. Quoted tokens keep quoted content.
  4. @each scales mixed-case source lists.

Edge Cases & Pitfalls

Most uppercase bugs are ASCII-only expectations or quote-state mix-ups.

ASCII

Only ASCII letters change

Digits, hyphens, spaces, and most non-ASCII letters stay as written.

quotes

Quote state is preserved

Unquoted input stays unquoted—pair with string.quote when CSS needs quotes.

runtime

Not a substitute for text-transform

Use CSS text-transform when the visible text must change without rewriting the stylesheet string.

inspect

Debug with meta.inspect

meta.inspect shows whether the result is quoted.

Sass Support

Prefer the module form with current Dart Sass.

APIStatus
string.to-upper-case()Dart Sass 1.23+ via @use "sass:string"
Return typeString (same quote state as input)
ScopeASCII letters only
Legacy globalto-upper-case($string)

Compile with the Dart Sass CLI.

Key Takeaways

  • ASCII letters → uppercase at compile time.
  • Quote state preserved for quoted and unquoted input.
  • vs to-lower-case — opposite casing helper.
  • Prefer @use "sass:string" (Dart Sass 1.23+).

One line: to uppercase ASCII letters in a Sass string, use string.to-upper-case($string).

Compile Notes

Practical checklist:

checklist.txt
1. @use "sass:string"
2. Pass quoted or unquoted input
3. Expect ASCII letters uppercased
4. Remember quote state is unchanged
5. Use quote() when CSS content needs quotes

Frequently Asked Questions

string.to-upper-case($string) returns a copy of $string with ASCII letters converted to upper case. Example: string.to-upper-case("Bold") is "BOLD".
Yes. Official sample: string.to-upper-case(sans-serif) becomes SANS-SERIF (still unquoted).
Yes. Official docs say ASCII letters are converted. Digits, hyphens, spaces, and most non-ASCII characters stay as they are.
Same idea, different stage. Sass changes the string at compile time. CSS text-transform changes how the browser displays text at runtime.
Yes. to-upper-case($string) is the legacy global name. Prefer string.to-upper-case 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.unique-id()

Generate a unique unquoted CSS identifier per compilation.

string.unique-id() →

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