camelCase, snake_case or kebab-case? How to Pick the Right One
A plain guide to the three naming styles used in code, URLs and data. See where each fits, what breaks when styles are mixed and how to convert names safely.
Published November 11, 2026 · By Sudip Bhowmick
The same phrase can become userName, user_name or user-name. These styles are easy to read once you know them, but choosing the wrong one can break a variable, URL or API field. The best choice depends on where the name will be used and the conventions already followed by that project.
The Three Formats at a Glance
camelCase joins words and capitalizes each word after the first: userName. snake_case joins words with underscores and usually uses lowercase: user_name. kebab-case joins words with hyphens: user-name. All three remove spaces, but they signal word boundaries differently.
PascalCase is a related style that capitalizes the first word too, as in UserName. It is common for class and component names in many languages, but it is not interchangeable with camelCase in every codebase.
Use the Style Your Language or Framework Expects
JavaScript and TypeScript commonly use camelCase for variables and functions, and PascalCase for classes and React components. Python code usually uses snake_case for functions and variables. Existing project rules should guide you when conventions differ between teams or libraries.
A name that looks tidy can still be invalid in a specific context. Some languages reserve underscores or interpret capitalization specially. Follow the linter and framework rules before renaming public code.
Use Hyphens for Readable URLs
Lowercase words separated by hyphens are a common choice for page slugs because they are easy to scan and type. For example, a guide to image resizing could use image-resizing-guide. Avoid changing a published URL casually: links may already point to it, so use a redirect if a rename is necessary.
Hyphens are not valid in many programming identifiers, so a URL slug should not be copied directly into a variable name without conversion.
Keep JSON and API Names Stable
JSON allows many key spellings, including all three styles. The important part is matching the API contract. If a service returns user_id, changing it to userId in a request can make the field disappear from the server's perspective, even though both names are readable to a person.
When transforming data between systems, document the mapping and test a real example. Renaming keys is a data change, so update every consumer rather than changing only the output you happen to see.
Convert Names Without Losing Acronyms
Automatic converters need to guess where words begin. An acronym such as APIResponse might become apiresponse or api-response depending on the input and rules. Review names containing abbreviations, numbers or existing separators after conversion.
For a quick batch cleanup, use the Camel Case Converter, Snake Case Converter or Kebab Case Converter. Convert a copy first when the names feed a build, database or public API.
A Simple Choice Rule
Let the surrounding system decide first. Use the team's established style for code, the exact documented format for API fields and a readable lowercase hyphenated slug for most new page URLs. Consistency within one project matters more than a personal preference for one separator.
Conclusion
camelCase, snake_case and kebab-case solve the same readability problem in different settings. Match the language or API convention, keep URL slugs separate from code identifiers, and review acronyms after automatic conversion. That avoids cosmetic cleanup turning into a broken integration.
Free Tool
Convert text to camelCase