All tools / Buying guides / camelCase vs snake_case vs kebab-case: which to use

camelCase vs snake_case vs kebab-case: which to use

The short answer

Follow the language ecosystem — do not invent your own. JavaScript and Java variables use camelCase, Python / Ruby / Rust use snake_case, CSS class names, URL paths and npm package names use kebab-case, and constants use SCREAMING_SNAKE_CASE. Consistency within a project matters far more than picking the "best" style.

Key differences

AspectcamelCasesnake_casekebab-case
SeparatorNone — capital letters mark word breaksUnderscoreHyphen
Java / JavaScript variablesStandardRareImpossible (hyphen is illegal)
Python / Rust / Ruby variablesDiscouragedStandardImpossible (hyphen is illegal)
CSS classes / HTML attributesWorks but uncommonUncommonStandard
URL paths / filenamesDiscouraged (case-sensitive)WorksStandard (search engines split on hyphens)
Typing costNeeds ShiftNeeds Shift + minusLowest

camelCase and PascalCase

Camel case marks word boundaries with capital letters and adds no extra characters, making it the standard for variables and functions in Java, JavaScript, C# and Swift; the capitalised PascalCase is usually reserved for classes and component names. The downside is friction for non-native English readers and for all-caps acronyms — XMLHttpRequest is the classic example.

snake_case and kebab-case

snake_case uses underscores and is the mainstream style in Python, Ruby, Rust, Go and database column names; its SCREAMING_SNAKE_CASE variant is reserved for constants. kebab-case uses hyphens and is the standard for CSS class names, HTML attributes, URL paths and npm package names — hyphens are illegal in identifiers but perfectly natural in URLs and CSS, and search engines treat them as word separators.

How to choose

Related tools

FAQ

Can I mix styles in one project

It is unavoidable across language boundaries (camelCase front end, snake_case back end is very common). Convert once at the boundary layer instead of letting both styles leak into the same layer of code.

Why hyphens rather than underscores in URLs

Search engines treat a hyphen as a word separator, while an underscore may be read as a joiner — user-name tokenises better than user_name.

Does naming style affect performance

Not at all. It is purely about readability and team convention, and consistency is worth much more than the style itself.