camelCase, snake_case and kebab-case: Which Naming Style to Use
When you name a variable with more than one word, you cannot use spaces. Programmers solved this in a few different ways, and each style has its own home.
The common styles
- camelCase:
userFirstName. The first word is small, later words start with a capital. Used in JavaScript, Java and Swift variables. - PascalCase:
UserFirstName. Every word starts with a capital. Used for classes and components. - snake_case:
user_first_name. Words joined by underscores. Python, Ruby and database columns love it. - kebab-case:
user-first-name. Words joined by dashes. Common in URLs and CSS. - CONSTANT_CASE:
MAX_RETRY_COUNT. All capitals for values that never change.
Why it matters
Using the style your language expects makes code easier for others to read. It is also a matter of correctness in some places. A CSS property written as backgroundColor will not work, it must be background-color. Meanwhile in JavaScript, background-color is not a valid variable name because the dash looks like a minus sign.
When you have to convert
You will need to convert names when sending data between systems. A Python backend may return first_name, while your JavaScript front end wants firstName. Or you may be turning a page title into a URL slug, from "My First Post" into my-first-post.
Watch out for acronyms
How should "HTTP response code" look in camelCase? Some write httpResponseCode, others HTTPResponseCode. Pick one rule and keep it across the project. Our converter treats the acronym as one word, so you get httpResponseCode.
Tips for good names
- Prefer clear names over short ones.
- Do not mix styles inside one project.
- Follow the guide for your language or team.
Convert in one click
Try the Naming Case tool on our Developer Converters page. Type a name or a phrase, even one that already has underscores or dashes, and you see all five styles at once, ready to copy.
Frequently asked questions
Which naming style should I use in JavaScript?
camelCase for variables and functions, PascalCase for classes and React components, and UPPER_SNAKE_CASE for constants. These are the conventions most JavaScript projects and style guides follow.
Which style does Python use?
snake_case for variables, functions and file names, PascalCase for classes, and UPPER_SNAKE_CASE for constants, as described in the PEP 8 style guide.
Why are URLs written in kebab-case?
Search engines treat hyphens as word separators, so "convert-csv-to-json" reads as four words. Underscores and run-together words are harder to read and may be treated as one long word.
What is the best style for database columns?
snake_case is the most common for SQL columns and tables, such as order_date. Many databases are case-insensitive, which makes camelCase names unreliable.
Open the free Developer Converters. It runs in your browser, so nothing is uploaded.