Home Sass Functions string string.to-upper-case() Sass string.to-upper-case() Function Overview
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.
02
Module @use "sass:string"
Concept
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.
Foundation
📝 Syntax @use "sass:string";
// Recommended
string.to-upper-case($string)
// Legacy global name
to-upper-case($string) Parameters Parameter Type Required Description $stringString Yes The string to copy and uppercase.
Return value Type Result String A new string with ASCII letters in upper case (quote state preserved)
Modules
📦 Loading sass:string // 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"); Details
🎨 Official Patterns Call Result 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.
Compare
⚖️ Sass vs CSS text-transform Topic Sass string.to-upper-case CSS text-transform: uppercase When it runs Compile time In the browser What changes The string value itself How text is displayed Best for Class names, tokens, fixed CSS values Visible 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.
Support
🛠 Compatibility This is about Sass compilers , not browsers. Uppercasing happens at compile time.
Implementation to-upper-caseDart Sass Yes — prefer string.to-upper-case (module since 1.23.0 ) LibSass Legacy to-upper-case may exist; no @use "sass:string" Ruby Sass Legacy to-upper-case 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";Uppercase a label string.to-upper-case("Bold")Uppercase unquoted string.to-upper-case(sans-serif)Build a class token .action-#{string.to-upper-case($name)}Opposite helper string.to-lower-case($string)Display-only upper Use CSS text-transform: uppercase
Hands-On
Examples Gallery Each example uses string.to-upper-case at compile time (Dart Sass 1.23+). Open View Compiled CSS for verified output.
official font modifier content @each 📚 Getting Started Official docs samples, then a font-family token.
Example 1 — Official Uppercase Samples Quoted and unquoted inputs keep their quote state.
@use "sass:meta";
@use "sass:string";
.probe {
--quoted: #{meta.inspect(string.to-upper-case("Bold"))};
--unquoted: #{meta.inspect(string.to-upper-case(sans-serif))};
} .probe {
--quoted: "BOLD";
--unquoted: 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).
@use "sass:string";
.heading {
font-family: string.to-upper-case("roboto"), sans-serif;
text-transform: none;
} .heading {
font-family: "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.
@use "sass:meta";
@use "sass:string";
$mod: "primary";
.btn {
--mod: #{meta.inspect(string.to-upper-case($mod))};
} .btn {
--mod: "PRIMARY";
} 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.
@use "sass:string";
@function upper-id($name) {
@return string.to-upper-case($name);
}
.badge::before {
content: upper-id("new");
} .badge::before {
content: "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.
@use "sass:string";
$parts: ("save", "edit", "delete");
@each $part in $parts {
.action-#{string.to-upper-case($part)} {
content: string.to-upper-case($part);
}
} .action-SAVE {
content: "SAVE";
}
.action-EDIT {
content: "EDIT";
}
.action-DELETE {
content: "DELETE";
} How It Works Interpolation drops Sass quotes in the selector, so you get classes like .action-SAVE, while content keeps the quoted string.
Applications
🚀 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.
Watch Out
⚠️ 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.Pro Tips
💡 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 Summary
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.
📝 01
API to-upper-case($s)
Call 📦 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 What does Sass string.to-upper-case() do? 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".
Does it work on unquoted strings? Yes. Official sample: string.to-upper-case(sans-serif) becomes SANS-SERIF (still unquoted).
Are only ASCII letters changed? Yes. Official docs say ASCII letters are converted. Digits, hyphens, spaces, and most non-ASCII characters stay as they are.
Is this the same as CSS text-transform: uppercase? Same idea, different stage. Sass changes the string at compile time. CSS text-transform changes how the browser displays text at runtime.
Is there a global to-upper-case()? Yes. to-upper-case($string) is the legacy global name. Prefer string.to-upper-case 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.
Did you know?
Official Sass docs uppercase both "Bold" and unquoted sans-serif—quote state is preserved while letters change case.
Wrap Up
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 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.
5 people found this page helpful
Helpful Share Copy link Suggestion