camelCase, snake_case or kebab-case? Naming Conventions
By Marcelo Torres · Published
Programmers can't use spaces in names, so every language has settled on a way to join words. Using the right one makes code easier to read and avoids surprises in URLs and APIs. Here's a practical reference.
The main styles
- camelCase: first word lowercase, the rest capitalized (userName).
- PascalCase: every word capitalized (UserName).
- snake_case: lowercase words joined by underscores (user_name).
- kebab-case: lowercase words joined by hyphens (user-name).
- CONSTANT_CASE: uppercase words joined by underscores (USER_NAME).
The Text Case Converter turns any phrase, or a list of names, into all of these at once.
By programming language
- JavaScript and TypeScript: camelCase for variables and functions, PascalCase for classes and React components, CONSTANT_CASE for fixed values by convention.
- Python: snake_case for variables and functions, PascalCase for classes and CONSTANT_CASE for constants, as recommended by the PEP 8 style guide.
- Java and Kotlin: camelCase for methods and variables, PascalCase for classes.
- C#: PascalCase for methods, properties and classes; camelCase for local variables and parameters.
- Go: camelCase or PascalCase, where the first letter matters: names starting with a capital letter are exported from the package.
- Ruby: snake_case for methods and variables, PascalCase for classes and modules.
When in doubt, follow the existing code base or the language's official style guide: consistency matters more than any individual preference.
Outside the code
- URLs: kebab-case. Hyphens are easy to read, and Google's own guidance recommends hyphens rather than underscores to separate words in URLs.
- CSS classes and HTML attributes: kebab-case (main-header, data-user-id).
- Environment variables: CONSTANT_CASE (DATABASE_URL).
- Database tables and columns: snake_case is the most common convention, because many databases fold unquoted names to one case.
- File names: kebab-case or snake_case avoid problems between operating systems that treat capital letters differently.
JSON and APIs
JSON doesn't impose a style for keys. APIs written mainly for JavaScript often use camelCase ("userName"), while many others use snake_case ("user_name"). Pick one style for the whole API and document it. Mixing both in the same response is a common source of bugs, which is easy to spot when you format the response with the JSON Formatter.
Accents and special characters
Most identifiers should use plain ASCII letters and digits. Some languages accept accented letters, but tools, databases and URLs often don't. That's why the converter turns configuración into configuracion in the programming styles while keeping accents in the text styles.