All posts
May 18, 20264 min read

camelCase, snake_case, kebab-case, PascalCase: which goes where

The same three words, "user account id", can be written half a dozen ways depending on where it lives: userAccountId, user_account_id, user-account-id, UserAccountId, USER_ACCOUNT_ID. None is more correct than the others. Each ecosystem picked one and stuck with it, and the friction comes when data crosses a boundary. Convert any string between all of them with the Case Converter.

The conventions and where they live

  • camelCase — first word lowercase, each later word capitalised: userAccountId. The default for variables and functions in JavaScript, TypeScript, and Java.
  • PascalCase (UpperCamelCase) — every word capitalised: UserAccountId. Used for classes, types, components, and React component files almost everywhere.
  • snake_case — lowercase words joined by underscores: user_account_id. The norm in Python, Ruby, Rust, SQL columns, and a great many JSON APIs.
  • SCREAMING_SNAKE_CASE — uppercase snake_case: USER_ACCOUNT_ID. Reserved for constants and environment variables.
  • kebab-case — lowercase words joined by hyphens: user-account-id. Used in URLs, CSS class names, HTML attributes, npm package names, and filenames, because these contexts dislike underscores or are case-insensitive.

Why the boundaries cause bugs

The pain shows up where two conventions meet. A Python or Rails backend speaks snake_case; a JavaScript frontend speaks camelCase. The JSON over the wire usually follows one of them, and one side has to translate. Pick a single rule, for example "the API is snake_case, the client maps to camelCase at the edge", and apply it consistently. Ad hoc conversion scattered through the codebase is where keys silently fail to match and values come back undefined.

Converting safely

Case conversion is not just changing capitalisation; it is re-splitting words. Going from kebab-case to camelCase means finding word boundaries at the hyphens, then recapitalising. Acronyms are the trap: is userID two words or does the converter see user and i and d? Tools differ, so check the output on names with acronyms and numbers rather than assuming. The Case Converter shows every form at once so you can confirm the split is right.

The slug special case

A URL slug is kebab-case with extra cleaning: lowercase everything, replace spaces and punctuation with hyphens, strip accents, and collapse repeats. "My First Post" becomes my-first-post. This is the same family of transformation, applied to make a title safe and readable in a URL. When you need that, the Case Converter handles slugify alongside the programming cases, and URL encoding explained covers what to do with the characters a slug cannot represent.