Text Case Conversion: camelCase, snake_case, kebab-case and More
Naming conventions are one of the most important yet overlooked aspects of writing clean code. The way you name variables, functions, classes and files affects readability, consistency and collaboration across a project. Different programming languages, frameworks and ecosystems have adopted specific text case formats as their standards. Understanding these conventions and knowing how to convert between them is an essential skill for every developer.
Why Naming Conventions Matter
Consistent naming conventions make code easier to read and understand at a glance. When every developer on a team follows the same conventions, new contributors can navigate the codebase without guessing what format to use. Linters and automated tools rely on consistent naming to enforce code quality rules. Beyond readability, naming conventions also carry semantic meaning. For example, in JavaScript a name written in SCREAMING_SNAKE_CASE immediately signals a constant, while PascalCase indicates a class or component.
- Readability. Properly cased names are easier to scan and parse mentally, especially in large files with hundreds of identifiers.
- Consistency. A unified naming style across a codebase reduces cognitive load and prevents naming conflicts.
- Language conventions. Most languages have community-agreed naming standards. Following them makes your code feel idiomatic.
- Team standards. Style guides and linters enforce naming rules, catching inconsistencies before they reach code review.
Common Text Case Formats
Here are the most widely used case formats in programming, along with examples and where you will typically encounter each one.
camelCase
The first word is lowercase, and every subsequent word starts with an uppercase letter. No separators are used. This is the default convention for variables and function names in JavaScript, TypeScript, Java and Swift.
getUserName
totalItemCount
isAuthenticated
PascalCase
Every word starts with an uppercase letter, including the first one. Also known as UpperCamelCase. This is the standard for class names in most languages, React component names and C# methods and properties.
UserProfile
HttpRequestHandler
NavigationBar
snake_case
All words are lowercase, separated by underscores. This is the dominant convention in Python, Ruby, Rust and database column names. It is also commonly used in file naming for many backend frameworks.
user_name
total_item_count
is_authenticated
kebab-case
All words are lowercase, separated by hyphens. This format is used extensively in CSS class names, URL slugs, HTML attributes and CLI flags. It is also the convention for npm package names and file names in Angular projects.
user-profile
nav-bar-item
is-authenticated
SCREAMING_SNAKE_CASE (CONSTANT_CASE)
All words are uppercase, separated by underscores. This is universally used for constants, environment variables and configuration keys across nearly all programming languages.
MAX_RETRY_COUNT
DATABASE_URL
API_SECRET_KEY
dot.case
All words are lowercase, separated by dots. You will see this in Java package names, configuration keys in YAML and TOML files, and object property paths.
com.example.app
server.port
database.connection.pool.size
Title Case
Each word starts with an uppercase letter, and words are separated by spaces. This is used for headings, UI labels, button text and document titles. It is not used for code identifiers since spaces are not valid in variable names.
User Profile Settings
Create New Account
Save And Continue
Language Conventions
Different programming languages and ecosystems have established preferences for which case formats to use. Here is a quick reference.
JavaScript / TypeScript → camelCase for variables/functions, PascalCase for classes/components
Python → snake_case for variables/functions, PascalCase for classes
Ruby → snake_case for variables/methods, PascalCase for classes
Java → camelCase for variables/methods, PascalCase for classes
C# → PascalCase for methods/properties, camelCase for local variables
Go → camelCase for private, PascalCase for exported identifiers
Rust → snake_case for variables/functions, PascalCase for types/traits
CSS → kebab-case for class names and properties
SQL → snake_case for tables and columns, UPPER CASE for keywords
How Case Conversion Works
Converting between case formats follows a consistent two-step process. First, the input string is split into individual words. Then, the words are joined back together using the target format's rules.
The tricky part is the splitting step. A case converter needs to detect word boundaries by looking for several types of separators.
- Uppercase letters. In camelCase and PascalCase, an uppercase letter signals the start of a new word (
getUserNamebecomesget,User,Name). - Underscores. In snake_case and CONSTANT_CASE, underscores separate words.
- Hyphens. In kebab-case, hyphens separate words.
- Spaces. In Title Case and sentence case, spaces separate words.
- Dots. In dot.case, periods separate words.
Converting Between Cases in JavaScript
Here is a practical example showing how to split a string into words and convert it to different case formats in JavaScript.
// Split any cased string into words
function splitWords(str) {
return str
.replace(/([a-z])([A-Z])/g, "$1 $2")
.replace(/[_\-\.]+/g, " ")
.trim()
.toLowerCase()
.split(/\s+/);
}
// Convert to different formats
const words = splitWords("getUserName");
// ["get", "user", "name"]
// camelCase
words.map((w, i) =>
i === 0 ? w : w[0].toUpperCase() + w.slice(1)
).join("");
// "getUserName"
// snake_case
words.join("_");
// "get_user_name"
// kebab-case
words.join("-");
// "get-user-name"
// CONSTANT_CASE
words.map(w => w.toUpperCase()).join("_");
// "GET_USER_NAME"
Converting Between Cases in Python
Python's re module makes it straightforward to implement case conversion.
import re
def split_words(s):
s = re.sub(r"([a-z])([A-Z])", r"\1 \2", s)
return re.split(r"[_\-\.\s]+", s.lower())
words = split_words("getUserName")
# ["get", "user", "name"]
# snake_case
"_".join(words)
# "get_user_name"
# camelCase
words[0] + "".join(w.capitalize() for w in words[1:])
# "getUserName"
# PascalCase
"".join(w.capitalize() for w in words)
# "GetUserName"
# CONSTANT_CASE
"_".join(w.upper() for w in words)
# "GET_USER_NAME"
Common Pitfalls
Case conversion seems simple on the surface, but several edge cases can trip you up. Being aware of these will help you avoid subtle bugs.
- Acronyms and abbreviations. How should
XMLParserbe converted? Some tools producexml_parser, while others producex_m_l_parser. The correct approach splits on transitions between consecutive uppercase letters and lowercase letters, soXMLParserbecomesxml_parser. Some style guides preferXmlParseroverXMLParserto avoid this ambiguity entirely. - Single-letter words. Strings like
getAValuecan be ambiguous. Is the "A" a separate word or part of the next word? Most converters treat each uppercase letter as the start of a new word, resulting inget_a_value. - Numbers in identifiers. Names like
section2Titleorh2Tagrequire special handling. Shouldsection2Titlebecomesection_2_titleorsection2_title? The answer depends on your specific rules for number boundaries. - Leading and trailing separators. Input strings like
_private_var_or--flag-namehave separators at the edges. A good converter strips these before splitting to avoid empty words in the output. - Mixed formats. Sometimes input already mixes conventions, like
my_camelCase_string. A robust converter handles these gracefully by splitting on all possible word boundaries simultaneously.
Convert text between any case format instantly
Paste your text and convert between camelCase, snake_case, kebab-case, PascalCase, CONSTANT_CASE and more. All processing happens in your browser. No data is sent to any server.
Open Case Converter