Skip to content
universalCase Converter

Blog

camelCase, PascalCase and snake_case Compared

Naming styles look like a matter of taste, but each has a home: a language, a file system or a convention that everyone expects.

By the Universal Case Converter Team

Why programmers care about case

A variable name cannot contain a space in most programming languages, so a name made of several words needs another way to show where one word ends and the next begins. Programmers solved this with a few conventions: capital letters inside the name, underscores between the words or hyphens between the words. These conventions are the naming styles, and they are often called identifier cases.

The names of the styles come from their shapes. camelCase has humps, as the capital letters stand out like humps on a camel. snake_case lies flat on the ground like a snake. kebab-case has its words skewered on a stick of hyphens. None of these names are official. They are habits that became conventions, and a convention only works if a team applies it everywhere.

camelCase: lowercase start, capitals inside

In camelCase the first word is lowercase and each following word starts with a capital letter, with no separators: userName, totalPrice, getUserById. It is the usual style for variables and functions in JavaScript, Java and Swift, and for JSON keys in many web services. Many code style guides, such as Google's JavaScript style guide, ask for camelCase for methods and local variables.

A common edge case is an acronym. Should the name be parseXMLFile or parseXmlFile? Some guides treat an acronym like a normal word and write Xml, which keeps the word boundaries clear, while others keep the acronym in capitals. The important point is that a team picks one answer and checks it. A converter that splits names at lower-to-upper changes will also split XMLHttpRequest into XML and Http.

PascalCase: every word capitalized

PascalCase, also called UpperCamelCase, is like camelCase but the first word is capitalized too: UserAccount, HttpClient, InvoiceLine. It is the standard style for class names and type names in most object-oriented languages: Java, C#, Swift, TypeScript and Python use it for classes, and Rust uses it for types and traits. In C# and in the Go language, PascalCase is also used for public methods and exported names, so the case of the first letter has a meaning.

The name comes from the Pascal language, whose standard library used the style. In some contexts, such as the names of React components, PascalCase is required rather than recommended, because the build tools use the capital first letter to tell a component from an ordinary HTML tag.

snake_case: lowercase with underscores

snake_case writes every word in lowercase and joins them with underscores: user_name, total_price, get_user_by_id. The Python style guide PEP 8 asks for lowercase names with words separated by underscores for functions, variables and modules. Ruby and Rust use snake_case for methods, functions and variables too, and it is also the most common style for the column and table names of relational databases, partly because many databases fold unquoted names to one case.

Readability is the usual argument for snake_case. The underscore acts as a visible space, so long names can be read at a glance. The disadvantage is length: an underscore is an extra character, and it needs a modifier key on most keyboards, so some programmers find it slower to type than camelCase.

kebab-case, CONSTANT_CASE and dot.case

kebab-case uses lowercase words and hyphens: user-profile-card. Programming languages cannot use it for variable names, because the hyphen means subtraction, but it is the normal style for CSS class names, HTML attributes, file names and web addresses. The article on kebab-case and URL slugs explains why it is also the recommended style for URLs.

CONSTANT_CASE, also called SCREAMING_SNAKE_CASE, uses capital letters and underscores: MAX_RETRY_COUNT. It is the convention for constants in Python, Java, JavaScript and Rust, and for environment variables. dot.case, with lowercase words separated by dots, appears in configuration keys, such as the properties of Java applications, and in package names such as com.example.app.

Which one should you use?

The best choice is the one your language and your team already use. In a Python project, follow PEP 8 and use snake_case for functions and variables, PascalCase for classes and CONSTANT_CASE for constants. In a JavaScript project, use camelCase for variables and functions, PascalCase for classes and components and CONSTANT_CASE for constants. In CSS, use kebab-case. In a SQL database, snake_case is the common choice.

The mistakes to avoid are mixing styles in one file and changing styles at the boundary of two systems without a plan. A common example is a Python backend that sends snake_case keys to a JavaScript frontend that expects camelCase. Teams solve this with a conversion layer or with a clear rule that the API uses one style only.

Converting names quickly and safely

Renaming dozens of identifiers by hand is slow, and errors are easy to make. A converter helps when you have a list of phrases or names that must be turned into a different style: you paste one name per line, choose the target style and copy the result. The converter on this page splits each line at spaces, punctuation and lower-to-upper changes, and joins the words with the separator of the style you choose.

For source code, a converter helps with names, but it does not update the places where a name is used. In a real project, use the rename function of your editor, which changes the name and all its references together, and use a converter for lists, data columns, file names and configuration keys. Run your tests after the change.

Convert text to camelCase, snake_case or PascalCase with the free case converter.

Open the case converter