camelCase vs snake_case vs kebab-case: When to Use Each
What are naming conventions?
Naming conventions are rules for formatting multi-word identifiers in code. Because most programming languages do not allow spaces in variable names, function names, or class names, developers use naming conventions to combine multiple words into a single readable identifier.
For example, the phrase "user first name" cannot be used as a variable name with spaces. Instead, developers write it as userFirstName (camelCase), user_first_name (snake_case), or user-first-name (kebab-case) depending on the language and context.
Furthermore, following consistent naming conventions within a codebase makes code significantly more readable and maintainable. As a result, most programming languages and frameworks have established conventions that developers are expected to follow.
There is no universally "correct" naming convention — the right choice depends entirely on the programming language, framework, and context you are working in. The most important thing is consistency within a project.
camelCase — the JavaScript standard
camelCase joins words without spaces, capitalising every word except the first. The name comes from the "humps" created by the capital letters in the middle of the word — like a camel's back.
When to use camelCase
- JavaScript variables —
const userName = "John" - JavaScript functions —
function getUserData() - JSON object keys —
{"firstName": "John"} - React component props —
<Button onClick={handleClick}> - Java and Swift variables — standard in both languages
PascalCase — for classes and components
PascalCase is similar to camelCase but capitalises every word including the first. It is sometimes called "UpperCamelCase" for this reason.
When to use PascalCase
- Class names —
class UserProfile {}in JavaScript, Python, Java - React components —
function NavBar(),function UserCard() - TypeScript interfaces and types —
interface UserData {} - C# variables and methods — PascalCase is the standard for all C# identifiers
snake_case — the Python standard
snake_case uses underscores to separate words, with all letters in lowercase. The name comes from the flat, horizontal appearance — like a snake lying on the ground.
When to use snake_case
- Python variables and functions —
user_name = "John",def get_user_data(): - Database column names —
first_name,created_at,user_id - Ruby methods and variables — snake_case is the Ruby standard
- File names —
my_script.py,user_profile.rb - PostgreSQL and MySQL column names — databases conventionally use snake_case
Python's official style guide (PEP 8) specifies snake_case for all variable names, function names, and module names. Following this convention makes your Python code consistent with the broader Python ecosystem and easier for other developers to read.
kebab-case — the CSS and URL standard
kebab-case uses hyphens to separate words, with all letters in lowercase. The name comes from the appearance of words "skewered" together by hyphens — like food on a kebab skewer.
When to use kebab-case
- CSS class names —
.nav-bar,.user-profile,.hero-section - HTML attributes —
data-user-id,aria-label - URL slugs —
/how-to-use-case-converter,/best-image-format - CLI commands and flags —
--output-file,--dry-run - Vue.js component names —
<user-profile>,<nav-bar> - HTTP headers —
Content-Type,Accept-Encoding
CONSTANT_CASE — for fixed values
CONSTANT_CASE uses all uppercase letters with underscores between words. It is used specifically for constants — values that never change during program execution.
Quick reference — camelCase vs snake_case vs kebab-case
Here is a practical summary of when to use camelCase vs snake_case vs kebab-case in different contexts:
- JavaScript variables and functions → camelCase
- JavaScript/TypeScript classes and React components → PascalCase
- Python variables, functions, and files → snake_case
- Database column names → snake_case
- CSS class names and HTML attributes → kebab-case
- URL slugs and page paths → kebab-case
- Constants and environment variables → CONSTANT_CASE
- JSON keys in REST APIs → camelCase (most common) or snake_case
When working with a team or an existing codebase, always follow the existing convention — even if it differs from what you personally prefer. Consistency within a project is more important than following any particular convention.
How to convert between cases instantly
Manually converting text between camelCase, snake_case, and kebab-case is tedious and error-prone, especially for long identifiers. Our free case converter handles all conversions instantly — paste your text, click the target case, and copy the result.
In addition to camelCase, snake_case, and kebab-case, our tool also supports PascalCase, CONSTANT_CASE, dot.case, UPPERCASE, lowercase, Title Case, Sentence case, and two creative case formats. As a result, you can convert between any naming convention in one click.
Convert text case instantly — free
camelCase, snake_case, kebab-case and 9 more formats
Convert case →Frequently asked questions
Is camelCase or snake_case more readable?
Research on code readability suggests that snake_case is marginally more readable for most people because the underscore character creates a clear visual separation between words. However, camelCase is faster to type and is the dominant convention in JavaScript and many other popular languages. In practice, readability depends more on familiarity — developers tend to find the convention they use most to be the most readable.
Can I use camelCase in Python?
Python allows camelCase syntactically, but it is strongly discouraged. Python's official style guide PEP 8 specifies snake_case for variables and functions. Furthermore, the Python standard library and most Python packages use snake_case consistently. As a result, using camelCase in Python makes your code look out of place and harder for other Python developers to read.
Why can't I use kebab-case in JavaScript?
kebab-case cannot be used for JavaScript variable or function names because the hyphen character is interpreted as the minus operator. For example, user-name would be parsed as user minus name, which is a subtraction expression rather than a variable name. This is why JavaScript uses camelCase instead.
What naming convention do REST APIs use?
REST APIs most commonly use either camelCase or snake_case for JSON keys, depending on the team's preference and the primary programming language of the backend. JavaScript-based APIs tend to use camelCase, while Python and Ruby APIs often use snake_case. Furthermore, URL paths in REST APIs almost always use kebab-case slugs.
Related articles
Last updated: April 14, 2026 · View all articles · Browse all tools