Sass string.to-lower-case()

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

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

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

Lower vs Upper

Same characters, opposite case helpers:

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

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

Quoted and unquoted inputs both lowercase ASCII letters.

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

.probe {
  --a: #{meta.inspect(string.to-lower-case("Bold"))};
  --b: #{meta.inspect(string.to-lower-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 — Normalize a Token

Lowercase a design-token string for CSS content.

SCSS
@use "sass:string";

.btn {
  text-transform: none;
  content: string.to-lower-case("PRIMARY");
}

How It Works

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

Example 3 — Lower vs Upper

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-lower-case lowers every ASCII letter.
  3. to-upper-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-lower-case("BOLD"))};
  --from-unquoted: #{meta.inspect(string.to-lower-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 — Lowercase Class Names in a Loop

Normalize mixed-case tokens into CSS class selectors.

SCSS
@use "sass:string";

$names: "PRIMARY", "Accent", "muted";

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

How It Works

  1. Quoted tokens keep quoted content.
  2. Selector gets a lowercase slug via interpolation.
  3. @each scales a token list.
  4. 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.

Sass Support

Prefer the module form with current Dart Sass.

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

Compile with the Dart Sass CLI.

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

Compile Notes

Practical checklist:

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

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".
Yes. Official sample: string.to-lower-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-lower-case($string) is the legacy global name. Prefer string.to-lower-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.to-upper-case()

Convert ASCII letters in a string to upper case.

string.to-upper-case() →

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