Programmers name thousands of variables, functions, files and URLs, and every language community has its own conventions. Using the right text case makes code easier to read and fits the style others expect. This guide explains common text case styles for programmers with examples, and our Case Converter can switch between them.
The main styles
| Style | Example | Common use |
|---|---|---|
| camelCase | totalPrice | JavaScript variables and functions, Java methods |
| PascalCase | TotalPrice | Classes in many languages, React components |
| snake_case | total_price | Python variables and functions, database columns |
| kebab-case | total-price | URLs, CSS classes, file names |
| CONSTANT_CASE | TOTAL_PRICE | Constants in many languages |
Language conventions
- JavaScript/TypeScript: camelCase for variables, PascalCase for classes.
- Python: snake_case for functions and variables (PEP 8), PascalCase for classes.
- PHP (WordPress): snake_case functions are common in WordPress code.
- CSS: kebab-case class names.
- SQL: snake_case column names are common.
URL slugs
For web pages, kebab-case slugs are standard: lowercase, words separated by hyphens. Search engines treat hyphens as word separators, so “gpa-calculator” is better than “gpa_calculator” or “GPACalculator”.
Acronyms
Teams differ on “userID” vs “userId”. Many style guides prefer treating acronyms as words (userId, HtmlParser) for readability. Pick one rule per project.
Converting quickly
Paste a phrase like “total price with tax” into the converter and choose a style:
| Style | Result |
|---|---|
| camelCase | totalPriceWithTax |
| snake_case | total_price_with_tax |
| kebab-case | total-price-with-tax |
Consistency
Linters and formatters (ESLint, Black, PHP_CodeSniffer) can enforce naming rules automatically.
For writing headings, read title case vs sentence case. Count characters in identifiers or slugs with the Character Counter, and check text length with the Word Counter.
File names
File naming conventions vary too. Web projects often use kebab-case for files (user-profile.js), Python modules use snake_case (user_profile.py), and React component files frequently use PascalCase (UserProfile.jsx). Avoid spaces in file names; they cause problems in command lines and URLs.
Environment variables
Environment variables are almost always in CONSTANT_CASE, such as DATABASE_URL or API_KEY. Keeping this convention makes configuration easy to spot in code.
Frequently asked questions
What is camelCase?
Words joined with each word after the first capitalised, like totalPrice.
Which case is best for URLs?
Lowercase kebab-case, such as gpa-calculator.
What case does Python use?
snake_case for functions and variables, PascalCase for classes.
