CamelCase vs PascalCase vs snake_case: When to Use Each
Programming naming conventions are one of the first things developers learn and one of the last things they stop arguing about. camelCase, PascalCase, snake_case, and kebab-case each have established homes in modern software development, and choosing the wrong convention for a context — even if the code still runs — signals unfamiliarity with the codebase's norms. Understanding when each case is appropriate makes your code more readable, more consistent with community standards, and easier for collaborators to work with. This guide explains each convention, where it is used, and how to convert between them instantly.
camelCase: The Standard for Variables and Functions
camelCase writes compound words with no separators, where each word after the first starts with a capital letter. The name comes from the humped appearance of the capital letters in the middle of the word — like the humps of a camel. Examples: firstName, getUserById, isValidEmail, totalItemCount. Lower camelCase (which begins with a lowercase letter) is the dominant convention for variable names and function names in many of the world's most widely used programming languages. In JavaScript and TypeScript, variables and function names are camelCase by convention: let userName, function calculateTotal(). In Java, all non-constant variables and methods use camelCase: String firstName, void processPayment(). In Swift and Kotlin, camelCase is the standard for variables, constants, and functions. In Python, camelCase is technically legal but not the preferred convention — Python uses snake_case for variables and functions (see below). camelCase is also used in JSON property names in most JavaScript ecosystems: { 'firstName': 'John', 'totalAmount': 99.99 }. When an API returns JSON data, the property names are almost universally camelCase in Node.js-based backends and JavaScript-first APIs. The advantage of camelCase for code is that it produces compact names with no extra characters. A variable like customerOrderCount is clear, readable, and shorter than customer_order_count by two characters — a small difference per occurrence that compounds across a large codebase.
PascalCase: Classes, Types, and Components
PascalCase (also called UpperCamelCase) is identical to camelCase except the very first letter is also capitalized. Examples: UserProfile, PaymentProcessor, HttpRequest, ShoppingCart. PascalCase is the universal convention for class names across virtually all object-oriented languages. In Java, C#, JavaScript, TypeScript, Python, Ruby, and Swift, class names use PascalCase. This is one of the most consistent naming conventions across programming languages — wherever you see a PascalCase identifier in code, it almost certainly refers to a class, type, or constructor. In TypeScript and C#, interface names and type aliases use PascalCase. In TypeScript: interface UserRepository, type ApiResponse. In C#: interface IUserRepository (with a conventional I prefix), class DatabaseContext. In React and other modern JavaScript frameworks, component names must be PascalCase. A React component named userCard would not work correctly — React distinguishes between built-in HTML elements (lowercase) and custom components (PascalCase): <UserCard /> versus <div>. This is not a style choice; it is required by React's JSX parser. In Python, classes follow PascalCase (class CustomerProfile) while functions and variables use snake_case. This makes the distinction between class names and function names visually immediate in Python code. PascalCase is also used for enumeration members in some languages (Swift, Kotlin) and for namespace names in C# and other languages.
snake_case: Python, Databases, and Constants
snake_case writes compound words with all letters lowercase and words separated by underscores. Examples: first_name, user_profile, get_user_by_id, maximum_retry_count. snake_case is the canonical naming convention in Python. PEP 8, Python's official style guide, specifies snake_case for variables, functions, methods, modules, and packages. This is consistently applied across the entire Python ecosystem, making Python code visually distinctive from JavaScript and Java code. If you are writing Python and using camelCase, you are writing non-idiomatic Python that will feel out of place to other Python developers. In database design, snake_case is the dominant convention for table names and column names across most database systems including PostgreSQL, MySQL, and SQLite. Columns like user_id, created_at, product_category, and total_price are snake_case. This convention exists partly because SQL keywords are case-insensitive and databases are often case-insensitive for identifiers by default, making lowercase with underscores the safe, consistent choice. ORMs (Object-Relational Mappers) like Django's ORM, Rails' ActiveRecord, and SQLAlchemy are designed around snake_case database conventions and typically handle the mapping to camelCase in application code automatically. SCREAMING_SNAKE_CASE (all uppercase with underscores) is the universal convention for constants in most languages: MAX_CONNECTIONS, DEFAULT_TIMEOUT, API_BASE_URL, DATABASE_URL. This applies in Python, JavaScript, Java, C, and many others. Seeing SCREAMING_SNAKE_CASE in code immediately signals 'this is a constant that should not change at runtime.'
kebab-case: URLs, CSS, and HTML Attributes
kebab-case writes compound words with all letters lowercase and words separated by hyphens. Examples: primary-button, max-width, user-profile-page, get-started. kebab-case is the standard for CSS class names and CSS custom property names. Classes like .nav-link, .hero-section, .card-title, and .is-active are all kebab-case. CSS custom properties (variables) follow the same convention: --primary-color, --font-size-base, --border-radius-sm. CSS property names themselves (like background-color, font-size, flex-direction) are also kebab-case. HTML attributes are kebab-case: data-user-id, aria-label, data-toggle-target. Custom data attributes must be kebab-case by HTML specification. URL slugs and path segments use kebab-case for SEO and readability: /blog/how-to-count-words, /products/wireless-headphones, /about-us. Search engines parse words in hyphenated slugs as separate words, which matters for keyword relevance. Underscores in URLs are treated as word joiners by Google (wireless_headphones is treated as one word, wireless-headphones as two separate words). kebab-case is also used as file names for components and modules in some ecosystems, particularly Vue.js (where component files are named my-component.vue) and general web projects where lowercase filenames with hyphens are preferred for cross-platform compatibility (since Windows is case-insensitive but Linux is case-sensitive for file names). kebab-case cannot be used as variable names in most programming languages because the hyphen is the subtraction operator. Writing let kebab-case would be parsed as let kebab minus case. This is why kebab-case is limited to contexts outside of programming language identifiers: CSS, HTML, URLs, and file names.
Frequently Asked Questions
- Which case convention should I use for REST API endpoint names?
- REST API URL paths should use kebab-case for path segments: /api/user-profiles, /api/order-items, /api/payment-methods. This is the recommendation in the REST API design guidelines used by Google, Microsoft, and most major API providers. Query parameter names in REST APIs are typically camelCase (following JSON conventions): ?sortOrder=asc, ?userId=123. JSON response body property names should be camelCase when the primary consumer is a JavaScript application, and snake_case when the primary consumer is Python or a system that prefers snake_case. This is a pragmatic convention choice, not a hard technical requirement.
- Can I mix naming conventions in the same codebase?
- Within a single language context, mixing conventions should be avoided because it reduces readability and creates inconsistency that makes code harder to navigate. However, it is entirely normal to use multiple conventions across different layers of a project. A typical web application might use camelCase for JavaScript variables and functions, PascalCase for React components and TypeScript types, snake_case for Python backend code and database columns, kebab-case for CSS classes and URL slugs, and SCREAMING_SNAKE_CASE for environment variables and constants. Each layer follows its own language's conventions — they just happen to use different cases.
- Does the case converter handle multi-word phrases correctly for camelCase and snake_case?
- Yes. The WikiPlus Case Converter splits input text on spaces, underscores, hyphens, and other common word separators, then reassembles the words in the target case. This means you can convert 'user profile page' (space-separated), 'user_profile_page' (snake_case), 'user-profile-page' (kebab-case), or 'UserProfilePage' (PascalCase) and get the correct result in any target format. The tool recognizes the structure of compound words in any of these input formats, making it a reliable bidirectional converter rather than just a one-way transformer.