camelCase vs snake_case vs kebab-case: When to Use Each
Naming conventions keep tripping you up? Here's a practical breakdown of each case style and a free tool to convert between them.
Naming things is hard. Naming them in the right case is harder. I've seen codebases where the same developer used camelCase, snake_case, and kebab-case in the same file — all for variables. Picking a case style and sticking to it saves everyone time.
The Cases That Actually Matter
| Style | Example | Where you'll see it |
|---|---|---|
| camelCase | userName | JavaScript variables, Java methods |
| PascalCase | UserService | JS/TS classes, React components, C# types |
| snake_case | user_name | Python, Rust, file names |
| kebab-case | user-name | CSS classes, URL slugs, config keys |
| SCREAMING_SNAKE | MAX_RETRIES | Constants, env vars |
| lowercase | username | URLs, casual text |
| UPPERCASE | USERNAME | Headings, emphasis (rarely in code) |
| Title Case | User Name | Blog titles, button labels |
Why So Many Cases?
Mostly history. C liked lowercase. Java popularized camelCase. Python went with snake_case because it reads more like English. CSS chose kebab-case because hyphens are valid in selectors but camelCase isn't (well, it is now, but nobody uses it).
The conventions stick because consistency within a codebase matters more than which convention you pick.
Case Conversion in Practice
Where you actually need a converter:
- API field mapping — your backend returns snake_case, your frontend wants camelCase
- URL slugs — converting a blog title like "My Post Title" to my-post-title
- Constant extraction — turning defaultTimeout into DEFAULT_TIMEOUT
- CSS class generation — converting component names to kebab-case selectors
I've written these conversions as one-liners too many times. The text case converter on this site handles all the common styles — paste your text, pick the target case, copy the result.
## Text Case Types Explained
Different case styles serve different purposes:
- UPPERCASE: All letters capitalized. Used for emphasis, warnings, and acronyms.
- lowercase: All letters lowercase. Used in code identifiers (Python, CSS), URLs, and informal text.
- Title Case: First letter of each word capitalized. Used for book titles, article headlines, and song titles.
- Sentence case: First letter of each sentence capitalized. Standard for prose.
- camelCase: First word lowercase, subsequent words capitalized. Used in JavaScript, Java, and C# for variables and functions.
- PascalCase: Every word capitalized. Used for class names in many languages.
- snake_case: Words separated by underscores, typically lowercase. Used in Python, Ruby, and database column names.
- kebab-case: Words separated by hyphens. Used in URLs, CSS class names, and file names.
- CONST_CASE: All uppercase with underscores. Used for constants in many languages.
Case Conversion Pitfalls
- Locale sensitivity: In Turkish, the lowercase of
Iisı(dotless i), noti. Most programming languages handle this incorrectly unless you specify a locale. - Unicode: Converting case for non-ASCII characters (
é,ñ,ß) requires Unicode-aware functions. JavaScripttoUpperCase()handles most cases, but some edge cases fail. - Existing case: Converting
XMLParserto snake_case should producexml_parser, notx_m_l_parser. Smart case converters detect existing capitalization boundaries.