Skip to content
Allin

camelCase vs snake_case: A Guide to Naming Conventions in Code

Published 6/20/2025 · 3 min read · Developer tools

Daniel Okonkwo

Daniel OkonkwoFront-end developer and tech writer at Allin

Web performance · File formats

Checked against 2 sources

View profile
In short

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.

Programming case converterConvert identifiers between camelCase, snake_case, kebab-case, PascalCase and CONSTANT_CASE, one per line. Runs of capitals split correctly: parseHTTPResponse becomes parse_http_response.Try the tool

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
ExplainerThe Caesar Cipher Explained: How Shift Ciphers and ROT13 WorkThe Caesar cipher shifts every letter by a fixed amount. Learn how the shift works, why ROT13 is a special case, how to encode and decode by hand, and why the cipher offers no real security today.How-toHow to Convert JSON to CSV: Flattening Arrays of Objects into Rows and ColumnsA practical guide to turning a JSON array of objects into a clean CSV file, including how to flatten nested fields and handle the tricky edge cases.ExplainerWhat Is a URL Slug? Why Lowercase, Hyphenated, and Good for SEOA URL slug is the readable, hyphenated part of a web address that names a page. Learn why slugs are lowercase, how they help SEO, and how to generate one from a title.ComparisoncamelCase, snake_case, kebab-case: Which One, and Why You Rarely Get to ChooseThe conventions are not taste. A hyphen is the minus operator, so kebab-case cannot be an identifier in most languages - which is exactly why CSS and URLs use it. Plus the acronym round-trip that silently corrupts names, and the rule that fixes it.How-toRegex Basics: A Beginner's GuideA regular expression is a pattern for matching text. Here are the building blocks — character classes, quantifiers and anchors — with a worked example.ExplainerEscaping a String for JSON: Three Characters Are Mandatory, and One Is a TrapRFC 8259 requires exactly three things to be escaped inside a JSON string. Everything else is optional. The one that actually breaks pipelines is a lone surrogate — legal in JSON text, impossible in UTF-8, and silently replaced the moment your data is written out.

Related tools

Sources

Spotted a mistake in this article?