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

NameExampleHow the words are joined
camelCaseorderTotalFirst word lowercase, each later word capitalized
PascalCaseOrderTotalEvery word capitalized; also called UpperCamelCase
snake_caseorder_totalAll lowercase, separated by underscores
CONSTANT_CASEORDER_TOTALAll uppercase with underscores; also called SCREAMING_SNAKE_CASE
kebab-caseorder-totalAll 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.

LanguageVariables and functionsClasses and typesConstants
JavaScript / TypeScriptcamelCasePascalCase (also React components)CONSTANT_CASE by convention
Python (PEP 8)snake_casePascalCaseCONSTANT_CASE
Java / KotlincamelCasePascalCaseCONSTANT_CASE
C#camelCase locals, PascalCase methods and propertiesPascalCasePascalCase
GocamelCase (private), PascalCase (exported)Same ruleSame rule
Rustsnake_casePascalCaseCONSTANT_CASE
Rubysnake_casePascalCaseCONSTANT_CASE
PHP (PSR-1)camelCase methodsPascalCaseCONSTANT_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-id becomes element.dataset.userId in JavaScript.
  • URLs use kebab-case. Google's URL guidelines recommend hyphens rather than underscores to separate words, so /blog/order-total rather 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 userId is actually stored as userid, 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, not UUID, and HttpClient, not HTTPClient.
  • .NET capitalizes two-letter acronyms fully (IOStream) and treats longer ones as words (HtmlParser).
  • JavaScript has both in its own standard library: XMLHttpRequest next to encodeURIComponent and innerHTML.

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. XMLHttpRequest is XML + Http + Request. Splitting before every capital letter gives X M L Http Request.
  • Numbers inside words. base64Encode and sha256Hash should become base64_encode and sha256_hash, not base_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 livesUse
JavaScript, TypeScript, Java variables and functionscamelCase
Classes, types, React componentsPascalCase
Python, Ruby, Rust variables and functionssnake_case
Constants and environment variablesCONSTANT_CASE
Database tables and columnssnake_case
URLs, CSS classes, file names, data-* attributeskebab-case
JSON fieldscamelCase 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.

Try the tool