Text case converter

Convert any text between the six naming conventions developers use daily — camelCase, PascalCase, snake_case, kebab-case, Title Case and UPPERCASE.

Text Case Converter

Convert any text between the six cases developers juggle daily — camelCase for JavaScript, kebab-case for CSS and URLs, snake_case for databases, and more.

Mixed input is fine — existing camelCase, hyphens, underscores and spaces are all understood and re-split into words first.

Converted

camelCase
PascalCase
snake_case
kebab-case
Title Case
UPPERCASE

How to use this tool

The conventions aren't arbitrary — each one exists because of a constraint in its environment.

camelCase dominates JavaScript because identifiers can't contain hyphens (a hyphen is the minus operator) and the language's own APIs use it. PascalCase distinguishes things that get instantiated or rendered — classes, and components in React, where an uppercase first letter is what tells JSX to treat a tag as a component rather than an HTML element.

kebab-case owns CSS and URLs. Both are case-insensitive contexts where hyphens read naturally, and Google explicitly treats hyphens as word separators in URLs while underscores join words together. snake_case rules databases and Python, largely because many SQL dialects fold unquoted identifiers to lowercase, making camelCase unreliable across systems.

The conversion is harder than it looks

Converting between cases means first splitting text into words — and the input rarely announces its own format. This converter handles the common cases: it splits on spaces, hyphens and underscores, and it detects camelCase boundaries by looking for a lowercase character followed by an uppercase one.

The edge cases that break naive converters are worth knowing if you write your own. Consecutive capitals (XMLHttpRequest, parseJSON) are genuinely ambiguous — is JSON one word or four letters? Numbers create similar problems: should address2 become address-2 or address2? There is no universally correct answer, only a convention your codebase applies consistently.

Where conversion actually comes up

The most frequent real-world case is crossing a boundary between systems. An API returns snake_case JSON and your JavaScript wants camelCase. A design token named in kebab-case needs a camelCase equivalent in a theme object. A database column becomes a form field name.

For one-off work a converter is faster than fiddling with a regex. For anything systematic, do the conversion in one place — a single mapping layer where API responses enter your app — rather than scattering ad-hoc renames through your codebase.

Consistency beats correctness

There is no objectively best convention, and arguing about it is one of programming's great time sinks. What genuinely costs teams time is inconsistency: when developers have to guess whether a helper is getUserId, get_user_id or GetUserID, every lookup becomes a search.

Pick a convention per layer, follow the ecosystem's default where one exists, write it down, and enforce it with a linter so it stops being a discussion. If you need to rename existing code, do it as its own commit — mixing renames into a feature change makes the diff unreviewable.

Developer Implementation Guide: Programmatic Case Conversion

Converting case in code is surprisingly difficult due to edge cases like consecutive capital letters (e.g., XMLHTTPRequest). Below is a robust JavaScript implementation for converting strings to camelCase.

Robust camelCase Function

This function handles spaces, underscores, and hyphens, safely converting them into camelCase.


function toCamelCase(str) {
  return str
    // Replace dashes and underscores with spaces
    .replace(/[-_]+/g, ' ')
    // Replace non-alphanumeric characters with spaces
    .replace(/[^\w\s]/gi, '')
    // Split into words, capitalize the first letter of each word (except the first)
    .replace(/\s+(.)/g, function(match, group1) {
      return group1.toUpperCase();
    })
    // Ensure the very first character is lowercase
    .replace(/^(.)/, function(match, group1) {
      return group1.toLowerCase();
    })
    // Remove remaining spaces
    .replace(/\s+/g, '');
}

console.log(toCamelCase("user_first_name")); // "userFirstName"
console.log(toCamelCase("hello-world")); // "helloWorld"
        

For large-scale structural changes (like converting entire database schemas or API responses), consider using dedicated libraries like lodash/camelCase which have been battle-tested against thousands of edge cases.

Frequently asked questions

What is the difference between camelCase and PascalCase?

Both join words with capitals, but camelCase starts lowercase (getUserName) and PascalCase starts uppercase (GetUserName). JavaScript uses camelCase for variables and functions, and PascalCase for classes and React components.

Should URLs use hyphens or underscores?

Hyphens. Google treats a hyphen as a word separator, so css-tricks reads as two words, while css_tricks is read as one. Google has recommended hyphens in URLs for well over a decade.

Why do databases use snake_case?

Many SQL dialects fold unquoted identifiers to lowercase, which makes camelCase unreliable across systems — userName can silently become username. snake_case survives that folding intact, so word boundaries stay readable.

How does the converter handle acronyms like XMLHttpRequest?

It splits on the boundary between a lowercase and an uppercase character, so runs of consecutive capitals stay grouped. Acronyms are genuinely ambiguous in case conversion — check the result when your input contains them.