elefcode
← All guides

Dev Basics · 4 min read

camelCase, snake_case, kebab-case: Naming Conventions Explained

Spaces are not allowed in identifiers, so programmers invented ways to join words. Which one you use is mostly decided by the language or context you are in — and mixing them is the quickest way to make code look foreign.

Try it yourself with the related tool.

Convert text case →

Advertisement

The main styles

camelCase starts lowercase and capitalises each new word. PascalCase capitalises every word. snake_case joins lowercase words with underscores, and SCREAMING_SNAKE_CASE uses uppercase. kebab-case joins lowercase words with hyphens. Title Case and Sentence case are for human-facing text.

Where each one belongs

JavaScript and Java use camelCase for variables and functions and PascalCase for classes and React components. Python and Ruby use snake_case for functions and variables. Constants and environment variables are usually SCREAMING_SNAKE_CASE. URLs, CSS class names, and file names favour kebab-case. Database columns are most often snake_case.

The acronym problem

Is it userID or userId, HTTPServer or HttpServer? Most modern style guides treat acronyms as words — userId, HttpServer — because converters can then split and rejoin names reliably. XMLHTTPRequest cannot be converted to snake_case unambiguously; XmlHttpRequest can.

Converting at the boundary

When a snake_case API meets camelCase front-end code, convert once at the boundary — in the API client — rather than mixing both styles through the codebase. Many serializers and ORMs can do this automatically.

Related guides