camelCase vs snake_case: A Guide to Naming Conventions in Code
Published 6/20/2025 · 3 min read · Developer tools
Daniel Okonkwo — Front-end developer and tech writer at Allin
Web performance · File formats
Checked against 2 sources
camelCase joins words with no spaces and capitalizes each word after the first, like firstName. snake_case uses lowercase words joined by underscores, like first_name. PascalCase capitalizes every word, like FirstName, and kebab-case uses lowercase words joined by hyphens, like first-name. The right choice is dictated by your language and its community style guide: camelCase for JavaScript variables, snake_case for Python, PascalCase for class names, kebab-case for URLs and CSS.
camelCase, snake_case, PascalCase, and kebab-case explained: what each looks like, where it is the convention, and how to choose one consistently.
The four conventions at a glance
All four solve the same problem: identifiers cannot contain spaces, so multi-word names need a joining rule. camelCase writes myUserName, capitalizing every word after the first. PascalCase, also called UpperCamelCase, capitalizes the first word too, giving MyUserName. snake_case lowercases everything and joins with underscores, my_user_name. kebab-case does the same with hyphens, my-user-name.
The differences are purely stylistic to a human, but not to a computer: myUserName and my_user_name are different identifiers. That is why converting between conventions has to be deliberate, and why a mismatch between what a database column is called and what your code expects is a classic source of bugs.
Where each convention is the norm
Conventions are set by language communities. JavaScript and Java use camelCase for variables and functions and PascalCase for classes and types. Python and Ruby favor snake_case for variables and functions, reserving PascalCase for classes. C# uses PascalCase for methods and properties. kebab-case is rare in code because hyphens read as minus signs, but it rules URLs, CSS class names, and HTML attributes.
A special case is the constant. Many languages write compile-time constants in SCREAMING_SNAKE_CASE, an all-uppercase snake_case such as MAX_RETRIES. This signals at a glance that the value should never change, and it is one of the few places uppercase snake_case is idiomatic.
Choosing and converting consistently
The single most important rule is consistency within a codebase. Do not mix firstName and first_name for the same concept. When you cross a boundary, such as reading snake_case columns from a database into a camelCase application, convert at the edge in one clearly named place, rather than sprinkling conversions everywhere.
Conversion is mechanical: split the name into words, then rejoin with the target rule. The only tricky part is splitting, because camelCase has no separator. A converter detects word boundaries at each uppercase letter, while snake_case and kebab-case split on their delimiter, letting you move a name between any two styles reliably.
Frequently asked questions
- What is the difference between camelCase and PascalCase?
- Only the first letter. camelCase starts lowercase (userName); PascalCase capitalizes the first word too (UserName). PascalCase is also called UpperCamelCase.
- Why is kebab-case not used for variable names?
- Because most languages read the hyphen as a subtraction operator, so first-name would parse as first minus name. It is safe in URLs, CSS, and HTML, where the hyphen is just a character.
- Which convention should I use for a REST API's JSON fields?
- There is no single rule, but camelCase and snake_case are both common. Pick one, document it, and keep every field in the API consistent so clients can rely on it.
- Is there a name for ALL_CAPS with underscores?
- Yes, it is called SCREAMING_SNAKE_CASE, or upper snake case. It is the common convention for constants, like MAX_SIZE or API_KEY.
Articles you may find interesting
All guides →Related tools
Sources
Spotted a mistake in this article?