Case Styles and Naming Conventions Explained
Names in code, files, URLs and headings follow conventions that differ from one language and format to the next. This guide lists the common case styles, where each one is expected, and the details that trip people up: acronyms, numbers, headings and letters outside English.
The Common Styles
| Style | Example | How it is built |
|---|---|---|
| camelCase | orderTotal | First word lower case, later words capitalised, no separator |
| PascalCase | OrderTotal | Every word capitalised, no separator |
| snake_case | order_total | Lower case, words joined with _ |
| CONSTANT_CASE | ORDER_TOTAL | Upper case, words joined with _ |
| kebab-case | order-total | Lower case, words joined with - |
| dot.case | order.total | Lower case, words joined with . |
| Title Case | Order Total | Words separated by spaces, each capitalised |
| Sentence case | Order total | Only the first word capitalised |
camelCase is sometimes called lower camel case and PascalCase upper camel case. CONSTANT_CASE is also known as screaming snake case.
Which Style Each Language and Format Expects
Most ecosystems settled on a convention long ago, and following it makes code easier to read for everyone who knows that ecosystem:
| Where | Usual convention |
|---|---|
| JavaScript, TypeScript, Java | camelCase for variables and functions, PascalCase for classes, CONSTANT_CASE for fixed constants |
| Python (PEP 8) | snake_case for functions and variables, PascalCase for classes, CONSTANT_CASE for constants |
| C# | PascalCase for types, methods and public members, camelCase for local variables and parameters |
| Go | PascalCase exports a name from its package, camelCase keeps it private |
| Ruby, Rust | snake_case for methods and variables, PascalCase for types |
| CSS and HTML | kebab-case for properties, class names and data- attributes |
| URLs | kebab-case; Google recommends hyphens rather than underscores between words |
| SQL tables and columns | snake_case, because many databases fold unquoted names to one case |
| Environment variables | CONSTANT_CASE, such as DATABASE_URL |
| Configuration keys | dot.case for nested settings, such as server.port |
| JSON APIs | No single rule: many use camelCase, others snake_case; follow the API you work with |
kebab-case cannot be used for variable names in most programming languages, because the hyphen
is read as a minus sign: order-total means order minus total.
Acronyms and Numbers
Acronyms are where conventions disagree most. One school keeps them in capitals
(userID, parseHTML); another treats them as ordinary words
(userId, parseHtml). Google's Java and JavaScript style guides take the
second approach, which keeps word boundaries clear when acronyms meet: XmlHttpRequest
is easier to split than XMLHTTPRequest. Microsoft's .NET guidelines keep two-letter
acronyms in capitals (IOStream) and capitalise only the first letter of longer ones
(HtmlButton). The browser API XMLHttpRequest mixes both, which is why it
is often quoted as a warning.
Numbers have no case, so a converter cannot tell whether utf8Decoder means "utf8
decoder" or "utf 8 decoder". Converters usually attach a number to the word before it. Pick one
spelling and use it everywhere.
Title Case and Sentence Case in Headings
In headings, style guides do not capitalise every word the same way. AP and Chicago style keep short articles, conjunctions and prepositions in lower case unless they come first or last ("The Lord of the Rings"), and they differ on the exact list. Many interface and documentation guides, including Microsoft's and Google's developer documentation guides, use sentence case instead ("Change your password"), which is easier to apply consistently and reads less formally.
The LeedyBox converter's Title Case capitalises every word, which is right for labels and variable-like names but not for a newspaper-style headline: lower the small words by hand afterwards.
Converting Between Styles Loses Information
Every conversion first splits a name into words, using capital letters and separators as clues,
and then joins the words in the new style. Whatever the target style cannot express is gone:
parseHTML becomes parse_html, and converting back gives
parseHtml. Punctuation is dropped too, so "don't" turns into two words.
So treat one style as the source of truth. If a database uses snake_case and the code uses camelCase, convert at the boundary every time, in the same direction, rather than storing names in both forms.
Renaming Keys Across an API Boundary
When a front end in camelCase talks to a back end in snake_case, most serialization libraries can map the names automatically, so the data is never renamed by hand. Converting a JSON document once, for example a fixture or a sample response, is a different job, and the case converter's "JSON keys" mode does it without touching the values.
Watch for collisions: user_name and userName become the same key in
either style, and one of them would overwrite the other. Leading symbols such as _id
or $ref often carry meaning for a specific database or schema, so check whether they
may be renamed at all.
Upper and Lower Case Beyond English
Case rules are not the same in every language. German ß becomes SS in upper case, so the word gets
longer. Turkish has a dotted and a dotless i: its upper-case pair is i → İ and ı → I, while the
default rule used by most programming languages turns i into I. JavaScript's
toUpperCase() uses the default rule; toLocaleUpperCase('tr') applies
the Turkish one. Korean, Chinese and Japanese have no upper and lower case at all, so only the
separators between words change.
Case can also matter for file names. Windows and, by default, macOS treat
Readme.md and README.md as the same file, while Linux treats them as two.
A rename that only changes case can therefore go unnoticed on one system and break links or imports
on another.
Frequently Asked Questions
Is camelCase or snake_case better?
Neither is better in general. Use the convention of the language, framework or API you are working in; consistency within one codebase matters more than the choice itself.
Should URLs use hyphens or underscores?
Hyphens. Google's guidance for URLs recommends hyphens between words, and kebab-case slugs
such as /case-converter/ are the common practice on the web.
Why does Git not notice that I changed only the case of a file name?
On a case-insensitive file system, Git often treats the old and new names as the same file.
Rename the file with git mv, for example through a temporary name, so the
change is recorded for systems where case matters.
How should I write a brand name like iPhone or eBay in camelCase?
Converters split at capital letters, so such names come out as separate words. In code it is
usually clearer to treat the brand as one word (iphoneModel) and keep its
official spelling only in text shown to people.