What is CamelCase? A Developer's Complete Guide
CamelCase is everywhere in programming — but so are its relatives PascalCase, snake_case, and kebab-case. This guide explains each convention, which languages use them, and when to use which.
What is CamelCase?
CamelCase (also written camel case or camelCase) is a naming convention where multiple words are concatenated without spaces, and each word except the first starts with a capital letter. The name comes from the "humps" formed by the capital letters — like a camel's back.
Examples: myVariable, getUserData, firstName, isLoggedIn
Types of CamelCase
There are two variants of camelCase in widespread use:
Lower camelCase (camelCase)
The first word is entirely lowercase; each subsequent word starts with a capital letter. This is what most developers mean when they say "camelCase".
myVariablegetUserByIdisEmailValidtotalPriceWithTax
Used for: variables, functions, and method names in JavaScript, Java, Swift, Kotlin, TypeScript, and C#.
Upper CamelCase (PascalCase)
Every word, including the first, starts with a capital letter. Also called PascalCase because it was popularized by the Pascal programming language.
MyVariableGetUserByIdUserProfilePageShoppingCartController
Used for: class names, constructor functions, React components, C# namespaces, and TypeScript interfaces.
CamelCase vs snake_case
snake_case uses all lowercase letters with underscores separating words. It is the opposite approach to camelCase's capitalization strategy.
| Concept | camelCase | snake_case |
|---|---|---|
| User ID variable | userId | user_id |
| Get user function | getUser() | get_user() |
| Is valid flag | isValid | is_valid |
| First name field | firstName | first_name |
Use camelCase in: JavaScript, TypeScript, Java, Swift, Kotlin, C#
Use snake_case in: Python, Ruby, PHP (variables), SQL column names, file names in many projects
CamelCase vs kebab-case
kebab-case (also called spinal-case or hyphen-case) uses all lowercase words joined by hyphens. It is named for the resemblance to food on a skewer.
| Concept | camelCase | kebab-case |
|---|---|---|
| CSS class | (not used) | user-profile-card |
| URL slug | (not used) | getting-started-guide |
| File name | userProfile.js | user-profile.js |
| HTML attribute | data-userId | data-user-id |
Important: Kebab-case cannot be used as variable names in most programming languages because the hyphen is treated as a subtraction operator. It is primarily used in CSS, HTML, URLs, and file names.
All Four Naming Conventions Compared
| Convention | Example | Where used |
|---|---|---|
| camelCase | getUserData | JS/TS variables & functions, Java, Swift |
| PascalCase | GetUserData | Classes, React components, C# methods |
| snake_case | get_user_data | Python, Ruby, SQL, PHP variables |
| kebab-case | get-user-data | CSS, HTML, URLs, file names |
| SCREAMING_SNAKE_CASE | MAX_RETRY_COUNT | Constants in most languages |
When to Use CamelCase: Language-by-Language Guide
- JavaScript / TypeScript: camelCase for variables and functions; PascalCase for classes and React components
- Java: camelCase for methods and variables; PascalCase for classes and interfaces
- Python: snake_case for variables and functions (PEP 8); PascalCase for class names
- C#: PascalCase for methods, properties, and classes; camelCase for private fields and parameters
- Swift: camelCase for variables, functions, and properties; PascalCase for types and protocols
- Ruby: snake_case for methods and variables; PascalCase for classes and modules
- Go: camelCase for unexported (private) identifiers; PascalCase for exported (public) identifiers
- CSS / HTML: kebab-case for class names and attributes
- SQL: snake_case for column and table names
Why Consistent Naming Conventions Matter
Consistent naming conventions make code easier to read, search, and maintain. When every developer on a team follows the same convention, there is no ambiguity about whether a function should be called getUser, get_user, or GetUser. Most linters and formatters (ESLint, Prettier, Black, RuboCop) can automatically enforce naming conventions as part of your CI/CD pipeline.
Need to convert text between naming conventions? Try our Case Modify tools — including uppercase, lowercase, and text transformation tools that work directly in your browser.
Frequently Asked Questions
What is camelCase in programming?
CamelCase is a naming convention where words are joined without spaces, and each word after the first starts with a capital letter: myVariableName. It is one of the most widely used naming conventions in JavaScript, Java, Swift, and TypeScript.
What is the difference between camelCase and PascalCase?
In camelCase the first word is lowercase (myClass); in PascalCase every word starts with a capital (MyClass). PascalCase is typically used for class names; camelCase for variables and functions.
Should I use camelCase or snake_case for JavaScript?
The JavaScript community convention (and the ECMAScript specification) uses camelCase for variables and functions. Use camelCase in JavaScript and TypeScript projects unless your team's style guide specifies otherwise.
Can I use camelCase in CSS?
Technically yes, but it is strongly discouraged. CSS convention is kebab-case for class names and IDs (.user-profile-card). HTML attributes and custom data attributes also use kebab-case (data-user-id). CamelCase in CSS can cause confusion and break cross-browser compatibility in some edge cases.
Related articles: What is Title Case? • Uppercase vs Lowercase • What is Sentence Case?