camelCase vs snake_case vs kebab-case: which to use
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
| Aspect | camelCase | snake_case | kebab-case |
|---|---|---|---|
| Separator | None — capital letters mark word breaks | Underscore | Hyphen |
| Java / JavaScript variables | Standard | Rare | Impossible (hyphen is illegal) |
| Python / Rust / Ruby variables | Discouraged | Standard | Impossible (hyphen is illegal) |
| CSS classes / HTML attributes | Works but uncommon | Uncommon | Standard |
| URL paths / filenames | Discouraged (case-sensitive) | Works | Standard (search engines split on hyphens) |
| Typing cost | Needs Shift | Needs Shift + minus | Lowest |
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
- JS / Java / C# variables and functions → camelCase
- Python / Rust / Go / database columns → snake_case
- CSS class names, URLs, filenames → kebab-case
- Constants → SCREAMING_SNAKE_CASE
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.