JavaScript toUpperCase() and toLowerCase(): Convert String Case

Call toUpperCase() on a JavaScript string to get an uppercase string or toLowerCase() to get a lowercase string. The original stays the same, so store or display the returned value.

Convert a string to upper or lower case

Neither method needs an argument. They convert characters with case mappings and preserve spaces, digits, and characters without case. The first two lines of output show the converted values, and the last line shows the original. Check values that might be null or undefined before calling a method on them. ECMAScript · toUpperCase() ECMAScript · toLowerCase()

const original = 'Aaa Bbb 123';
const upper = original.toUpperCase();
const lower = original.toLowerCase();

console.log(upper);    // AAA BBB 123
console.log(lower);    // aaa bbb 123
console.log(original); // Aaa Bbb 123

Display results without editing the input

Typing or pasting into the field fires an input event. Read the value in the handler and write the results to separate output elements. That leaves the text and cursor in place while the user edits. textContent displays angle brackets and tag-like input as literal text. HTML Standard · input events

Try the complete example

Save the following code as case-conversion.html and open it in a browser. The input Aaa Bbb 123 produces AAA BBB 123 and aaa bbb 123. The page calls update() once to fill the initial outputs. Paste some text or clear the field to see both outputs change. If your JavaScript assigns input.value directly, also call update().

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>String case conversion</title>
</head>
<body>
<h1>String case conversion</h1>
<label for="source">Original string</label>
<input id="source" type="text" value="Aaa Bbb 123">
<dl>
  <dt>Uppercase</dt>
  <dd><output id="upper" for="source"></output></dd>
  <dt>Lowercase</dt>
  <dd><output id="lower" for="source"></output></dd>
</dl>
<script>
const input = document.querySelector('#source');
const upper = document.querySelector('#upper');
const lower = document.querySelector('#lower');

function update() {
  const value = input.value;
  upper.textContent = value.toUpperCase();
  lower.textContent = value.toLowerCase();
}

input.addEventListener('input', update);
update();
</script>
</body>
</html>

Apply language-specific case rules

The default methods use Unicode’s default case mappings. To apply the rules of a specific language, pass its language tag to toLocaleUpperCase() or toLocaleLowerCase(). Here, tr selects Turkish. In Turkish, lowercase i maps to dotted uppercase İ, and uppercase I maps to dotless lowercase ı. ECMAScript Internationalization API · toLocaleLowerCase()

console.log('i'.toUpperCase());               // I
console.log('i'.toLocaleUpperCase('tr'));     // İ
console.log('I'.toLowerCase());               // i
console.log('I'.toLocaleLowerCase('tr'));     // ı

console.log('ß'.toUpperCase());               // SS
console.log('ß'.toUpperCase().length);        // 2

Case conversion can change a string’s length. In the example, the default uppercase mapping turns the single German letter ß into SS. If your goal is to compare text for searching or sorting, consider the language’s comparison rules separately.