Naming Conventions Explained
camelCase, snake_case, PascalCase, kebab-case — what each one is, where it's used, and how to convert between them.
Why naming conventions matter
Programming languages and systems can't use spaces in names. Multi-word identifiers like "user account id" need some other way to show word boundaries. Naming conventions solve this — they're consistent patterns for joining words without spaces.
Different ecosystems standardized on different conventions. Mixing them signals unfamiliarity with a codebase and makes grep/search harder. Most style guides and linters enforce a specific convention automatically.
The main conventions
| Convention | Example | Common uses |
|---|---|---|
| camelCase | userAccountId | JavaScript/TypeScript variables, functions, object keys, JSON fields |
| PascalCase | UserAccountId | Classes, React components, TypeScript types/interfaces, constructors |
| snake_case | user_account_id | Python variables/functions, Ruby, SQL columns, C/Rust, config files |
| SCREAMING_SNAKE_CASE | USER_ACCOUNT_ID | Constants in most languages, environment variables, macros in C |
| kebab-case | user-account-id | CSS classes/properties, HTML attributes, URL slugs, CLI flags, filenames |
| dot.case | user.account.id | Config keys (Java properties, .env), package names (com.example) |
| flatcase | useraccountid | Rare — some database names, domain names (no separator at all) |
camelCase
The first word is all lowercase; each subsequent word starts with an uppercase letter. No separators. The capitalized letters resemble a camel's humps.
// JavaScript — variables and functions use camelCase
const firstName = "Ada"
const totalOrderCount = 42
function calculateMonthlyPayment(principal, rate) { ... }
// JSON keys conventionally use camelCase
{ "userId": 1, "firstName": "Ada", "isVerified": true }PascalCase
Every word starts with a capital letter, including the first. Also called UpperCamelCase. Used for things that are "constructed" or "instantiated" — classes, types, and in React, components.
// Classes use PascalCase in most languages
class UserAccount { ... }
class HttpRequestHandler { ... }
// TypeScript types and interfaces
type UserRole = 'admin' | 'viewer'
interface ApiResponse { ... }
// React components — PascalCase tells React it's a component
function UserProfileCard({ user }) { ... }
<UserProfileCard user={currentUser} />snake_case
Words are separated by underscores, all lowercase. The dominant convention in Python, Ruby, and SQL — and how environment variables and most Unix filenames are written.
# Python — PEP 8 mandates snake_case for variables and functions
user_name = "Ada"
def calculate_monthly_payment(principal, interest_rate):
...
-- SQL — column names are conventionally snake_case
SELECT user_id, first_name, created_at
FROM user_accounts
WHERE is_verified = TRUE;kebab-case
Words separated by hyphens, all lowercase. Not valid in most programming languages (hyphens are subtraction operators), so it's used in contexts where identifiers aren't evaluated as code: CSS, HTML, URLs, CLI flags, and filenames.
/* CSS class names */
.user-profile-card { ... }
.is-active { ... }
/* HTML attributes */
<div data-user-id="1" aria-label="User profile"></div>
/* URL slugs */
/guides/naming-conventions-explained
/* CLI flags */
npm install --save-dev
git commit --no-editConverting between conventions
// JavaScript: snake_case → camelCase
"user_account_id"
.split('_')
.map((w, i) => i === 0 ? w : w[0].toUpperCase() + w.slice(1))
.join('')
// → "userAccountId"
// camelCase → kebab-case
"userAccountId"
.replace(/([A-Z])/g, '-$1')
.toLowerCase()
// → "user-account-id"
// camelCase → snake_case
"userAccountId"
.replace(/([A-Z])/g, '_$1')
.toLowerCase()
// → "user_account_id"Frequently asked questions
- What's the difference between camelCase and PascalCase?
- camelCase starts with a lowercase letter (myVariable), PascalCase starts with an uppercase letter (MyVariable). In practice, languages use them for different things — JavaScript uses camelCase for variables and functions, PascalCase for classes and constructors.
- Why can't I use kebab-case in JavaScript?
- Because the hyphen (-) is the subtraction operator in JavaScript. The parser would interpret user-name as user minus name. That's why CSS uses kebab-case (CSS has a different parser) but JavaScript uses camelCase. You can use kebab-case strings as object keys if you quote them: obj['user-name'], but not as bare identifiers.
- What should I use for filenames?
- It depends on the ecosystem. JavaScript/TypeScript projects typically use kebab-case (user-profile.ts) or PascalCase for React components (UserProfile.tsx). Python projects use snake_case (user_profile.py). The most important thing is consistency within a project — pick one and stick to it.