converttolowercase

Home › Guides › How to convert a string to lowercase in code

How to convert a string to lowercase in code

Every language has a lowercase function, but they differ in how they treat Unicode and locales. Here is a quick reference and the pitfalls worth knowing.

Updated November 25, 2026

Quick reference

LanguageLowercaseUppercase
Pythons.lower()s.upper()
JavaScript / TypeScripts.toLowerCase()s.toUpperCase()
Javas.toLowerCase(Locale.ROOT)s.toUpperCase(Locale.ROOT)
C#s.ToLowerInvariant()s.ToUpperInvariant()
PHPmb_strtolower($s)mb_strtoupper($s)
SQLLOWER(col)UPPER(col)
Bash 4+${s,,}${s^^}
Gostrings.ToLower(s)strings.ToUpper(s)
Rubys.downcases.upcase
Rusts.to_lowercase()s.to_uppercase()
Kotlins.lowercase()s.uppercase()
Excel VBALCase(s)UCase(s)

Strings are immutable in most of these languages, so the function returns a new string — assign it: name = name.lower().

How to convert a string to lowercase in code: illustrated example
How to convert a string to lowercase in code at a glance.

Convert your text here

Prefer to skip the menus? Paste the text below — it converts live.

0 characters · 0 words · 0 lines · 0 letters changed

Options
Separate words with commas or new lines. Saved in this browser only.

Python: lower() vs casefold()

"Straße".lower()     # 'straße'
"Straße".casefold()  # 'strasse'

lower() is right for displaying text. casefold() is designed for comparing strings regardless of case, so use it when checking whether two words match: a.casefold() == b.casefold().

JavaScript and locales

"TITLE".toLowerCase()              // "title"
"TITLE".toLocaleLowerCase("tr-TR") // "tıtle"  (dotless ı)

toLowerCase() uses language-neutral Unicode rules. toLocaleLowerCase() applies language-specific rules — needed for Turkish and Azerbaijani text, harmful for identifiers such as HTML tags or JSON keys.

The Turkish I problem

Turkish has four forms of the letter: I ı (dotless) and İ i (dotted). On a machine whose default locale is Turkish, a locale-sensitive lowercase turns “TITLE” into “tıtle”, so a comparison such as "TITLE".toLowerCase() == "title" can unexpectedly fail. That is why the Java and C# examples above use Locale.ROOT and ToLowerInvariant(): they behave the same on every computer.

PHP: strtolower vs mb_strtolower

strtolower() works byte by byte and only converts the ASCII letters A–Z, so accented letters such as “É” are left as they are. Use mb_strtolower($s, 'UTF-8') for text that may contain non-English characters.

SQL: lowercasing vs case-insensitive matching

UPDATE users SET email = LOWER(email);
SELECT * FROM users WHERE LOWER(email) = LOWER('Anna@Example.com');

Wrapping a column in LOWER() inside a WHERE clause usually prevents the database from using a normal index on that column. For large tables, store values already lowercased, add an index on the expression where your database supports it, or use a case-insensitive collation.

Shell one-liners

echo "HELLO" | tr '[:upper:]' '[:lower:]'   # hello
name="HELLO"; echo "${name,,}"              # hello (Bash 4+)

macOS ships with Bash 3.2, which does not support ${name,,}; use tr there, or zsh’s ${name:l}.

Frequently asked questions

How do I convert a string to lowercase in Python?

Call the lower() method: new = text.lower(). For case-insensitive comparisons use casefold() instead, which also handles letters like German ß.

What is the difference between toLowerCase and toLocaleLowerCase in JavaScript?

toLowerCase uses language-neutral Unicode rules. toLocaleLowerCase applies the rules of a given language, which matters mainly for Turkish and Azerbaijani, where uppercase I becomes a dotless ı.

Why does strtolower not change accented letters in PHP?

strtolower only converts the ASCII letters A–Z. Use mb_strtolower with UTF-8 for full Unicode support.