Programming Naming Conventions: camelCase, snake_case, PascalCase & More
Complete guide to programming naming conventions. Learn when to use camelCase, snake_case, PascalCase, kebab-case, and CONSTANT_CASE with language-specific rules for JavaScript, Python, Go, Java, CSS, and more.
Programming Naming Conventions: camelCase, snake_case, PascalCase & More
Naming conventions are one of the first things every developer needs to learn -- and one of the most common sources of inconsistency in codebases. Using the wrong case style does not cause syntax errors, but it signals unfamiliarity with a language's idioms and makes code harder to read for experienced developers.
This guide covers every major naming convention, when to use each one, and the specific rules for 10 programming languages. Use our free case converter to instantly transform text between all these formats.
The Major Naming Conventions
camelCase
Pattern: First word lowercase, subsequent words capitalized. No separators.
myVariableName
calculateTotalPrice
getUserById
isAuthenticated
Where it's used: JavaScript/TypeScript variables and functions, Java variables and methods, JSON property names, Swift variables and functions.
Why it's called camelCase: The capital letters in the middle of the word resemble the humps of a camel.
PascalCase (UpperCamelCase)
Pattern: Every word capitalized, including the first. No separators.
MyClassName
UserProfile
HttpRequestHandler
DatabaseConnection
Where it's used: Class names in nearly all languages, React/Vue/Angular component names, TypeScript interfaces and types, C# everything (methods, properties, classes).
Key difference from camelCase: The first letter is capitalized. myFunction (camelCase) vs MyFunction (PascalCase).
snake_case
Pattern: All lowercase, words separated by underscores.
my_variable_name
calculate_total_price
get_user_by_id
is_authenticated
Where it's used: Python variables, functions, and module names (PEP 8), Ruby variables and methods, Rust variables and functions, database column and table names, file names in many projects.
SCREAMING_SNAKE_CASE (CONSTANT_CASE)
Pattern: All uppercase, words separated by underscores.
MAX_RETRY_COUNT
DATABASE_URL
API_BASE_URL
DEFAULT_TIMEOUT_MS
Where it's used: Constants in most languages, environment variables, C/C++ preprocessor macros, Java static final fields.
kebab-case (dash-case)
Pattern: All lowercase, words separated by hyphens.
my-component-name
user-profile-card
border-bottom-color
my-awesome-package
Where it's used: CSS class names and properties, HTML attributes (data-*), URL slugs, npm package names, file names in many frameworks, Lisp/Clojure function names.
Note: kebab-case cannot be used for variable names in most programming languages because the hyphen is interpreted as a minus operator.
dot.case
Pattern: All lowercase, words separated by dots.
com.example.myapp
log.level.debug
spring.datasource.url
Where it's used: Java package names, configuration keys (Spring Boot, .properties files), C# namespaces, domain names.
Train-Case (HTTP-Header-Case)
Pattern: Every word capitalized, separated by hyphens.
Content-Type
X-Request-Id
Accept-Language
Cache-Control
Where it's used: HTTP headers, MIME types. This is the only common naming convention that capitalizes words while using hyphens.
Language-Specific Rules
JavaScript / TypeScript
| Element | Convention | Example |
|---|---|---|
| Variables | camelCase | let userName = "John" |
| Functions | camelCase | function getUserData() |
| Classes | PascalCase | class UserProfile |
| Interfaces (TS) | PascalCase | interface ApiResponse |
| Type aliases (TS) | PascalCase | type UserId = string |
| Constants | CONSTANT_CASE | const MAX_RETRIES = 3 |
| Enum members (TS) | PascalCase | enum Color { Red, Blue } |
| React components | PascalCase | function UserCard() |
| CSS modules | camelCase | styles.headerContainer |
| File names | kebab-case or camelCase | user-profile.ts |
| npm packages | kebab-case | my-awesome-lib |
Python
| Element | Convention | Example |
|---|---|---|
| Variables | snake_case | user_name = "John" |
| Functions | snake_case | def get_user_data(): |
| Classes | PascalCase | class UserProfile: |
| Constants | CONSTANT_CASE | MAX_RETRIES = 3 |
| Modules | snake_case | import user_utils |
| Packages | lowercase (no separators) | import mypackage |
| Private members | _leading_underscore | self._internal_data |
| Name mangling | __double_leading | self.__private_var |
| Dunder methods | double_both | def __init__(self): |
Python's naming conventions are defined in PEP 8, which is the universally accepted style guide.
Java
| Element | Convention | Example |
|---|---|---|
| Variables | camelCase | String userName |
| Methods | camelCase | getUserData() |
| Classes | PascalCase | class UserProfile |
| Interfaces | PascalCase | interface Serializable |
| Constants | CONSTANT_CASE | static final int MAX_RETRIES |
| Packages | lowercase.dot.separated | com.example.myapp |
| Enum values | CONSTANT_CASE | enum Status { ACTIVE, INACTIVE } |
Go
| Element | Convention | Example |
|---|---|---|
| Exported (public) | PascalCase | func GetUser(), type Config struct |
| Unexported (private) | camelCase | func parseInput(), var count int |
| Constants | PascalCase or camelCase | const MaxRetries = 3 |
| Packages | lowercase (single word) | package http |
| Interfaces | PascalCase + -er suffix | type Reader interface |
| Acronyms | ALL CAPS | userID, httpURL, sqlDB |
Go uses capitalization for visibility -- exported identifiers start with an uppercase letter, unexported ones with lowercase. This is enforced by the compiler, not just convention.
CSS
| Element | Convention | Example |
|---|---|---|
| Properties | kebab-case | background-color: red |
| Class names | kebab-case | .user-profile-card |
| BEM notation | block__element--modifier | .card__title--active |
| CSS custom properties | kebab-case with -- prefix | --primary-color: blue |
| Sass variables | kebab-case with $ | $font-size-large |
| Tailwind classes | kebab-case | text-sm, bg-blue-500 |
Rust
| Element | Convention | Example |
|---|---|---|
| Variables | snake_case | let user_name = "John" |
| Functions | snake_case | fn get_user_data() |
| Structs/Enums | PascalCase | struct UserProfile |
| Constants | SCREAMING_SNAKE_CASE | const MAX_RETRIES: u32 = 3 |
| Modules | snake_case | mod user_utils |
| Traits | PascalCase | trait Serialize |
| Crate names | kebab-case (Cargo.toml) / snake_case (code) | my-crate / my_crate |
SQL
| Element | Convention | Example |
|---|---|---|
| Keywords | UPPERCASE | SELECT, FROM, WHERE |
| Table names | snake_case (singular or plural) | user_profile or user_profiles |
| Column names | snake_case | first_name, created_at |
| Indexes | ix_ prefix | ix_users_email |
| Foreign keys | fk_ prefix | fk_orders_user_id |
Common Conversion Patterns
When working across languages or systems, you frequently need to convert between naming conventions:
| From → To | When |
|---|---|
| camelCase → kebab-case | JS property → CSS class name |
| camelCase → snake_case | JS/Java → Python/Ruby/Database |
| snake_case → camelCase | Database/API → JavaScript |
| PascalCase → kebab-case | Component name → file name |
| kebab-case → camelCase | CSS property → JS style property |
| CONSTANT_CASE → camelCase | Environment variable → config object |
Example: A JSON API might return user_name (snake_case), but your JavaScript code uses userName (camelCase), your CSS uses .user-name (kebab-case), and your React component is UserName (PascalCase) -- all representing the same concept.
Use our case converter to instantly convert between all these formats without manual retyping.
Acronyms and Abbreviations
Acronyms in identifiers are handled differently across languages:
| Language | Rule | Example |
|---|---|---|
| JavaScript | Capitalize only first letter | userId, htmlParser, apiUrl |
| Go | Keep all caps | userID, htmlParser, apiURL |
| C# | 2-letter acronyms: all caps; 3+: PascalCase | IOStream, HtmlParser |
| Java | Capitalize only first letter | userId, httpUrl |
| Python | Lowercase in snake_case | user_id, html_parser, api_url |
The inconsistency around acronyms is one of the most debated style issues. The most important thing is consistency within your project.
File Naming Conventions
| Language/Framework | Convention | Example |
|---|---|---|
| JavaScript/TypeScript | kebab-case or camelCase | user-profile.ts, userProfile.ts |
| React components | PascalCase | UserProfile.tsx |
| Python | snake_case | user_profile.py |
| Java | PascalCase (matches class) | UserProfile.java |
| Go | lowercase | userprofile.go |
| CSS/SCSS | kebab-case | user-profile.css |
| Tests | Same + .test/.spec | user-profile.test.ts |
Style Guide References
| Language | Official Style Guide |
|---|---|
| Python | PEP 8 |
| JavaScript | Airbnb / Google / StandardJS |
| TypeScript | Google TypeScript Style Guide |
| Java | Google Java Style Guide |
| Go | Effective Go (enforced by gofmt) |
| Rust | Rust API Guidelines |
| C# | .NET Naming Guidelines |
| Swift | Swift API Design Guidelines |
| Ruby | Ruby Style Guide |
| PHP | PSR-12 |
Frequently Asked Questions
Does naming convention affect code execution?
In most languages, no -- myVar and my_var are both valid. The exception is Go, where capitalization determines visibility: MyFunc is exported (public), myFunc is unexported (private). In CSS, class names are case-sensitive, so .MyClass and .myclass are different selectors.
Which naming convention is "best"?
There is no universally best convention. Follow the established convention for your language. Using snake_case in JavaScript or camelCase in Python will work, but it will confuse other developers and violate community expectations. Consistency within a project matters more than the specific choice.
How do linters enforce naming conventions?
ESLint (JavaScript) has the camelcase rule. Pylint (Python) enforces PEP 8 naming. RuboCop (Ruby) checks naming style. Go's compiler enforces export rules by capitalization. Most linters can be configured to match your project's specific naming requirements.
Need to convert text between naming conventions? Use our case converter to instantly transform between camelCase, snake_case, PascalCase, kebab-case, and more. For counting characters and words in your code, try our word counter.