Home Sass String string.to-lower-case() Sass string.to-lower-case() Definition
Definition and Usage string.to-lower-case($string) returns a copy of $string with ASCII letters converted to lower case. Quote state is preserved. Load with @use "sass:string".
Official sample idea. string.to-lower-case("Bold") is "bold"; string.to-lower-case(SANS-SERIF) is sans-serif.
Compile-time normalize. Useful for class names, design tokens, and map keys when input casing is mixed.
Not CSS text-transform. Sass changes the string in the stylesheet. text-transform: lowercase only changes how the browser paints text.
Syntax
Syntax @use "sass:string";
string.to-lower-case($string) //=> string
string.to-lower-case("Bold"); // "bold"
string.to-lower-case(SANS-SERIF); // sans-serif
// Global alias (legacy): to-lower-case($string)
// Prefer string.to-lower-case after @use "sass:string" Pattern: pass mixed-case text → get ASCII-lowercased copy → keep the same quote state.
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. Token 3. vs upper 4. Quotes 5. Loop Example 1 — Official Lowercase Samples Quoted and unquoted inputs both lowercase ASCII letters.
@use "sass:meta";
@use "sass:string";
.probe {
--a: #{meta.inspect(string.to-lower-case("Bold"))};
--b: #{meta.inspect(string.to-lower-case(SANS-SERIF))};
} .probe {
--a: "bold";
--b: sans-serif;
} How It Works Quoted "Bold" becomes "bold".Unquoted SANS-SERIF stays unquoted.Hyphen is unchanged.Matches the official Sass docs samples.Example 2 — Normalize a Token Lowercase a design-token string for CSS content.
@use "sass:string";
.btn {
text-transform: none;
content: string.to-lower-case("PRIMARY");
} .btn {
text-transform: none;
content: "primary";
} How It Works Input is uppercase.to-lower-case rewrites at compile time.Quoted result is safe for content.text-transform: none avoids double-casing in the browser.Example 3 — Lower vs Upper Same mixed-case source, both directions.
@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)};
} .compare {
--lower: "mixed case";
--upper: "MIXED CASE";
} How It Works Space is kept in both results.to-lower-case lowers every ASCII letter.to-upper-case does the opposite.Pair them when normalizing maps or labels.Example 4 — Quote State Is Preserved Quoted stays quoted; unquoted stays unquoted.
@use "sass:meta";
@use "sass:string";
.class-name {
--from-quoted: #{meta.inspect(string.to-lower-case("BOLD"))};
--from-unquoted: #{meta.inspect(string.to-lower-case(BOLD))};
} .class-name {
--from-quoted: "bold";
--from-unquoted: bold;
} How It Works Letters change; quote flags do not.inspect makes the difference obvious.content usually needs a quoted value.Use quote() if you must force quotes afterward.Example 5 — Lowercase Class Names in a Loop Normalize mixed-case tokens into CSS class selectors.
@use "sass:string";
$names: "PRIMARY", "Accent", "muted";
@each $name in $names {
.chip-#{string.to-lower-case($name)} {
content: string.to-lower-case($name);
}
} .chip-primary {
content: "primary";
}
.chip-accent {
content: "accent";
}
.chip-muted {
content: "muted";
} How It Works Quoted tokens keep quoted content.Selector gets a lowercase slug via interpolation.@each scales a token list.Stable output even when source casing varies. Edge Cases & Pitfalls Most lowercase 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.
Toolchain
Sass Support Prefer the module form with current Dart Sass.
API Status string.to-lower-case()Dart Sass 1.23+ via @use "sass:string" Return type String (same quote state as input) Scope ASCII letters only Legacy global to-lower-case($string)
Compile with the Dart Sass CLI .
Remember
Key Takeaways ASCII letters → lowercase at compile time.
Quote state preserved for quoted and unquoted input.
vs to-upper-case — opposite casing helper.
Prefer @use "sass:string" (Dart Sass 1.23+).
One line: to lowercase ASCII letters in a Sass string, use string.to-lower-case($string).
Practice
Compile Notes Practical checklist:
1. @use "sass:string"
2. Pass quoted or unquoted input
3. Expect ASCII letters lowercased
4. Remember quote state is unchanged
5. Use quote() when CSS content needs quotes Frequently Asked Questions What does Sass string.to-lower-case() do? string.to-lower-case($string) returns a copy of $string with ASCII letters converted to lower case. Example: string.to-lower-case("Bold") is "bold".
Does it work on unquoted strings? Yes. Official sample: string.to-lower-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: lowercase? 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-lower-case()? Yes. to-lower-case($string) is the legacy global name. Prefer string.to-lower-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.
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