Text Case Conventions Every Developer Should Know
Naming conventions are one of those small decisions that compound across an entire codebase. Use the wrong case in the wrong place and your code looks foreign to anyone familiar with the language. This guide covers every major text case convention, when each one applies, and the reasoning behind them.
The major case styles
camelCase
The first word is lowercase, every subsequent word starts with an uppercase letter. No separators.
getUserName
fetchOrderDetails
isActive
Where it is used: JavaScript and TypeScript variables and functions, Java methods and variables, JSON property names (by convention), Swift variables and functions.
camelCase is the default style for the JavaScript ecosystem. If you are writing a JS/TS library, your public API should use camelCase for methods and properties.
PascalCase (UpperCamelCase)
Every word starts with an uppercase letter. No separators.
UserProfile
HttpResponse
OrderService
Where it is used: Class names in nearly every language (Java, C#, TypeScript, Python), React component names, C# methods and properties, Go exported identifiers, TypeScript interfaces and types.
PascalCase signals "this is a type or constructor" in most codebases. In React, it is mandatory for components -- the JSX compiler uses the case to distinguish between HTML elements and custom components.
// React requires PascalCase for components
function UserCard({ name }: { name: string }) {
return <div>{name}</div>;
}
// This works:
<UserCard name="Alice" />
// This would be treated as an HTML element:
<userCard name="Alice" /> // Wrong -- renders as unknown HTML element
snake_case
All lowercase with underscores separating words.
user_name
get_order_details
is_active
Where it is used: Python variables, functions, and modules (PEP 8 standard), Ruby methods and variables, Rust variables and functions, PostgreSQL column names, C standard library functions.
Python's PEP 8 is unambiguous: functions and variables use snake_case, and the community follows this strictly. If you are writing Python and using camelCase for functions, every linter will flag it.
# Python convention
def get_user_by_id(user_id: int) -> dict:
first_name = fetch_first_name(user_id)
return {"first_name": first_name}
SCREAMING_SNAKE_CASE (UPPER_SNAKE_CASE)
All uppercase with underscores separating words.
MAX_RETRY_COUNT
API_BASE_URL
DATABASE_CONNECTION_STRING
Where it is used: Constants in almost every language, environment variables, C/C++ preprocessor macros, enum values (in some conventions).
This convention universally means "this value does not change." When you see MAX_CONNECTIONS, you know immediately it is a constant without checking the declaration.
const MAX_RETRY_COUNT = 3;
const API_BASE_URL = 'https://api.example.com';
const DEFAULT_TIMEOUT_MS = 5000;
kebab-case
All lowercase with hyphens separating words.
user-profile
get-order-details
my-component
Where it is used: URLs and URL slugs, CSS class names, HTML attributes, npm package names, CLI flags, Kubernetes resource names, YAML keys (often).
kebab-case is the web's native case. URLs are case-insensitive by convention, and hyphens are the standard word separator. CSS class names universally use this style.
.user-profile-card {
background-color: var(--card-bg);
border-radius: 8px;
}
# CLI flags
npm install --save-dev
docker run --restart=always
Title Case
The first letter of each significant word is capitalized.
The Quick Brown Fox Jumps Over
How to Build a REST API
Where it is used: Headings, titles, UI labels, button text in some design systems.
The rules for Title Case vary by style guide. AP style, Chicago style, and APA style all have slightly different rules about which prepositions and conjunctions to capitalize. Most tools capitalize every word or follow simplified rules.
Sentence case
Only the first word and proper nouns are capitalized.
The quick brown fox jumps over
How to build a REST API
Where it is used: Google's Material Design for buttons, many modern UI frameworks, body text, descriptions.
Why conventions matter
Consistent casing across a codebase provides instant visual signals about what an identifier represents:
| You see | You infer |
|---|---|
PascalCase |
Class, type, interface, component |
camelCase |
Variable, function, method, property |
snake_case |
Python/Ruby variable or function |
SCREAMING_SNAKE |
Constant, env variable |
kebab-case |
URL, CSS class, CLI flag |
Breaking these conventions forces every reader to spend extra cognitive cycles parsing your code. Following them makes your code feel native to its ecosystem.
Converting between cases programmatically
The core algorithm for case conversion is:
- Tokenize: Split the input into individual words by detecting boundaries (underscores, hyphens, spaces, or uppercase-to-lowercase transitions)
- Normalize: Lowercase all tokens
- Rejoin: Combine tokens using the target convention's rules
// Simple tokenizer that handles most cases
function tokenize(str) {
return str
.replace(/([a-z])([A-Z])/g, '$1 $2') // camelCase boundaries
.replace(/[_\-]+/g, ' ') // underscore/hyphen separators
.toLowerCase()
.trim()
.split(/\s+/);
}
function toCamelCase(str) {
const words = tokenize(str);
return words[0] + words.slice(1).map(w => w[0].toUpperCase() + w.slice(1)).join('');
}
function toSnakeCase(str) {
return tokenize(str).join('_');
}
function toKebabCase(str) {
return tokenize(str).join('-');
}
Common mistakes
Mixing conventions in one language. A JavaScript file with both get_user and getUser is confusing. Pick the language's convention and stick with it.
Using camelCase for database columns. SQL is case-insensitive by default, and most databases fold unquoted identifiers to lowercase. Use snake_case for columns: created_at, not createdAt.
Forgetting acronyms. How do you write "HTTP API client" in PascalCase? HTTPAPIClient is unreadable. Most style guides recommend treating acronyms longer than two letters as regular words: HttpApiClient.
kebab-case in JavaScript identifiers. Hyphens are the minus operator in JS. You cannot write my-variable as an identifier. Use camelCase for JS and save kebab-case for CSS, URLs, and file names.
Summary
Every casing convention exists for a reason, shaped by the language, ecosystem, or medium it serves. Knowing which to use where -- and converting between them when crossing boundaries (like mapping a snake_case database column to a camelCase JSON field) -- is a small skill that keeps your code clean and idiomatic.
Try our Case Converter to convert text between any case format instantly -- right in your browser, no upload required.