Naming conventions and where they are used
| Case | Example | Typically used for |
|---|---|---|
| camelCase | userAccountId |
JavaScript, Java and C# variables and functions, JSON keys |
| PascalCase | UserAccountId |
Classes and types in most languages, exported Go names, React components |
| snake_case | user_account_id |
Python and Ruby variables, Rust functions, SQL columns |
| CONSTANT_CASE | USER_ACCOUNT_ID |
Constants, environment variables |
| kebab-case | user-account-id |
URLs, CSS classes, HTML attributes, CLI flags, file names |
| COBOL-CASE | USER-ACCOUNT-ID |
COBOL, some HTTP header conventions |
| Train-Case | User-Account-Id |
HTTP headers (Content-Type) |
| dot.case | user.account.id |
Config keys (Spring, Java properties), i18n keys |
| path/case | user/account/id |
File paths, routes, package paths |
| Title Case | User Account Id |
Headings and labels |
| Sentence case | User account id |
UI text, messages |
| lower case | user account id |
Plain text |
| UPPER CASE | USER ACCOUNT ID |
Emphasis, SQL keywords |
| flatcase | useraccountid |
Java packages, some file names |
Conventions by language
- JavaScript and TypeScript: camelCase for variables and functions, PascalCase for classes, types and React components, CONSTANT_CASE for module-level constants.
- Python (PEP 8): snake_case for functions, variables and modules, PascalCase for classes, CONSTANT_CASE for constants.
- Go: camelCase for unexported names, PascalCase for exported ones. Acronyms keep one case:
userID,HTTPServer. - Rust: snake_case for functions, variables and modules, PascalCase for types and traits, CONSTANT_CASE for constants and statics.
- Java and C#: camelCase for fields, parameters and (in Java) methods, PascalCase for classes and (in C#) methods and properties.
- CSS and HTML: kebab-case for class names, custom properties (
--main-color) and attributes (data-user-id). - SQL: snake_case for tables and columns, because unquoted names are case-insensitive in most databases.
Tricky inputs
Splitting words correctly matters more than joining them. This is how the converter handles common edge cases:
| Input | snake_case | camelCase |
|---|---|---|
XMLHttpRequest |
xml_http_request |
xmlHttpRequest |
getHTTPResponseCode |
get_http_response_code |
getHttpResponseCode |
base64Encode |
base64_encode |
base64Encode |
iOSVersion |
i_os_version |
iOsVersion |
user_ID |
user_id |
userId |
Converting case in code
import { camelCase, snakeCase, kebabCase, startCase } from 'lodash-es';
camelCase('user_account_id'); // 'userAccountId'
snakeCase('userAccountId'); // 'user_account_id'
kebabCase('UserAccountId'); // 'user-account-id'
snakeCase('base64Encode'); // 'base_64_encode' (lodash splits numbers)
import re
def to_snake(name: str) -> str:
name = re.sub(r'([A-Z]+)([A-Z][a-z])', r'\1_\2', name) # XMLHttp -> XML_Http
name = re.sub(r'([a-z\d])([A-Z])', r'\1_\2', name) # fooBar -> foo_Bar
return re.sub(r'[-\s]+', '_', name).lower()
def to_camel(name: str) -> str:
first, *rest = to_snake(name).split('_')
return first + ''.join(w.capitalize() for w in rest)
to_snake('XMLHttpRequest') # 'xml_http_request'
to_camel('user_account_id') # 'userAccountId'
Converting JSON keys for a typed model? The JSON to Go and JSON to Pydantic generators rename fields to each language’s convention and keep the original key in a struct tag or alias.
Frequently asked questions
What is the difference between camelCase and PascalCase?
Both join words without separators and capitalise each word. camelCase starts with a lowercase letter (userName), PascalCase starts with an uppercase one (UserName). Most languages use camelCase for variables and functions and PascalCase for classes and types. In Go, PascalCase also means the name is exported from its package.
snake_case or kebab-case?
Use whatever the context expects. snake_case is valid in identifiers in almost every language, so it is used for Python and Ruby names, SQL columns and many JSON APIs. kebab-case contains hyphens, which most languages read as minus, so it is used where names are strings: URLs, CSS classes, HTML attributes, command-line flags and file names.
How are acronyms like HTTP or ID converted?
An acronym is detected as one word, so XMLHttpRequest splits into XML, Http, Request and becomes xml_http_request. By default acronyms are written like normal words in camelCase and PascalCase (XmlHttpRequest), as recommended by the Google and Microsoft style guides. Turn on “Keep acronyms uppercase” to keep XMLHttpRequest as it is.
How are numbers handled?
A number stays attached to the word before it, so base64Encode becomes base64_encode and v2Api becomes v2_api. Lodash and some other libraries split numbers into their own word (base_64_encode). Turn on “Numbers are separate words” if you need to match that behaviour.
Can I convert many names at once?
Yes. Paste one identifier per line, for example a list of database columns or JSON keys, and every line is converted separately. Indentation at the start of each line is kept. The table under the tool shows the first line in all 14 cases.