Skip to main content
Back to Blog

Programming Naming Conventions: Camel, Snake, Kebab

Where camelCase, snake_case, and kebab-case come from and which languages and tools use which convention.

Kashyap Thakar
7 min
CodingBest PracticesStyle
Programming Naming Conventions: Camel, Snake, Kebab

There are only two hard things in Computer Science: cache invalidation and naming things. Part of the naming struggle is deciding how to write the name.

The Big Three

1. camelCase

Start with lowercase, then capitalize each subsequent word.
myVariableName
Used in: JavaScript, Java, Swift, and Go (for unexported names).

2. snake_case

All lowercase, separated by underscores.
my_variable_name
Used in: Python, Ruby, SQL, Rust.

3. kebab-case

All lowercase, separated by hyphens.
my-variable-name
Used in: URLs, CSS classes, Lisp.

Other Contenders

  • PascalCase: Like camelCase but starts capitalized (MyClass). Standard for classes in most languages.
  • SCREAMING_SNAKE_CASE: Used for constants (MAX_RETRIES).

Why It Matters

Consistency is key. Mixing styles makes code hard to read. If you work with an API that returns snake_case JSON but your frontend uses camelCase, you need to transform the data at some point (see below).

Conventions by Language at a Glance

Each language community settled on a house style, and the idiomatic choice is almost always the one the standard library and official style guides already use. Following it means your code looks like everyone else's and linters will not fight you.

LanguageVariables and functionsTypes and classesConstants
JavaScript / TypeScriptcamelCasePascalCaseUPPER_SNAKE_CASE or camelCase
Python (PEP 8)snake_caseCapWordsUPPER_SNAKE_CASE
JavacamelCasePascalCaseUPPER_SNAKE_CASE (static final)
C#camelCase locals, PascalCase methods and propertiesPascalCasePascalCase
GoMixedCaps (capital first letter = exported)MixedCapsMixedCaps
Rustsnake_caseUpperCamelCaseSCREAMING_SNAKE_CASE
Rubysnake_caseCamelCaseSCREAMING_SNAKE_CASE
  • Go: there is no public keyword. A name that starts with a capital letter is exported from its package and a lowercase one is private, so capitalization carries meaning beyond style. Go also asks that initialisms keep a consistent case, such as URL or userID.
  • Rust: the compiler warns by default when a name breaks these conventions. The Rust API guidelines treat acronyms as single words in UpperCamelCase, so the type is Uuid, not UUID.
  • Python: PEP 8 recommends short, all-lowercase module names and a leading underscore for non-public names. It also allows mixedCase only where that is already the prevailing style, for example to stay compatible with an existing library.
  • SQL Server and others: there is no enforced standard, and some SQL Server projects use PascalCase for tables and columns. Pick one style per schema.
  • PostgreSQL: unquoted identifiers are folded to lowercase, so CREATE TABLE UserAccounts creates a table named useraccounts. That is a practical reason SQL schemas use snake_case: mixed-case names would force you to quote them everywhere.
  • Web platform: CSS properties, class names and custom properties (--brand-color) use kebab-case. HTML data-user-id attributes are exposed to JavaScript as element.dataset.userId, so the browser itself converts between kebab-case and camelCase.

Why You Can't Use kebab-case for Variables

The three styles are not interchangeable, because the separator character has to be legal inside an identifier. In most languages the hyphen is the minus operator, so a hyphenated name parses as arithmetic:

const a = 10, b = 3;
a-b                   // 7  (subtraction, not a variable named "a-b")
const my-var = 1;     // SyntaxError: Missing initializer in const declaration

Underscores and letter case are legal in identifiers almost everywhere, which is why camelCase and snake_case dominate code. Hyphens survive in places that are not parsed as expressions: URLs, CSS, file names, YAML keys, and Lisp-family languages, where arithmetic uses prefix notation and a-b is a single symbol.

Beyond Case: Naming Rules That Travel

Case is the easy part. A few habits make names readable in any language:

  • Booleans read as questions: isActive, hasPermission, canRetry. Avoid negated names like isNotValid, which turn into double negatives in conditions.
  • Functions are verbs, values are nouns: fetchUser() returns something, user is something.
  • Collections are plural: users is a list, user is one item.
  • Put units in the name when the type cannot: timeoutMs or timeout_seconds prevents a whole class of bugs.
  • Match name length to scope: i is fine in a three-line loop, but a module-level value deserves a descriptive name.

Where Conventions Collide

