camelCase vs snake_case vs kebab-case: Naming Conventions by Language
camelCase, PascalCase, snake_case, kebab-case and CONSTANT_CASE: what each looks like, which languages and files expect which, and how to handle acronyms.
userId, UserId, user_id, user-id and USER_ID are the same two words joined five different ways. None of them is more correct than the others. What matters is where the name lives: each language, file format and protocol has a convention, and code that ignores it looks wrong to everyone who reads it, and sometimes simply does not work.
Paste any identifier or list of identifiers into the converter below to see every case at once. It runs in your browser.
Case ConverterPaste text to see it in every case at once, from camelCase and snake_case to Title Case and sentence case. Everything runs in your browser.The five cases you will meet most
| Name | Example | How the words are joined |
|---|---|---|
| camelCase | orderTotal | First word lowercase, each later word capitalized |
| PascalCase | OrderTotal | Every word capitalized; also called UpperCamelCase |
| snake_case | order_total | All lowercase, separated by underscores |
| CONSTANT_CASE | ORDER_TOTAL | All uppercase with underscores; also called SCREAMING_SNAKE_CASE |
| kebab-case | order-total | All lowercase, separated by hyphens |
There are a few less common ones: dot.case shows up in config keys such as spring.datasource.url, and Train-Case is how HTTP headers like Content-Type are traditionally written.
Which convention each language expects
Most languages mix two or three cases, using the case itself to tell you what kind of thing a name refers to.
| Language | Variables and functions | Classes and types | Constants |
|---|---|---|---|
| JavaScript / TypeScript | camelCase | PascalCase (also React components) | CONSTANT_CASE by convention |
| Python (PEP 8) | snake_case | PascalCase | CONSTANT_CASE |
| Java / Kotlin | camelCase | PascalCase | CONSTANT_CASE |
| C# | camelCase locals, PascalCase methods and properties | PascalCase | PascalCase |
| Go | camelCase (private), PascalCase (exported) | Same rule | Same rule |
| Rust | snake_case | PascalCase | CONSTANT_CASE |
| Ruby | snake_case | PascalCase | CONSTANT_CASE |
| PHP (PSR-1) | camelCase methods | PascalCase | CONSTANT_CASE |
Go is the one where case is not just style. A name that starts with a capital letter is exported from its package, and a lowercase one is private. Renaming parseConfig to ParseConfig changes the package's public API.
Outside the code: files, URLs, databases and config
The language is only part of the picture. The same value often crosses several systems that each have their own rules.
- CSS uses kebab-case for properties (
background-color), and kebab-case is the norm for class names and custom properties (--brand-500). - HTML attributes are lowercase and
data-*attributes use kebab-case. The browser converts them for you:data-user-idbecomeselement.dataset.userIdin JavaScript. - URLs use kebab-case. Google's URL guidelines recommend hyphens rather than underscores to separate words, so
/blog/order-totalrather than/blog/order_total. - SQL tables and columns are usually snake_case. In PostgreSQL this is close to a requirement: unquoted identifiers are folded to lowercase, so a column created as
userIdis actually stored asuserid, and you have to write"userId"in quotes everywhere to keep the capital. - Environment variables are CONSTANT_CASE:
DATABASE_URL,NODE_ENV. Shells allow lowercase, but uppercase with underscores is what every tool and platform expects. - HTTP headers are case-insensitive. HTTP/1.1 traditionally writes them in Train-Case (
Content-Type), while HTTP/2 and HTTP/3 send them all lowercase (content-type). Never compare header names with a case-sensitive check. - JSON APIs have no single rule. Google's JSON style guide recommends camelCase, which matches JavaScript clients; the Stripe and GitHub REST APIs use snake_case (
created_at). Pick one per API and do not mix them in the same payload.
Acronyms: the part conventions disagree on
Is it userID or userId? XMLHttpRequest or XmlHttpRequest? Style guides genuinely disagree:
- Go keeps initialisms in one consistent case:
userID,ServeHTTP,parseURL. - Rust treats an acronym as a single word:
Uuid, notUUID, andHttpClient, notHTTPClient. - .NET capitalizes two-letter acronyms fully (
IOStream) and treats longer ones as words (HtmlParser). - JavaScript has both in its own standard library:
XMLHttpRequestnext toencodeURIComponentandinnerHTML.
Treating acronyms as ordinary words (userId, HtmlParser) is the easier rule to follow, because it survives conversion. Fully capitalized acronyms do not:
getUserID → get_user_id → getUserId
XMLHttpRequest → xml_http_request → XmlHttpRequest
Once a name has gone through snake_case, nothing records that ID or XML used to be capitals, so converting back cannot restore them. If your code generator or ORM maps database columns to object properties, this is why user_id turns into userId and never userID.
Converting between cases without breaking names
Converting a name means first splitting it into words, then joining those words in the new style. The splitting step is where naive find-and-replace goes wrong.
- Acronyms followed by a word.
XMLHttpRequestisXML+Http+Request. Splitting before every capital letter givesX M L Http Request. - Numbers inside words.
base64Encodeandsha256Hashshould becomebase64_encodeandsha256_hash, notbase_64_encode. The digits belong to the word before them. - Mixed input. A list copied from a spreadsheet may contain spaces, underscores and hyphens at once. Any non-letter, non-digit character should count as a word break.
The converter above follows these rules, so you can paste a column of database names and copy back the camelCase properties, or the other way around. Check the output for acronyms you want to keep in capitals, since those are the one thing no converter can guess.
Quick reference
| Where the name lives | Use |
|---|---|
| JavaScript, TypeScript, Java variables and functions | camelCase |
| Classes, types, React components | PascalCase |
| Python, Ruby, Rust variables and functions | snake_case |
| Constants and environment variables | CONSTANT_CASE |
| Database tables and columns | snake_case |
URLs, CSS classes, file names, data-* attributes | kebab-case |
| JSON fields | camelCase or snake_case, consistently within one API |
When you are unsure, look at the code around you and follow it. A project that consistently uses an unusual convention is easier to work in than one that switches between two good ones.
