Naming Conventions in Code: camelCase, snake_case & kebab-case
A programming naming convention is a standardized syntactical rule governing how multi-word identifiers—such as variables, functions, classes, and database columns—are cased and delimited to maintain consistency, avoid compiler syntax errors, and maximize codebase readability.
Because computer compilers and interpreters treat whitespace as token delimiters, variable names cannot contain spaces (e.g., total user count is parsed as three distinct tokens rather than one reference). Over decades of software development, programming communities established standardized casing conventions to separate words without introducing spaces. Choosing the correct casing standard is critical for language idiomaticity, team consistency, and automated linting configurations.
Programming Casing Conventions Reference Matrix
Use this reference table to compare standard naming conventions across typography patterns, delimiters, and target language environments:
| Convention | Formatting Pattern | Primary Use Cases | Dominant Ecosystems |
|---|---|---|---|
| camelCase | firstSecondThird |
Variables, functions, class methods | JavaScript, TypeScript, Java, Go, Swift |
| PascalCase | FirstSecondThird |
Classes, interfaces, React components, types | C#, Java, TypeScript, Python classes |
| snake_case | first_second_third |
Variables, module functions, database fields | Python, Rust, Ruby, PostgreSQL, MySQL |
| SCREAMING_SNAKE | FIRST_SECOND_THIRD |
Global constants, environment variables | C, C++, Node.js, Python, Java, PHP |
| kebab-case | first-second-third |
CSS selectors, HTML attributes, URL slugs | CSS, HTML, REST URLs, Kubernetes manifests |
1. camelCase vs. PascalCase: Rules and Implementation
Both camelCase and PascalCase eliminate delimiters by capitalizing the first letter of compound words. The single difference lies in the first character:
camelCase (Lower Camel Case)
The identifier begins with a lowercase letter, followed by uppercase initial letters for every subsequent word. In JavaScript, TypeScript, and Java, camelCase is the standard for local variables, object keys, and functions:
// JavaScript / TypeScript example
const maxRetryAttempts = 3;
function calculateMonthlyInterest(accountBalance, annualRate) {
return (accountBalance * annualRate) / 12;
}
PascalCase (Upper Camel Case)
Every word begins with a capital letter, including the very first word. PascalCase is traditionally reserved for constructors, object-oriented classes, TypeScript types, and UI components:
// TypeScript interface & class
interface UserBillingProfile {
accountNumber: string;
isSubscriptionActive: boolean;
}
class PaymentProcessor {
// Class implementation
}
Frontend Framework Convention: In React and Vue, component names must use PascalCase (e.g., <UserProfileCard />). This signals to the compiler that the tag represents a user-defined component rather than a native HTML element (such as <div> or <span>).
2. snake_case vs. kebab-case: Underscores vs. Hyphens
snake_case (Under_Score)
snake_case separates words with underscores (_) in all-lowercase letters. It is the official styling standard in Python under PEP 8, Rust under RFC 430, and relational databases like PostgreSQL and MySQL:
# Python PEP 8 standard
def verify_user_permission(user_record, permission_level):
auth_token = generate_session_token(user_record.id)
return auth_token is not None
Relational databases prefer snake_case because SQL syntax is traditionally case-insensitive. Writing columns as first_name prevents parsing conflicts that arise when database drivers normalize uppercase letters into lowercase.
kebab-case (Dash-Case)
kebab-case separates words with hyphens (-). Because programming languages interpret hyphens as subtraction operators (meaning user-name is evaluated as user minus name), kebab-case is invalid for variables in nearly all compiled and interpreted languages.
However, kebab-case is the universal standard for CSS class names, HTML custom attributes, and SEO URL slugs:
/* CSS syntax standard */
.user-profile-header {
display: flex;
justify-content: space-between;
}
→ To transform text strings between uppercase, lowercase, Title Case, and Sentence case instantly, use our Free Case Converter Tool.
3. SCREAMING_SNAKE_CASE: Universal Constant Notation
When a variable represents an immutable, global constant or configuration setting, developers use all-uppercase letters separated by underscores:
// Global configuration constants
const MAXIMUM_FILE_UPLOAD_BYTES = 10485760; // 10MB
const DEFAULT_AUTH_EXPIRATION_SECONDS = 3600;
This signals to other engineers that the reference is immutable and should never be reassigned during runtime execution.
4. The Full-Stack Boundary: Bridging snake_case and camelCase
A frequent design challenge in full-stack web architecture occurs at the network boundary:
- Database layers (PostgreSQL / MySQL) store records in snake_case (e.g.,
created_at,user_id). - Frontend codebases (TypeScript / JavaScript) operate in camelCase (e.g.,
createdAt,userId).
To avoid leaking database architecture into frontend state, API serializes should transform keys at the network controller layer (using automated object mappers or schema validators) rather than manually renaming variables across UI components.
Frequently Asked Questions
Why does Google prefer kebab-case over snake_case in URLs?
Google’s search algorithms interpret hyphens (kebab-case) as clear word separators, indexing web-tools as two distinct words ("web tools"). Underscores (snake_case) are treated as character joiners, meaning crawlers may interpret web_tools as a single compound string ("web_tools"), reducing keyword match precision.
What is the difference between camelCase and PascalCase?
camelCase starts with a lowercase letter (e.g., userAccount) and is used for variables, functions, and object keys. PascalCase capitalizes the initial letter of every word (e.g., UserAccount) and is reserved for classes, TypeScript types, and UI components like React elements.
How should acronyms like HTTP or URL be handled in camelCase?
Modern clean code style guides recommend treating acronyms as standard words rather than full capitalizations. For example, use parseHttpUrl() or xmlHttpRequest rather than parseHTTPURL() or XMLHTTPRequest. This maintains clear word boundaries and avoids awkward consecutive uppercase sequences.
Can I use kebab-case for JSON keys?
While valid JSON allows any string in double quotes (e.g., {"user-id": 101}), using kebab-case in JSON is discouraged. In JavaScript, kebab-case keys cannot be accessed via dot notation, forcing developers to use bracket syntax (data['user-id'] instead of data.userId).
Related Text & Publishing Utilities
- Free Case Converter Tool (convert text to UPPERCASE, lowercase, Title Case, and Sentence case)
- Free Slug Generator (convert headlines into sanitized, lowercase kebab-case permalinks)
- Free Word Counter (analyze text volume, character counts, and reading time)