Invert Case
Swap uppercase and lowercase: Hello World → hELLO wORLD.
Back to all tools on ToolForge
Input
Result
About Invert Case
The Invert Case tool swaps uppercase letters to lowercase and lowercase to uppercase, transforming "Hello World" into "hELLO wORLD". This case transformation is useful for fixing capitalization errors, creating stylistic text effects, normalizing inconsistent data, and debugging case-sensitive issues.
Also known as "toggle case" or "swap case", this transformation is distinct from uppercase (all caps) or lowercase (all small) conversions. It preserves the character positions while inverting their case state.
Case Transformation Types
| Type | Input | Output | Use Case |
|---|---|---|---|
| Invert/Toggle | Hello World | hELLO wORLD | Swap existing case |
| Uppercase | Hello World | HELLO WORLD | Emphasis, acronyms |
| Lowercase | Hello World | hello world | Normalization, emails |
| Title Case | hello world | Hello World | Headings, names |
| Sentence case | HELLO WORLD | Hello world | Regular prose |
Character Handling Rules
| Character Type | Examples | Invert Case Result |
|---|---|---|
| Uppercase letters | A-Z | Converted to lowercase (a-z) |
| Lowercase letters | a-z | Converted to uppercase (A-Z) |
| Digits | 0-9 | Unchanged |
| Punctuation | . , ! ? ; : | Unchanged |
| Symbols | @ # $ % & * | Unchanged |
| Whitespace | Space, tab, newline | Unchanged |
| Accented letters | é, ñ, ü, É, Ñ, Ü | Case swapped (browser dependent) |
Examples
Basic examples: Hello World → hELLO wORLD ABC xyz → abc XYZ The Quick Brown Fox → tHE qUICK bROWN fOX a1B2c3 → A1b2C3 Mixed content (letters affected, rest unchanged): Email: [email protected] → eMAIL: [email protected] Price: $99.99 USD → pRICE: $99.99 usd Path: /Home/User/docs → pATH: /hOME/uSER/DOCS Code snippets: function myFunction() → FUNCTION MYfUNCTION() const API_KEY = "abc" → CONST api_key = "ABC" <div class="nav"> → <DIV CLASS="NAV">
Common Use Cases
- Fix caps lock mistakes: Recover text typed with caps lock on accidentally
- Alternating case style: Create mOcKiNg tExT effect for memes or stylistic purposes
- Data normalization: Handle inconsistently capitalized datasets
- Debugging: Test case-sensitive code, passwords, or API keys
- Double inversion recovery: Fix text that was uppercased then lowercased (or vice versa)
- Test data generation: Create varied case patterns for testing
- Accessibility: Some users find alternating case easier to read
Case Inversion in Programming
JavaScript:
function invertCase(str) {
return str.split('').map(c => {
return c === c.toUpperCase() ? c.toLowerCase() : c.toUpperCase();
}).join('');
}
Python:
text = "Hello World"
inverted = text.swapcase()
# Result: "hELLO wORLD"
PHP:
$text = "Hello World";
$inverted = strtr($text,
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz');
Java:
StringBuilder result = new StringBuilder();
for (char c : text.toCharArray()) {
if (Character.isUpperCase(c)) {
result.append(Character.toLowerCase(c));
} else {
result.append(Character.toUpperCase(c));
}
}
Unicode and International Characters
Modern JavaScript engines support Unicode case conversion:
- Latin extended: Á↔á, Ñ↔ñ, Ü↔ü, ß↔SS (German sharp s)
- Greek: Α↔α, Β↔β, Γ↔γ
- Cyrillic: А↔а, Б↔б, В↔в
- Special cases: Turkish İ↔i, I↔ı (dotted/dotless)
Note: Some locale-specific cases (like Turkish dotted I) may require special handling in production code.
Technical Notes
- Performance: O(n) time complexity where n is string length
- Memory: Creates new string; original unchanged
- Encoding: Works with UTF-8 encoded text
- Browser support: Universal for ASCII; Unicode varies by engine
- Reversibility: Applying invert twice returns original text
How to Invert Case
- Enter your text: Type or paste the text you want to transform.
- Click Invert Case: The tool swaps uppercase to lowercase and vice versa.
- Review the result: Check that the transformation looks correct.
- Copy the output: Use the inverted text in your document or application.
Tips
- Invert twice returns the original text (useful for verification)
- Non-letter characters remain unchanged
- Works with multi-line text and code snippets
- For title case or other transformations, use dedicated case converters
- Unicode support depends on your browser's JavaScript engine
Frequently Asked Questions
- What is case inversion and when is it useful?
- Case inversion (also called toggle case or swap case) converts uppercase letters to lowercase and lowercase to uppercase. It's useful for: fixing incorrectly capitalized text, creating alternating case effects, normalizing inconsistent data, debugging case-sensitive issues, and meeting specific formatting requirements.
- How does case inversion handle non-alphabetic characters?
- Non-alphabetic characters remain unchanged: digits (0-9), punctuation, symbols, spaces, and special characters pass through unmodified. Only A-Z and a-z letters are affected. Unicode letters with diacritics (é, ñ, ü) are also inverted when supported by the browser.
- What is the difference between invert case and other case transformations?
- Invert case swaps existing case (A→a, a→A). Uppercase converts all to caps (HELLO). Lowercase converts all to small (hello). Title case capitalizes first letters (Hello World). Each serves different purposes: invert for toggling, uppercase for emphasis, lowercase for normalization, title case for headings.
- Does invert case work with accented characters?
- Modern browsers support Unicode case conversion, so accented letters like é↔É, ñ↔Ñ, ü↔Ü are inverted. However, support varies by browser and JavaScript engine. Simple ASCII (A-Z, a-z) works universally. Test with your specific characters if using extended Unicode.
- What are common use cases for case inversion?
- Common uses: fixing caps lock mistakes, alternating case for stylistic effect (mOcKiNg tExT), normalizing mixed-case data, debugging case-sensitive code or passwords, creating test data with varied casing, and reversing accidental double-capitalization.
- How is case inversion implemented in programming?
- Most languages provide case inversion: JavaScript uses char.toUpperCase() and char.toLowerCase() in a map; Python has str.swapcase(); PHP uses strtr with range mapping; Java has manual iteration with Character.isUpperCase(). The algorithm checks each character and applies the opposite case.