camelCase vs snake_case vs kebab-case

The same phrase can be written four ways depending on where it lives. Names in code, keys in a database, URLs and headings each have a convention, and following the local one matters more than which style you prefer.

The three styles

StyleExampleTypical use
camelCaseuserAccountBalanceVariables in JavaScript, Java, Swift
PascalCaseUserAccountBalanceClass and type names
snake_caseuser_account_balancePython variables, SQL columns, JSON keys
kebab-caseuser-account-balanceURLs, CSS class names, HTML attributes
SCREAMING_SNAKEUSER_ACCOUNT_BALANCEConstants

There is no universal winner. Each language and platform picked one, and consistency within a layer is worth more than the choice itself.

Convert text between upper, lower, title and sentence case.

Open the Case Converter →

Why each convention exists

camelCase avoids the underscore key, which is awkward to type on some layouts and was historically significant in languages where underscores were less idiomatic. It reads well for short names and worse for long ones.

snake_case is easier to read for long names and is the Python and SQL norm. kebab-case is required in URLs because underscores can be hidden by link underlines, and in CSS because it matches HTML attribute conventions.

Where mixing causes bugs

The classic failure is a field named userId in one layer and user_id in another, with a conversion that is missing or applied twice. The result is a silent null rather than an error.

Another is a URL slug built with underscores, which some systems and search engines treat differently from hyphens. Consistency at the boundary is what prevents both.

Converting between them

Split the name into words, then rejoin in the target style. Splitting is the hard part: a run of capitals such as HTTPServer needs to become HTTP and Server, and a number such as user2fa is ambiguous.

For most cases a simple rule works: split on underscores and hyphens, then split camelCase at each capital that follows a lowercase letter. Test on your real data before converting a whole column.

Acronyms and numbers

Acronyms are where conventions differ most. Some teams write userId, others write userID, and some write user_id with the acronym lowercased. Pick one rule and document it, because automated conversion cannot guess.

Numbers should usually attach to the preceding word, as in address2 or version2, rather than starting a new word. That keeps the split predictable.

URLs and slugs

URLs use kebab-case because hyphens are word separators in search engines and are visible in a link. Underscores can disappear under an underline, and camelCase in a URL is read as one long word.

Lowercase everything in a URL. Case sensitivity varies by server, so a link that works in testing can fail when someone types it in lowercase.

Files and folders

File names follow the same logic as URLs: lowercase kebab-case avoids problems across Windows, macOS and Linux, where case handling differs.

Avoid spaces in file names for anything that will be served or scripted. A space becomes %20 in a URL and breaks shell commands that are not quoted.

Data keys and APIs

JSON keys are usually camelCase or snake_case depending on the ecosystem. The important rule is that one API uses one style throughout, because clients generate code from the examples.

If you must support both, convert at the boundary and never in the middle of a pipeline. One conversion point is testable; several are not.

Common mistakes

A conversion checklist

List the distinct names in the source. Run the conversion. Compare the before and after lists side by side and look for collisions, such as user_id and userId both mapping to the same target.

Collisions are the dangerous outcome, because they silently merge two fields. A diff catches them in seconds.

Choosing a style for a new project

Follow the dominant language and framework. A Python project uses snake_case for variables and modules, PascalCase for classes. A JavaScript project uses camelCase for variables and PascalCase for components.

Where the language is silent, pick the style that reads best for the names you actually have, then apply it everywhere.

Frequently asked questions

Which is better, camelCase or snake_case?

Neither. Follow the convention of the language or platform you are working in.

Why do URLs use hyphens?

They are treated as word separators by search engines and remain visible in underlined links.

Can I mix styles in one project?

Not within a layer. Different layers, such as code and URLs, normally use different styles.

Sources

More free tools

Related guides