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:
| Style | Example | Where it's the default |
|---|---|---|
| camelCase | userAccountId | JavaScript/TypeScript variables and functions, Java methods, JSON in web APIs |
| PascalCase | UserAccount | Class and type names in almost every language (JS, Java, C#, Python classes) |
| snake_case | user_account_id | Python variables and functions, Ruby, SQL column and table names |
| SCREAMING_SNAKE_CASE | MAX_RETRY_COUNT | Constants in almost any language, environment variables |
| kebab-case | user-account-id | URL slugs, HTML/CSS attributes, CLI flags, file names in many JS projects |
| Train-Case / HTTP-Header-Case | Content-Type | HTTP 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:
- API boundaries between languages. A Python backend naturally returns
snake_caseJSON keys, while the JavaScript frontend consuming it expects camelCase. Teams either convert at the boundary (a serializer that renames keys on the way out) or just live with camelCase-on-the-frontend, snake_case-on-the-wire — but forgetting which side does the converting is a classic source of "why is this field undefined" bugs. - Case-sensitive file systems and imports.
import Button from './button'works on Windows and macOS (case-insensitive by default) but fails on Linux CI if the file is actually namedButton.jsx. This is one of the most common "works on my machine, fails in CI" bugs, and it's purely a casing mismatch. - Environment variables and config keys. Shell convention is SCREAMING_SNAKE_CASE for env vars; a config loader that expects camelCase and silently returns
undefinedfor a mismatched key can fail without any error message at all. - Database columns vs. ORM model fields. Most SQL databases are case-insensitive or lowercase column names by default, so an ORM mapping a camelCase model field to a database column often needs an explicit mapping — skip it and the ORM either errors out or silently creates a second, differently-cased column.
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 naming | Convention to use |
|---|---|
| JavaScript/TypeScript variable, function | camelCase |
| Class or type, in almost any language | PascalCase |
| Python or Ruby variable, function | snake_case |
| Constant (any language) | SCREAMING_SNAKE_CASE |
| URL path segment, CLI flag, CSS class | kebab-case |
| Database column or table name | snake_case (check your ORM's default first) |
| Environment variable | SCREAMING_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.