Guide

Case Styles in Programming: camelCase, snake_case & More Explained

Every codebase has a naming convention, and almost nobody agrees on the same one across languages. A JavaScript function is getUserData, the JSON it returns has a field called user_data, and the database column behind that field is user_data again but the table is UserProfiles. None of that is random — each case style has a history and a reason it stuck to a particular ecosystem, and knowing the pattern saves you from second-guessing every variable name you write.

The case styles you'll actually run into

There are more naming schemes than anyone needs to memorize, but a handful cover almost everything you'll see in real code:

StyleExampleWhere it's the default
camelCaseuserAccountIdJavaScript/TypeScript variables and functions, Java methods, JSON in web APIs
PascalCaseUserAccountClass and type names in almost every language (JS, Java, C#, Python classes)
snake_caseuser_account_idPython variables and functions, Ruby, SQL column and table names
SCREAMING_SNAKE_CASEMAX_RETRY_COUNTConstants in almost any language, environment variables
kebab-caseuser-account-idURL slugs, HTML/CSS attributes, CLI flags, file names in many JS projects
Train-Case / HTTP-Header-CaseContent-TypeHTTP headers specifically — rarely used elsewhere

Notice that most languages don't use just one style — they use different styles for different kinds of names within the same file. A single line of Python might reference a snake_case variable, call a PascalCase class, and read a SCREAMING_SNAKE_CASE constant, and that's completely normal, not inconsistent.

Why the conventions differ by language

These aren't arbitrary style preferences — most trace back to a specific style guide that a language's core team published early on, which then became the expected norm because tooling, linters, and code reviews enforce it. Python's PEP 8 explicitly recommends snake_case for functions and variables, which is why almost all Python code looks that way even though the language itself doesn't require it. JavaScript inherited camelCase from Java, which inherited it from a mix of earlier C-family conventions. Ruby's community settled on snake_case independently of Python, for similar readability reasons. CSS and HTML use kebab-case because hyphens are the only word-separator character that's valid in both without extra escaping — camelCase HTML attributes and underscored CSS properties simply don't parse the way you'd expect.

The practical upshot: when you're writing idiomatic code in a language, match what that language's standard library and popular frameworks already do. A snake_case variable in a JavaScript file, or a camelCase one in Python, isn't wrong in the sense that it won't run — but it reads as foreign to anyone who's spent time in that ecosystem, and most linters will flag it.

Where mixing case styles actually breaks things

Most of the time, inconsistent casing is a style nit a linter catches. But there are a few spots where it causes real bugs, not just ugly diffs:

Converting between case styles without doing it by hand

Renaming a batch of keys, migrating an API response format, or reformatting a CSV header row into valid variable names is a mechanical, error-prone task if you do it one name at a time — it's easy to miss an underscore or leave one word un-capitalized in a long list. The Case Converter tool takes a block of text or a list of names and converts the whole thing at once — camelCase, PascalCase, snake_case, kebab-case, CONSTANT_CASE, and a few others — entirely in your browser, so nothing you paste in (which might be internal field names or schema details) gets sent anywhere.

A common real use: you're given a spreadsheet of column headers like First Name, Last Login Date, Account ID, and you need them as valid snake_case database columns or camelCase JSON keys before you can use them in code. Pasting the whole list into the Case Converter and converting in one pass is faster and more reliable than retyping each one, and it avoids the small inconsistencies (one column ending up accountid instead of account_id) that creep in when a list gets long enough that attention drifts.

A quick reference for which style to reach for

What you're namingConvention to use
JavaScript/TypeScript variable, functioncamelCase
Class or type, in almost any languagePascalCase
Python or Ruby variable, functionsnake_case
Constant (any language)SCREAMING_SNAKE_CASE
URL path segment, CLI flag, CSS classkebab-case
Database column or table namesnake_case (check your ORM's default first)
Environment variableSCREAMING_SNAKE_CASE

When a style guide exists for your project — an ESLint config, a company handbook, a language's own official guide like PEP 8 — that overrides any general rule here. Consistency within one codebase matters more than picking the theoretically "correct" style; a project that's consistently wrong by some external standard is still easier to work in than one that's inconsistent with itself.

Frequently asked questions

Does the case style I use actually affect how code runs?

For variable and function names, no — most languages treat userName and user_name identically as far as execution goes; casing there is purely a readability and convention matter enforced by linters and code review, not the compiler or interpreter. The exceptions are places where casing carries meaning: file paths on case-sensitive file systems, HTTP header names in some strict parsers, and any system (like a case-sensitive database) that treats differently-cased identifiers as genuinely different names.

Why do JSON APIs so often use snake_case even in JavaScript-heavy projects?

JSON itself has no naming convention — it's plain text — so the casing you see reflects whichever backend generated it. A huge number of web APIs are built with Python, Ruby, or PHP backends, all of which default to snake_case, so that convention ends up baked into the response even though the JavaScript frontend consuming it will typically use camelCase internally. Some frameworks convert automatically at the API boundary; many don't, which is why you'll often see both styles in the same request/response pair.

Is there one "correct" case style for naming things in general?

No — there's no universal standard across languages, only per-language and per-project conventions. What matters is matching the convention already used by the language, framework, or codebase you're working in, and then staying consistent within it. Introducing your own preferred style into a codebase that already has an established one creates more friction than any theoretical readability gain from your preferred format.

Last reviewed: · Who maintains this · How it is checked

Drafted with AI assistance and reviewed before publication — not claimed to be hand-written. This is a how-to rather than a factual reference, so it carries no Sources block: attaching official-looking citations to a page that does not need them borrows authority rather than demonstrating it. Where it does state a fact, that fact is checkable, and the tools it points to are on this site. Found something wrong? Tell us — we correct the page and re-date it.