Mastering Text Cases: Camel, Snake, and Kebab Explained
A clear map of which case to use in JavaScript, Python, CSS, URLs, and configs, and how to convert between them.
Picking a naming convention is the easy part. Converting between conventions is where bugs hide. This guide gives a quick map of the common styles and then goes deep on conversion: how a case converter splits identifiers, where acronyms, digits, and non-ASCII letters break it, and which conversions you can safely reverse. For the conventions each language and tool expects, see programming naming conventions.
The Common Styles at a Glance
| Style | Example | Typically used for |
|---|---|---|
| camelCase | getUserById | JavaScript/TypeScript variables and functions, Java methods, many JSON APIs |
| PascalCase | UserService | Classes and types, React components |
| snake_case | get_user_by_id | Python, Ruby and Rust variables and functions, SQL column names |
| SCREAMING_SNAKE_CASE | MAX_RETRIES | Constants, environment variables |
| kebab-case | my-first-post | URL slugs, CSS class names, HTML attributes such as data-user-id |
| Train-Case | Content-Type | HTTP header names as conventionally written (header names are case-insensitive) |
Kebab-case cannot be used for variable names in most languages because the hyphen is parsed as a minus operator. Most conversions happen where data crosses a boundary: a snake_case database row becoming a camelCase JavaScript object (user_first_name to userFirstName), or an API response being mapped for a frontend. Convert once at that boundary rather than throughout the code. The naming conventions post covers why kebab-case cannot be a variable name, the per-language rules, and a worked key-mapping helper for nested objects and arrays.
Spaces and Punctuation
Naming conventions do not allow spaces or most punctuation, so converters treat them as word boundaries and usually drop them. A tokenizer that only recognizes ASCII letters and digits will also treat accented letters as separators, which can silently shorten a name (see the Unicode section below).
How a Case Converter Works: Split, Then Join
Every conversion between naming styles is really two steps. First the identifier is split into words. Then those words are re-joined with the target style's rules. All the interesting bugs live in the first step, because delimited styles (snake_case, kebab-case) mark the word boundaries explicitly while camelCase and PascalCase only hint at them with capital letters. The mechanics matter because they decide what survives a round trip.
A tokenizer in JavaScript needs two rules to find boundaries inside camel-style names, plus a split on existing delimiters:
const toWords = (s) => s
.replace(/([a-z\d])([A-Z])/g, "$1 $2") // fooBar -> foo Bar, user2Name -> user2 Name
.replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2") // HTTPResponse -> HTTP Response
.split(/[\s_\-]+/).filter(Boolean).map((w) => w.toLowerCase());
toWords("getUserById").join("_") // "get_user_by_id"
toWords("api-base-url").join("_") // "api_base_url"The first rule splits where a lowercase letter or digit meets a capital. The second handles runs of capitals: when several capitals are followed by a lowercase letter, the last capital is assumed to start the next word. A shorter one-liner is common for quick scripts, but it only has the first rule:
"userFirstName".replace(/([a-z\d])([A-Z])/g, "$1_$2").toLowerCase()
// "user_first_name"
"parseXMLHTTPRequest".replace(/([a-z\d])([A-Z])/g, "$1_$2").toLowerCase()
// "parse_xmlhttprequest" <- the acronym run was never splitAcronyms: Where Information Gets Lost
A run of capitals is ambiguous. Does XMLHTTPRequest mean XML + HTTP + Request, or XMLH + TTP + Request? Only a human (or a dictionary) knows. The two-rule tokenizer above gives these results:
| Input | snake_case result | Problem |
|---|---|---|
| userID | user_id | Fine: a trailing acronym splits cleanly |
| getHTTPResponse | get_http_response | Fine: the second rule splits HTTP from Response |
| parseXMLHTTPRequest | parse_xmlhttp_request | Two adjacent acronyms merge into one word |
| XMLHttpRequest | xml_http_request | Fine, but the original acronym casing is lost |
| iPhoneCase | i_phone_case | Lowercase prefix is read as a word of its own |
Converting parse_xmlhttp_request back to camelCase gives parseXmlhttpRequest, which is not what you started with. The practical defence is to avoid adjacent acronyms in identifiers and to pick one policy for acronyms. Treating them as ordinary words (XmlHttpRequest, parseXmlHttpRequest) converts cleanly in both directions, because every word boundary is marked by a capital. The Rust API guidelines take this approach (Uuid rather than UUID). Go goes the other way and requires initialisms to have a uniform case (userID, ServeHTTP), which is harder to convert mechanically. Either is fine as long as it is consistent and your converter is told about it.
Numbers: Which Word Do They Belong To?
Digits have no case, so a tokenizer cannot tell whether 2 belongs to the word before or after it. The rule above attaches digits to the preceding letters and starts a new word at the next capital:
| Input | snake_case result | Note |
|---|---|---|
| user2Name | user2_name | Digits stay glued to the word before them |
| apiV2Endpoint | api_v2_endpoint | Works because V is capitalized |
| oauth2Token | oauth2_token | Reasonable |
| Base64Encode | base64_encode | Reasonable |
| user_2_name | user_2_name | A different identifier from user2_name |
The last row is the trap: user_2_name and user2_name are different identifiers, but both can map to user2Name in camelCase, so converting snake to camel and back can silently rename a field. Even a simple replace such as s.replace(/_([a-z])/g, ...) turns user_2_name into user_2Name, because the underscore before a digit is never touched. When identifiers include numbers, compare converter output against your real schema instead of trusting it, and prefer names where the number is part of a word (base64, oauth2) or clearly separated (v2).
Unicode and Locale Surprises
Case conversion is not a simple one-to-one letter mapping once you leave ASCII.
- Length can change.
"straße".toUpperCase()returns"STRASSE", so the string gets longer and uppercasing is not reversible. - Locale matters.
"I".toLowerCase()is"i", but"I".toLocaleLowerCase("tr")is the dotless"ı", and"i".toLocaleUpperCase("tr")is"İ". Never run locale-sensitive methods on identifiers or protocol keywords: usetoLowerCase()for those so a user's device language cannot changeTITLEintotıtle. [a-z]and\ware ASCII-only. A tokenizer written with[a-z]misses boundaries next to accented capitals:ÜberCoolÄpfelbecomesüber_cooläpfelwith the ASCII rules, butüber_cool_äpfelwhen the classes are replaced with\p{Ll}and\p{Lu}and theuflag is added.- Composed vs decomposed accents.
"café"can be 4 code points (éas one) or 5 (eplus a combining accent). Call.normalize("NFC")before comparing or splitting, and include\p{M}(marks) in letter classes when decomposed input is possible.
For code identifiers the safest policy is to restrict names to ASCII. For prose, such as title-casing headlines, expect to need locale-aware libraries.
Title Case and Sentence Case for Prose
Programming cases are not the only ones you may need. UPPERCASE, lowercase, Sentence case and Title Case are common for headings and UI copy, and JavaScript only provides the first two natively. The naive title-case idiom, s.replace(/\b\w/g, c => c.toUpperCase()), works for "hello world" but breaks on real text: "élan" becomes "éLan" because \w does not match é, and "l’été" becomes "L’éTé". Style guides such as AP and Chicago also disagree on which small words stay lowercase, so Title Case is a style decision rather than a mechanical one.
Which Conversions Are Lossless?
| Conversion | Round-trips? | Why |
|---|---|---|
| snake_case, kebab-case and SCREAMING_SNAKE_CASE between each other | Yes | Only the delimiter and letter case change, and the word boundaries are explicit |
| Delimited form to camelCase or PascalCase and back | Mostly | Lost if a word is a single letter, a number, or an acronym you wanted to keep |
| camelCase or PascalCase to a delimited form | Only if no acronyms | Word boundaries must be inferred from capitals |
| Anything to lowercase or UPPERCASE | No | Word boundaries are discarded |
Treat conversion into camelCase or PascalCase as a one-way operation unless your identifiers are plain lowercase words. If you need to go back, keep the original names in a mapping instead of recomputing them.
Converting in Bulk
For a list of SQL columns or constants, retyping is how typos creep in. Our Text Case Converter offers camelCase, PascalCase, snake_case, kebab-case, CONSTANT_CASE, dot.case, Title Case, sentence case, UPPERCASE, and lowercase. Know its limits before you rely on it: it treats anything other than ASCII letters and digits (including underscores and hyphens) as a word separator, and it does not split on capital letters. That means user_first_name or user first name converts correctly, but userFirstName to snake_case comes out as userfirstname, and accented letters are treated as separators and dropped. For camelCase input, use the tokenizer above in code instead, then spot-check names that contain acronyms or digits.
Frequently Asked Questions
How do I convert camelCase to snake_case in JavaScript?
For simple names, s.replace(/([a-z\d])([A-Z])/g, "$1_$2").toLowerCase() works. If your names contain acronyms such as HTTPResponse, add a second replace for /([A-Z]+)([A-Z][a-z])/g as shown above.
What is Train-Case, and how is it different from kebab-case?
Train-Case capitalizes each word and joins them with hyphens (Content-Type), while kebab-case is all lowercase (content-type). HTTP header names are conventionally written in Train-Case, though header names are case-insensitive.
Is Title Case the same as PascalCase?
No. Title Case keeps spaces between words (Text Case Converter) and is meant for human-readable headings, while PascalCase removes the spaces (TextCaseConverter) to form an identifier.
Why does uppercasing "ß" give "SS"?
Unicode defines a full case mapping for ß that expands it to two letters, and JavaScript's toUpperCase() follows it. The result is that case conversion can change a string's length and cannot be undone by lowercasing.
Can I convert case in bulk without writing code?
Yes. Yes, if the names are separated by spaces, underscores, or hyphens: paste them into the Text Case Converter and pick the target style. It does not split camelCase input on capital letters, so for that use the tokenizer above. Spot-check any names with acronyms or digits either way.
Written by Kashyap Thakar
Spotted a mistake? Let me know
Try these tools
Use these tools alongside this guide