camelCase, snake_case and kebab-case: A Developer's Guide
The common programming naming conventions, which languages and contexts use each, and how to convert between them.
Programming languages and file systems do not allow spaces in names, so developers use naming conventions to join words. Using the right one makes code consistent and easier to read.
The main conventions
| Convention | Example | Typical use |
|---|---|---|
| camelCase | userAccountId | JavaScript and Java variables and functions |
| PascalCase | UserAccount | Classes and types in many languages; React components |
| snake_case | user_account_id | Python variables and functions, database columns, Ruby |
| kebab-case | user-account-id | URLs, CSS classes, file names, command-line flags |
| CONSTANT_CASE | MAX_RETRY_COUNT | Constants and environment variables |
| dot.case | user.account.id | Configuration keys and some logging systems |
Follow the language's style guide
- JavaScript/TypeScript: camelCase for variables, PascalCase for classes and components.
- Python (PEP 8): snake_case for functions and variables, PascalCase for classes, CONSTANT_CASE for constants.
- PHP (PSR-12): camelCase for methods, PascalCase for classes.
- CSS: kebab-case for class names.
- SQL: snake_case is the most common convention for tables and columns.
Acronyms
Teams disagree on acronyms: userId or userID, XmlParser or XMLParser. Many style guides prefer treating acronyms as normal words (userId, XmlParser) because it keeps word boundaries clear. Choose one approach and document it.
Converting between styles
Our case converter converts plain phrases and existing identifiers. Paste "user account id" or "getUserName" and choose camelCase, PascalCase, snake_case, kebab-case, CONSTANT_CASE or dot.case. It splits camelCase boundaries automatically, which is useful when moving data between a JavaScript front end and a Python or SQL back end.
Consistent naming is a small habit that saves real time in code reviews and debugging.
Frequently asked questions
CamelCase vs snake_case: when should I use each?
In the camelCase vs snake case choice, follow the language. JavaScript naming conventions use camelCase for variables and functions. Python naming conventions (PEP 8) use snake_case. SQL naming conventions usually use snake_case for columns. When to use camelCase? In JavaScript, Java and PHP methods.
Snake case vs kebab case: what is the difference?
Snake case vs kebab case differ only in the separator: underscores (user_name) versus hyphens (user-name). Snake case is common in code and databases; kebab case is used in URLs, file names and CSS class names. CSS naming conventions favor kebab-case.
How to convert to camelCase or snake_case?
Paste the phrase into our camelCase converter and click camelCase, or click snake_case to convert to snake case. The same tool is a snake case converter, kebab case converter and PascalCase converter, and it also handles dot case.
What are PHP naming conventions?
PHP naming conventions in the PSR standards use PascalCase for classes, camelCase for methods and CONSTANT_CASE for class constants. Variable names follow the project's style, commonly camelCase.
How to name variables well?
How to name variables: use descriptive names that state the purpose (totalPrice, not tp), follow the language's naming convention, avoid unclear abbreviations and keep naming case styles consistent across the codebase.
Try the free Case Converter
Switch text between UPPERCASE, lowercase, Title Case, Sentence case and coding cases.
Open Case Converter