HSHimanshu Sharma
Free Tools

Naming styles explained: camelCase, snake_case, kebab-case and the Case Converter

Advertisement

Text comes in many shapes. A heading is written in title case, a sentence starts with a capital letter, a JavaScript variable is userName, a Python variable is user_name, a web address uses user-name, and a constant is USER_NAME. Converting between them by hand is tedious and invites typos, especially for long lists. The free Case Converter turns text into upper, lower, title, sentence, camel, Pascal, snake, kebab and constant case in one click. This guide explains each style, where it belongs and the pitfalls of converting automatically.

The styles at a glance

Take the phrase hello world again. Here is how each style writes it, as the tool produces it:

Style Result Typical use
lower case hello world again Email addresses, tags, plain text
UPPER CASE HELLO WORLD AGAIN Emphasis, acronyms, warning labels
Title Case Hello World Again Headings, book and article titles
Sentence case Hello world again Normal sentences, many modern headings
camelCase helloWorldAgain JavaScript and Java variables and functions
PascalCase HelloWorldAgain Classes and components in many languages
snake_case hello_world_again Python variables, database columns
kebab-case hello-world-again URLs, CSS class names, file names
CONSTANT_CASE HELLO_WORLD_AGAIN Constants and environment variables

Why programmers care

Programming languages do not allow spaces inside names, so words have to be joined somehow. Over time, communities agreed on conventions, and following them makes code easier for everyone to read.

camelCase. The first word is lower case and each following word starts with a capital letter, so the name looks like the humps of a camel. It is standard for variables and functions in JavaScript, Java and many other languages: firstName, calculateTotal.

PascalCase. Like camelCase, but the first word is capitalised too. It is used for classes, types and, in React and similar libraries, for components: UserProfile, ShoppingCart.

snake_case. Words are lower case and joined with underscores. It is the convention for variables and functions in Python, and for column and table names in many databases: order_date, customer_id. It is also readable in languages such as PHP and Ruby.

kebab-case. Words are lower case and joined with hyphens. It cannot be used as a variable name in most languages, since the hyphen reads as a minus sign, but it is ideal for web addresses and for CSS class names: main-navigation. Search engines treat hyphens in addresses as word separators, which is why clean URLs use them, whereas underscores are not treated the same way.

CONSTANT_CASE. Capital letters joined with underscores signal a value that does not change: MAX_UPLOAD_SIZE, API_URL. Environment variables use it too.

The most important rule is to follow the convention of the language and project you are in. A Python function named calculateTotal works, but it will look out of place to every Python developer who reads it.

Title case versus sentence case

These two matter for writers, not programmers.

Sentence case capitalises only the first word and proper names, the way you would write a normal sentence: How to learn Python in a month. It is easy to read and has become common in modern interfaces and on many news sites.

Title case capitalises the main words: How to Learn Python in a Month. Rules vary between style guides about small words such as a, of, to and in, which many guides leave lower case. A converter applies one simple rule, so read the result and correct any word that your style guide treats differently.

Pick one and use it consistently across a site. A mix of both in headings looks careless.

Using the Case Converter

  1. Open the Case Converter.
  2. Paste or type your text into the box.
  3. Choose the case you want: upper, lower, title, sentence, camel, Pascal, snake, kebab or constant.
  4. Copy the converted text from the result box.

Some practical uses:

  • Turn a column heading into a variable name. Order Total Amount becomes orderTotalAmount or order_total_amount.
  • Create a URL slug. Write the title, convert to kebab case and you have order-total-amount. Check that the result has no accented or special characters, and shorten it if it is long.
  • Fix text typed with caps lock on. Paste it, choose sentence case and repair the proper names.
  • Rename a list of fields when you move data between systems that use different conventions, such as a JavaScript front end and a database with snake_case columns.
  • Format headings for an article to your style guide's rule.

Limitations to be aware of

An automatic converter works on the characters you give it, so it cannot know your intent. Watch for these cases.

Acronyms. parse HTML response in camelCase may become parseHtmlResponse in one style guide and parseHTMLResponse in another. Both are in use. Choose one and apply it consistently in a project.

Proper names and brands. Title case may change iPhone to Iphone, or McDonald to Mcdonald. Correct these by hand.

Numbers. version 2 update becomes version2Update or version_2_update depending on the style, and conventions differ on whether the digit belongs to the word before or after it.

Accented and non-English letters. Check that characters such as é and ß are handled as you expect. Some languages have special rules for capitalisation. A well-known example is that the German letter ß has an upper-case form that is written SS in the usual conversion.

Already-joined words. Converting userName to snake case needs the tool to recognise where one word ends and the next begins. If it does not, paste the words with spaces first.

Where this shows up in real work

When you design an API, the names in the JSON data are part of the contract. Pick camelCase or snake_case and use it everywhere. The JSON Formatter is useful for checking the result. In databases, column names in snake_case avoid problems with systems that treat upper and lower case differently; the MySQL course explains naming in its lessons on creating tables. In CSS, class names in kebab-case are the common style, and the selectors lesson shows how they are used. In PHP, you will meet camelCase for methods, PascalCase for classes and snake_case in many built-in function names, which is a historical mix; the syntax lesson and the classes lesson show conventions in context.

Related tools

Count the words or characters in your text with the Word Counter. Remove hidden characters that may have crept into a pasted list with the Invisible Character Cleaner. When you convert a title into an address, make sure special characters are handled with the URL Encoder & Decoder.

Quick answers

Which style should I use for my project? The one your language and team already use. If you are starting fresh, follow the official style guide of the language.

Why not just use spaces? Most programming languages treat a space as a separator between separate things, so a name cannot contain one.

Is kebab-case good for SEO? Hyphens separate words in a web address and are widely recommended for readable URLs.

Does case matter to computers? Often yes. Name and name are different identifiers in most languages, and some file systems treat File.txt and file.txt as different files while others do not.

Advertisement