DEV Community

pulkitgovrani
pulkitgovrani Subscriber

Posted on Originally published at ilovekit.app

camelCase, snake_case, kebab-case, PascalCase: Naming Conventions Explained

Programmers use several naming styles because names can't contain spaces. Each language and context has its own convention, and following it makes code easier to read and less likely to clash with tools and linters.

The styles

camelCase           userAccountId
PascalCase          UserAccountId
snake_case          user_account_id
SCREAMING_SNAKE     USER_ACCOUNT_ID
kebab-case          user-account-id
Train-Case          User-Account-Id
lowercase           useraccountid
Enter fullscreen mode Exit fullscreen mode

Where each is used

  • camelCase: variables and functions in JavaScript, TypeScript, Java, and Swift.
  • PascalCase: class names, React components, and types in many languages; also C# methods.
  • snake_case: variables and functions in Python, Ruby, and Rust; also database column names.
  • SCREAMING_SNAKE_CASE: constants and environment variables (MAX_RETRIES, DATABASE_URL).
  • kebab-case: CSS class names, HTML attributes, file names, and URLs, since hyphens are readable in links and search engines treat them as word separators.

Title case vs sentence case

For prose rather than code, sentence case capitalizes only the first word and proper nouns, while title case capitalizes the main words. Many style guides for interfaces prefer sentence case because it reads more naturally.

Converting between styles

  1. Split the name into words on spaces, underscores, hyphens, and capital-letter boundaries.
  2. Lowercase the words, then rejoin them in the target style.
  3. Watch acronyms: XMLHttpRequest and userID may not split cleanly.
  4. Rename in your editor with a refactor tool rather than find and replace, so references update safely.

Practical tips

  • Follow the style guide of the language or project instead of choosing your own.
  • Use descriptive names: userAccountId beats uai.
  • Keep API field names consistent; when JSON uses snake_case and your code uses camelCase, convert at the boundary in one place.
  • In URLs, prefer lowercase kebab-case slugs.

Bulk conversions

For lists of names or headings, a case converter that runs locally converts hundreds of lines at once without uploading them.

Frequently asked questions

What is the difference between camelCase and PascalCase?

camelCase starts with a lowercase letter (userName), PascalCase starts with an uppercase letter (UserName).

Which case should I use for URLs?

Lowercase kebab-case, such as my-blog-post, which is readable and search-engine friendly.

What is snake_case used for?

Python and Ruby variable names, and database column names.

What is SCREAMING_SNAKE_CASE?

All uppercase words separated by underscores, used for constants and environment variables.

Try it: Case Converter — free, runs in your browser, nothing is uploaded.

Originally published at ilovekit.app.

Top comments (0)