Developer
camelCase vs snake_case vs kebab-case: When to Use Each
Published 6 min read
On this page
- What do the naming styles look like side by side?
- Why do programmers join words in different ways?
- When should you use camelCase?
- When is snake_case the better choice?
- Why can't you use kebab-case for variable names?
- Which style should JSON keys use?
- How do you convert a list of names between styles?
- A short checklist before you pick
- Quick answers
camelCase, snake_case and kebab-case are three ways to join words without spaces. camelCase capitalises each word after the first (userFirstName), snake_case links lowercase words with underscores (user_first_name), and kebab-case links them with hyphens (user-first-name). Use the one your language or platform expects: camelCase in JavaScript code, snake_case in Python, and kebab-case in CSS, URLs and file names.
The rest of this guide shows the same phrase in every style, explains why each convention lives where it does, and gives you a quick way to convert a whole list of names.
What do the naming styles look like side by side?
Here is the phrase "user first name" converted by our text case converter, which produces every style from one input:
| Style | Result | Where you usually see it |
|---|---|---|
| camelCase | userFirstName | JavaScript variables and functions |
| PascalCase | UserFirstName | Class, type and component names |
| snake_case | user_first_name | Python names, database columns |
| CONSTANT_CASE | USER_FIRST_NAME | Values that never change |
| kebab-case | user-first-name | CSS, URLs, file names |
| dot.case | user.first.name | Some configuration keys |
Each one is a naming convention: a shared habit, not a rule enforced by the computer. The point of a convention is that anyone reading the code can guess a name without looking it up.
Why do programmers join words in different ways?
An identifier, such as the name of a variable, a function or a file, usually cannot contain spaces. "user first name" would be read as three separate things. So the words have to be joined, and a separator or a capital letter has to show where one word ends and the next begins.
Different communities settled on different answers. Capital letters keep names short. Underscores look most like spaces, so long names stay readable. Hyphens read naturally to people, which is why they suit web addresses, but most programming languages treat a hyphen as a minus sign.
When should you use camelCase?
camelCase starts with a small letter and puts a capital at the start of each later word, so the capitals form the "humps". It is the common habit for variables and functions in JavaScript and TypeScript, and many other languages use it too.
Its close relative, PascalCase, also capitalises the first word. JavaScript and many other languages use PascalCase for classes, and front-end frameworks commonly use it for component names. If you see UserProfile and userProfile in the same project, one is probably a type and the other a value of that type.
When is snake_case the better choice?
snake_case writes every word in lowercase and joins them with underscores. Because the underscore looks like a gap, long names such as max_retry_count stay easy to scan.
It is the standard in Python. PEP 8, the official Python style guide, asks for lowercase words separated by underscores for functions and variables, CapWords (PascalCase) for classes, and capitals with underscores for constants. snake_case is also a common choice for database tables and columns, partly because some databases treat unquoted names as case-insensitive, which makes capital letters unreliable as word breaks.
Why can't you use kebab-case for variable names?
In most programming languages, user-first-name would be read as "user minus first minus name". The hyphen is an operator, so kebab-case simply does not work for variables in those languages.
On the web, though, kebab-case is everywhere. CSS property names such as background-color use it, many class names follow it, and it is a popular style for URL slugs and file names. Search engines and people both read a hyphen as a word break, so my-blog-post is easier to read than myblogpost.
Which style should JSON keys use?
JSON itself has no preference. A key can be firstName, first_name or even first-name, as long as it is a string in double quotes. The right choice is whatever the system that produces or reads the data already uses, and then consistency matters more than the style itself.
A file that mixes styles is harder to work with. Paste it into the JSON formatter to format it and sort the keys from A to Z, which makes mismatched names easy to spot. If the file will not parse at all, start with fixing common JSON mistakes.
How do you convert a list of names between styles?
Retyping names is slow, and it is easy to slip a letter. A faster way:
- Paste the names into the text case converter, one per line.
- Choose the style you need, for example snake_case.
- Copy the converted text.
The tool splits words at spaces, hyphens, underscores and camelCase humps, and it converts each line on its own. So parseHTTPResponse becomes parse_http_response in snake_case, parseHttpResponse in camelCase and parse-http-response in kebab-case. Notice what happened to the acronym: HTTP became http or Http. Decide early whether your project writes acronyms in full capitals, and keep to it.
A short checklist before you pick
- Follow the language first. Python code reads best in snake_case, JavaScript code in camelCase. Fighting the ecosystem makes code harder for everyone else.
- Follow the team second. An existing project's style wins over personal taste.
- Use kebab-case only where hyphens are safe: CSS, HTML attributes, URLs and file names.
- Rename carefully. Changing a field name in one place can break code, queries or data elsewhere.
For capital letters in ordinary writing rather than code, see title case and sentence case for normal writing.
Quick answers
What is the difference between camelCase and snake_case?
camelCase marks word breaks with capital letters (userFirstName). snake_case keeps everything lowercase and uses underscores (user_first_name). Neither is better; each is the norm in different languages.
Is kebab-case the same as hyphen case?
Yes. Kebab-case, hyphen case and dash case are names for the same style: lowercase words joined with hyphens.
What is PascalCase used for?
PascalCase capitalises every word, including the first, as in UserFirstName. It is widely used for class names, types and UI components.
What is CONSTANT_CASE?
It is snake_case in capital letters, such as MAX_RETRY_COUNT. Many languages use it for constants, values that do not change while a program runs.
Can I convert camelCase to snake_case online?
Yes. Paste the names into a case converter and choose snake_case. It detects the capital letters as word breaks and rewrites each line.
Related tools
Related guides
- SEO
Meta Title Length Checker: How Long Should a Title Be?
Use a meta title length checker the right way: how long a title tag should be, why Google may cut it off, and how to test and trim yours with a free tool.
- Writing
Title Case vs Sentence Case: Which to Use for Headlines
Title case vs sentence case explained with real headline examples, when to use each, why style guides differ, and how to convert a headline in seconds.