Names in code, file names and web addresses cannot contain spaces. Over time, several conventions have grown up for joining words together. They are all readable, but each community has its own favourite, and mixing them causes bugs and untidy projects.

The main styles

StyleExampleCommon use
camelCaseuserAccountIdVariables and functions in JavaScript, Java, Swift
PascalCaseUserAccountIdClasses and components in many languages
snake_caseuser_account_idPython, Ruby, database columns, Rust functions
kebab-caseuser-account-idURLs, CSS class names, file names
CONSTANT_CASEUSER_ACCOUNT_IDConstants and environment variables
dot.caseuser.account.idConfig keys, package names

Why conventions matter

A consistent style makes names predictable. If every function in a project is camelCase, you can guess the name of the next one. It also avoids errors, since many systems are case-sensitive: userId and userid are different names to a program, and file names on a Linux server are case-sensitive while those on Windows are not.

Which should I use for web addresses?

Use lower-case kebab-case in URLs. Google's guidance recommends hyphens to separate words in a URL, because it treats a hyphen as a word separator, while an underscore is generally not read as one. So /blog/strong-password-tips is a better address than /blog/strong_password_tips. Lower case also avoids duplicate pages when a server treats upper and lower case differently.

Title case and sentence case

For headings written for people, there are two common styles. Title case capitalises the main words, and sentence case capitalises only the first word and proper names. Rules for title case differ between style guides: for example, some capitalise every word of four letters or more, and others leave short words such as "of", "and" and "the" in lower case. If your publisher has a style guide, follow it, and treat an automatic converter as a first draft.

Pitfalls when converting

  • Acronyms. Is it userID or userId? Pick one rule, such as treating acronyms as ordinary words, and stick to it.
  • Names and proper nouns. An automatic converter cannot know that "NASA" or "McDonald" has a special form.
  • Numbers. address2 and address_2 may be handled differently.
  • Non-English letters. Accented letters are kept by modern tools, but not every programming language allows them in names.

Try it

Paste your text and click a style. Programming styles split joined words first, so userID becomes user_id. Use "Use result as input" to chain conversions. To count what you have written, try the Word Counter.