Trouble starts where data crosses between systems that follow different conventions:

  • Database to API: snake_case columns in PostgreSQL feeding a camelCase JavaScript client.
  • JavaScript to the DOM: data-user-id becomes dataset.userId, and background-color becomes style.backgroundColor.
  • Config to runtime: configuration keys, whose style depends on the tool, mapped to SCREAMING_SNAKE_CASE environment variables.

Each mismatch needs a transformation layer, which is extra code and a place for bugs.

Handling Boundaries in Code

When a snake_case API feeds a camelCase frontend, convert once, at the edge, rather than sprinkling both styles through your code. A small helper that splits an identifier into words and re-joins them is enough for plain keys, including nested objects and arrays:

const toWords = (s) => s
  .replace(/([a-z\d])([A-Z])/g, "$1 $2")
  .replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2")
  .split(/[\s_\-]+/).filter(Boolean).map((w) => w.toLowerCase());

const camel = (s) => toWords(s)
  .map((w, i) => (i ? w[0].toUpperCase() + w.slice(1) : w)).join("");
const snake = (s) => toWords(s).join("_");

const keysToCamel = (v) =>
  Array.isArray(v) ? v.map(keysToCamel)
  : v && typeof v === "object"
    ? Object.fromEntries(Object.entries(v).map(([k, x]) => [camel(k), keysToCamel(x)]))
    : v;

JSON.stringify(keysToCamel({
  user_id: 1, full_name: "Alice",
  home_address: { zip_code: "90210" },
  order_items: [{ item_id: 7 }],
}));
// {"userId":1,"fullName":"Alice","homeAddress":{"zipCode":"90210"},"orderItems":[{"itemId":7}]}

snake("getUserById")      // "get_user_by_id"
camel("api-base-url")     // "apiBaseUrl"

Put this in one place, such as your API client or serializer layer, and cover it with tests. Only convert keys, never values, and watch for dictionary-style objects whose keys are data (user IDs, locale codes) rather than field names. A converter will happily mangle those.

The tokenizer behind toWords is explained, along with its limits, in the text case conversion guide. In short, acronyms, numbers, and non-ASCII letters all need extra care: for example, snake("parseXMLHTTPRequest") returns parse_xmlhttp_request, which does not convert back to the original.

Enforce It With Tooling

A convention that depends on code review comments will drift. Let tools say it instead:

  • JavaScript/TypeScript: ESLint's camelcase rule, or @typescript-eslint/naming-convention for per-kind rules (variables, types, enum members).
  • Python: Pylint's invalid-name check or the pep8-naming plugin for flake8.
  • Rust: the compiler's built-in naming lints, no setup required.

Configure exceptions explicitly, for example for fields that mirror a third-party snake_case API, instead of disabling the rule globally. Inside an existing project, matching what the codebase already does beats textbook style. Related reading on keeping configuration names consistent: environment variable best practices and JSON vs YAML for config.

Converting Lists of Names

For a one-off list of column names or constants, the Text Case Converter can switch between camelCase, PascalCase, snake_case, kebab-case, CONSTANT_CASE, and more. Two limits to know: it splits words on spaces and punctuation (underscores and hyphens included) but not on capital letters, so it converts user_first_name to camelCase correctly but turns userFirstName into userfirstname when you ask for snake_case. It also treats non-ASCII letters as separators. For camelCase input, or whole payloads, use a helper like the one above. Whatever you use, check identifiers with acronyms or digits by hand.

Frequently Asked Questions

Which naming convention should I use?

Use the one your language's community and standard library use: camelCase in JavaScript and Java, snake_case in Python and Rust, PascalCase for types nearly everywhere. Inside an existing project, follow whatever the codebase already does.

What is the difference between camelCase and PascalCase?

Only the first letter. camelCase starts lowercase (userName) and PascalCase starts uppercase (UserName). Many languages use PascalCase for types and classes so that a type is visually distinct from a variable.

Can I use kebab-case for variable names?

Not in most languages, because the hyphen is parsed as a minus operator. Kebab-case works in URLs, CSS, file names, and config formats such as YAML, but a JavaScript identifier has to use camelCase or snake_case instead.

Should API JSON keys be camelCase or snake_case?

Either works. What matters is picking one for the whole API and documenting it. Many teams match the language of their main consumer, and convert at one boundary layer if the backend and frontend disagree.

How do I convert between naming conventions quickly?

For a handful of identifiers written with spaces, underscores, or hyphens, paste them into the Text Case Converter. For camelCase input or whole payloads, use a helper like the one above, applied in a single place.

Written by

Spotted a mistake? Let me know