Sass string.to-upper-case() Function

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

What You’ll Learn

string.to-upper-case() belongs to the built-in sass:string module. It returns a copy of a string with ASCII letters converted to upper case. This page covers quote state, Sass vs CSS text-transform, and five compiled examples.

01

Concept

Uppercase ASCII

02

Module

@use "sass:string"

03

Returns

New string

04

Quotes

Preserved

05

Vs CSS

text-transform

06

Practice

5 examples

What Is string.to-upper-case()?

Official docs: returns a copy of $string with the ASCII letters converted to upper case.

  • The original string is not mutated—you always get a new value.
  • Quoted strings stay quoted; unquoted strings stay unquoted.
  • Hyphens, digits, and spaces are left alone.
  • Pair with string.to-lower-case when you need the opposite.
💡
Beginner tip

Think of a stamp that only capitalizes A–Z. "Bold" becomes "BOLD", and unquoted sans-serif becomes SANS-SERIF.

📝 Syntax

styles.scss
@use "sass:string";

// Recommended
string.to-upper-case($string)

// Legacy global name
to-upper-case($string)

Parameters

ParameterTypeRequiredDescription
$stringStringYesThe string to copy and uppercase.

Return value

TypeResult
StringA new string with ASCII letters in upper case (quote state preserved)

📦 Loading sass:string

styles.scss
// Recommended — namespaced (Dart Sass 1.23+)
@use "sass:string";
$label: string.to-upper-case("Bold"); // "BOLD"

// Optional — bring members into scope
@use "sass:string" as *;
$label: to-upper-case("Bold");

// Legacy global
$label: to-upper-case("Bold");

🎨 Official Patterns

CallResult
to-upper-case("Bold")"BOLD" (quoted)
to-upper-case(sans-serif)SANS-SERIF (unquoted)

These are the official Sass documentation samples. Notice the hyphen stays, and quote state matches the input.

⚖️ Sass vs CSS text-transform

TopicSass string.to-upper-caseCSS text-transform: uppercase
When it runsCompile timeIn the browser
What changesThe string value itselfHow text is displayed
Best forClass names, tokens, fixed CSS valuesVisible page text styling
⚠️
ASCII only in Sass

Official docs convert ASCII letters. For full Unicode casing of visible copy, CSS text-transform is often the better tool.

🛠 Compatibility

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

Implementationto-upper-case
Dart SassYes — prefer string.to-upper-case (module since 1.23.0)
LibSassLegacy to-upper-case may exist; no @use "sass:string"
Ruby SassLegacy to-upper-case 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";
Uppercase a labelstring.to-upper-case("Bold")
Uppercase unquotedstring.to-upper-case(sans-serif)
Build a class token.action-#{string.to-upper-case($name)}
Opposite helperstring.to-lower-case($string)
Display-only upperUse CSS text-transform: uppercase

Examples Gallery

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

📚 Getting Started

Official docs samples, then a font-family token.

Example 1 — Official Uppercase Samples

Quoted and unquoted inputs keep their quote state.

styles.scss
@use "sass:meta";
@use "sass:string";

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

How It Works

Matches the official docs. meta.inspect shows quotes clearly: "BOLD" vs bare SANS-SERIF.

Example 2 — Uppercase a Font Name

Compile-time uppercase for a family token (not browser display transform).

styles.scss
@use "sass:string";

.heading {
  font-family: string.to-upper-case("roboto"), sans-serif;
  text-transform: none;
}

How It Works

Sass writes "ROBOTO" into the CSS file. Setting text-transform: none shows this is not a browser visual transform.

📈 Practical Patterns

Modifiers, content labels, and looped class tokens.

Example 3 — Normalize a Modifier Token

Store an uppercase variant of a modifier name.

styles.scss
@use "sass:meta";
@use "sass:string";

$mod: "primary";

.btn {
  --mod: #{meta.inspect(string.to-upper-case($mod))};
}

How It Works

Useful when design tokens or debug props should always appear in a fixed case.

Example 4 — Uppercase content Labels

A tiny helper for badge text that must be uppercase in CSS.

styles.scss
@use "sass:string";

@function upper-id($name) {
  @return string.to-upper-case($name);
}

.badge::before {
  content: upper-id("new");
}

How It Works

The helper keeps call sites readable. The compiled CSS contains the finished "NEW" string.

Example 5 — Uppercase Class Tokens In A Loop

Build action classes and matching content values.

styles.scss
@use "sass:string";

$parts: ("save", "edit", "delete");

@each $part in $parts {
  .action-#{string.to-upper-case($part)} {
    content: string.to-upper-case($part);
  }
}

How It Works

Interpolation drops Sass quotes in the selector, so you get classes like .action-SAVE, while content keeps the quoted string.

🚀 Real-World Use Cases

  • Token normalization — force modifiers or flags into a fixed case.
  • Generated class names — uppercase segments in BEM-style or utility loops.
  • Pseudo-element labels — bake uppercase into content strings.
  • Debug props — print uppercase variants with meta.inspect.
  • Pair with lower-case — normalize both directions in shared helpers.

🧠 How Compilation Works

1

Pass a string

Call string.to-upper-case($string).

Source
2

Sass uppercases ASCII letters

Digits, hyphens, and quote state stay the same.

Compile
3

Use the new string

Assign to CSS properties or interpolate into selectors.

Emit
4

CSS ships

Browsers only see finished text like "BOLD" or SANS-SERIF.

⚠️ Common Pitfalls

  • Expecting Unicode casing — docs convert ASCII letters; use CSS for display casing of rich text.
  • Confusing with text-transform — Sass changes the value; CSS changes display.
  • Expecting mutation — the original variable stays unchanged.
  • Forgetting quote state — quoted inputs stay quoted in the result.
  • Uppercasing for looks only — prefer CSS when you only want visual uppercase.

💡 Best Practices

✅ Do

  • Use @use "sass:string" and string.to-upper-case()
  • Use it for tokens, class fragments, and fixed CSS strings
  • Pair with string.to-lower-case for normalization
  • Inspect quote state with meta.inspect while learning
  • Prefer Dart Sass 1.23+

❌ Don’t

  • Assume full Unicode case conversion
  • Replace CSS text-transform for visible page copy
  • Expect the original string variable to change
  • Expect browsers to evaluate the call
  • Rely on LibSass for the module API

Key Takeaways

Knowledge Unlocked

Five things to remember about string.to-upper-case()

Copy a string and convert ASCII letters to upper case at compile time.

5
Core concepts
📦 02

Module

sass:string

@use
🔗 03

Result

new uppercase string

Output
📚 04

Scope

ASCII letters

Rule
05

Pair

to-lower-case

Pattern

❓ 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.
Did you know?

Official Sass docs uppercase both "Bold" and unquoted sans-serif—quote state is preserved while letters change case.

Conclusion

string.to-upper-case() returns a copy of a string with ASCII letters in upper case. Quote state is preserved, and the work happens at compile time. Use CSS text-transform when you only need visual uppercase for page text.

Continue with string.unique-id() or the Sass introduction.

Next: unique identifiers

Learn string.unique-id() to generate unique CSS names at compile time.

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.

5 people found this page helpful