Text & Writing
How To Convert Text Case
Changing the case of a piece of text is not a single operation. There are at least eight named styles, each with its own rules, and picking the wrong one is as much a mistake as getting the letters wrong.
Quick Answer
Title Case = capitalise each significant word, lower-case the small ones
- word
- A run of letters, digits or hyphens
- small word
- Articles, conjunctions and short prepositions
- separator
- Space, underscore or hyphen between words
The phrase how to convert text between naming styles becomes How to Convert Text Between Naming Styles in Title Case, with the small word to left in lower case.
What Is How To Convert Text Case?
Text case is about which letters are capitalised and how words are joined. It sounds like a cosmetic detail, but several programming languages and file systems treat differently cased names as different things, so case is sometimes functional rather than decorative.
Upper case writes every letter as a capital. It is used for headings, acronyms and short labels, and it is genuinely harder to read in long passages because all the letters lose their distinctive shapes and the text becomes a uniform block.
Lower case writes every letter small. It is the default for body text, for file names on most web servers, and for anything where case-insensitivity is desirable.
Title Case capitalises the first letter of each significant word. The convention, in both the Chicago and the AP style guides, is to keep short articles, conjunctions and prepositions in lower case unless they begin or end the title.
The small words left lower-case in Title Case are the articles a, an and the, the conjunctions and, or and but, and short prepositions such as of, to, in, on, at, by, for, with and as. Anything longer, or any verb, is capitalised.
Sentence case capitalises only the first letter of the sentence and any proper nouns. It is the normal style for running text and for many modern editorial guidelines, which prefer it over Title Case for headlines because it is easier to read.
camelCase joins words with no separator and capitalises every word after the first. It is the standard for variables and function names in JavaScript, Java and Swift, and it always starts with a lower-case letter.
PascalCase is camelCase with the first word capitalised as well. It is used for class and type names in many languages and for component names in JavaScript frameworks.
snake_case joins words with underscores and writes them in lower case. It is the convention for variables and function names in Python and Ruby, and for column names in SQL.
kebab-case joins words with hyphens and writes them in lower case. It is the standard for CSS class names, for HTML attributes, and for URL slugs, where spaces are not permitted.
SCREAMING_SNAKE_CASE is snake_case in upper case and is the usual style for constants in many languages. It is not a separate idea so much as a combination of two of the others.
Converting between the joined styles requires splitting the text into words first. A splitter must break on spaces and punctuation and also on the capital letters inside camelCase, which is why a naive split on spaces turns customerAccountBalance into a single word.
The calculator converts text into any of the eight styles, splitting on spaces, punctuation and existing camel boundaries so that mixed input still converts cleanly. It reports the character and word counts of the input as well.
Formula
Title Case = capitalise significant words, keep small words lower-case
Each word is capitalised unless it belongs to the set of small words, which stay in lower case unless they open or close the title.
| Symbol | Meaning | Unit | Notes |
|---|---|---|---|
| w | Word | word | A single word in the text. |
| S | Small words | set | Articles, conjunctions and short prepositions. |
camelCase = first lower + rest capitalised, no separator
Split into words, keep the first in lower case, capitalise the rest, and join them with no separator. snake_case and kebab-case use the same split with a different separator and no capitals.
| Symbol | Meaning | Unit | Notes |
|---|---|---|---|
| w_i | Word | word | The i-th word after splitting. |
| cap | Capitalise | operation | Upper-case the first letter and lower-case the rest. |
How To Calculate How To Convert Text Case
- 1
Split the text into words
Break on spaces and punctuation, and also on the capital letters inside camelCase, so that customerAccountBalance becomes three words rather than one.
- 2
Normalise the letters
Decide the target case for each word. Upper and lower case apply to the whole string; the other styles work word by word.
- 3
Apply the style rule
Title Case capitalises significant words and leaves small words alone. camelCase lower-cases the first word, snake_case and kebab-case lower-case everything.
- 4
Join with the right separator
A space for Title and Sentence case, nothing for camel and Pascal, an underscore for snake and a hyphen for kebab.
- 5
Check the result reads correctly
Acronyms and proper nouns often need manual repair. An identifier such as userId may come back as User Id or user id depending on how the splitter treats the capitals.
Examples
Example 1: Title Case a headline
- Text
- the quick brown fox jumps over the lazy dog
- Style
- Title Case
| Step | Calculation | Result |
|---|---|---|
| Words | split on the spaces | 9 |
| Small words kept lower-case | the, over, the | 3 |
| Words capitalised | 9 - 3 | 6 |
| Title Case output | capitalise six, keep three small | The Quick Brown Fox Jumps Over the Lazy Dog |
Result: The headline becomes The Quick Brown Fox Jumps Over the Lazy Dog, with the six main words capitalised and the three small words left in lower case.
Example 2: camelCase from a sentence
- Text
- user profile settings
- Style
- camelCase
| Step | Calculation | Result |
|---|---|---|
| Words | split on the spaces | 3 |
| First word lower-case | user | user |
| Remaining words capitalised | profile, settings | 2 |
| camelCase output | join with no separator | userProfileSettings |
Result: The three words become userProfileSettings, with the first word left in lower case and the other two capitalised.
Calculator
Prefer a full-width tool? Open the How To Convert Text Case calculator page.
Common Mistakes
Capitalising the small words in a title
Title Case keeps articles, conjunctions and short prepositions in lower case. Capitalising every word is a different style, sometimes called Start Case.
Using Title Case for body text
Title Case is a headline style. Applying it to a paragraph makes the text harder to read, because every word competes for attention.
Splitting camelCase on spaces only
A camelCase identifier has no spaces to split on. The splitter must detect the capital letters inside the word, or the whole identifier is treated as one token.
Mixing naming conventions in one file
A codebase that uses camelCase in one place and snake_case in another is harder to read and can hide bugs when names are compared. Pick one convention per language and keep it.
Assuming case conversion is reversible
Lower-casing a string and then title-casing it does not restore the original, because the information about which letters were capitalised has been discarded.
Ignoring locale-specific capitalisation
In Turkish a lower-case i capitalises to a dotted capital I, which differs from the English rule. Locale-aware capitalisation matters for any text that is not plain ASCII.
Forgetting that some file systems are case sensitive
Renaming a file from readme to Readme is a real change on a case-sensitive file system but a no-op on a case-insensitive one, which trips up deployments.
FAQ
What is the difference between Title Case and Sentence case?
Title Case capitalises each significant word, while Sentence case capitalises only the first word and any proper nouns. Sentence case is generally considered easier to read and is common in modern editorial style.
Which words stay lower-case in Title Case?
Articles such as a, an and the, conjunctions such as and, or and but, and short prepositions such as of, to, in, on, at, by, for and with. They are usually capitalised if they begin or end the title.
What is the difference between camelCase and PascalCase?
camelCase starts with a lower-case letter, as in getUserName, while PascalCase starts with a capital, as in GetUserName. Languages differ over which one is used for which kind of name.
When should I use snake_case or kebab-case?
snake_case is the convention for Python and Ruby identifiers and for SQL columns. kebab-case is used for CSS classes, HTML attributes and URL slugs, where hyphens are allowed but spaces are not.
Why does converting my text break acronyms?
A splitter cannot tell that the ID in userId is an acronym rather than a word. It may produce User Id or user id, and the acronym needs repairing by hand after the conversion.
Does changing case change the character count?
No. Changing a letter from lower to upper case does not change how many characters there are, so a character limit is unaffected by a case conversion.
References
- [1]The Chicago Manual of Style, Title Case and headline style — https://www.chicagomanualofstyle.org/home.html
- [2]Python Software Foundation, Naming conventions in programming — https://peps.python.org/pep-0008/
- [3]Unicode Consortium, Unicode case mapping — https://www.unicode.org/versions/latest/ch04.pdf