camelCase, snake_case, kebab-case: which naming style to use, and how to convert
Published
Open Case converterEach naming style is a convention tied to a language or a place: camelCase for JavaScript variables, PascalCase for class and type names, snake_case for Python and database columns, kebab-case for URLs, CSS classes and file names, CONSTANT_CASE for constants and environment variables. To switch a name or a whole list from one to another, paste it into the case converter and tap the style under Code.
The five code cases side by side
Starting from the words "user account id":
| Style | Result | Where it is the usual choice |
|---|---|---|
| camelCase | userAccountId |
Variables and functions in JavaScript, TypeScript, Java; JSON keys in many APIs |
| PascalCase | UserAccountId |
Class, type, interface and component names in most languages |
| snake_case | user_account_id |
Variables and functions in Python and Ruby; SQL table and column names |
| kebab-case | user-account-id |
URLs, CSS class names, file names, command-line flags |
| CONSTANT_CASE | USER_ACCOUNT_ID |
Constants, environment variables |
These are conventions, not rules of the languages themselves. A team's style guide or linter config is the final word for a given project.
Steps
- Open the case converter and paste the name, or a list with one name per line, into Your text.
- Under Code, tap the style you want: camelCase, PascalCase, snake_case, kebab-case or CONSTANT_CASE.
- Check the Result. A pasted list is joined into one name; see the note on lists below.
- Press Copy.
How the input is split into words
The code cases first break the text into words, then join them in the new style. A word boundary is any of these:
- a space, hyphen, underscore, dot, slash or other punctuation:
user-account_idgivesuser,account,id; - a change from lower to upper case:
userAccountgivesuser,Account; - an acronym followed by a capitalised word:
XMLHttpRequestgivesXML,Http,Request; - a change between letters and digits:
maxValue2givesmax,Value,2.
So any style converts to any other. XMLHttpRequest in snake_case is xml_http_request, and in kebab-case xml-http-request.
Acronyms are not kept in capitals inside camelCase or PascalCase: HTTP response code becomes httpResponseCode and HttpResponseCode. If your project writes HTTPResponseCode, fix those letters by hand.
Converting a list of names
The code cases treat everything you paste as one name. Line breaks count as separators, so a pasted list of three column names comes out as one long joined name. Two ways to handle a list:
- Convert names one at a time when there are only a few.
- For a long list of plain words with spaces, such as spreadsheet headings ("Order total", "Ship date"), use the slug generator when the target is kebab-case or snake_case. It makes one slug per line, with Hyphen - or Under _ as the separator, and folds accents (é becomes e). It splits only on spaces and punctuation, so it does not split an existing camelCase name;
orderTotalstays one word.
Common conversions
| You have | You need | Tap |
|---|---|---|
A Python field created_at |
A JSON key in camelCase | camelCase gives createdAt |
| A heading "Order Summary Card" | A component name | PascalCase gives OrderSummaryCard |
A setting name apiBaseUrl |
An environment variable | CONSTANT_CASE gives API_BASE_URL |
A class name PrimaryButton |
A CSS class | kebab-case gives primary-button |
A column TotalAmountUSD |
A database column | snake_case gives total_amount_usd |
Questions
What is the difference between camelCase and PascalCase?
Only the first letter. camelCase starts lower case (userName), PascalCase starts upper case (UserName). PascalCase is sometimes called upper camel case.
Does it keep digits?
Yes. Digits become their own word, so item2Price becomes item_2_price in snake_case. Remove the extra separator by hand if your project writes item2_price.
What happens to accents and symbols?
Letters keep their accents in the code cases, and symbols act as separators and disappear. For names that must be plain a to z, the slug generator's a-z only setting folds accents to plain letters.
Is anything sent to a server?
No. The conversion runs in your browser, so it is fine for internal names and unreleased code.
Case converter
Change text between UPPER, lower, Title and more.
Open Case converterRelated tools
- Slug generator: Turn a title into a clean URL slug.
- Remove line breaks: Join lines from a PDF or email with a space, comma or your own text.