Train case (also called Train-Case or Capital-Kebab-Case) is a naming style where each word starts with a capital letter and words are joined by hyphens, like User-Profile or Api-Version. It looks like train cars linked together, hence the name. This style shines in URLs, CSS class names (especially BEM variants), project naming, and config files. In this guide, we break down its rules, use cases, and how it compares to other naming conventions.
Train case (also written as Train-Case or Capital-Kebab-Case) is a naming convention that mixes hyphen separators with capitalised first letters. Every word begins with an uppercase letter and is joined by a single hyphen, giving each term a distinct, train‑like appearance — for example, User-Profile or Api-Version. This style is particularly useful in project names, URL slugs, CSS class names (especially within BEM), and certain configuration files. Compared to plain lowercase kebab-case, train case offers extra readability and visual emphasis, making it a favourite for branding and public-facing identifiers.
Every word must start with a capital letter, followed by lowercase letters. This is similar to PascalCase, but with hyphens instead of no separator — e.g., Max-Retry, not max-retry or MAX-RETRY.
Words are connected by a single hyphen -, as in User-Account. Since hyphens are safe in URLs and carry special meaning in CSS, train case integrates well with those environments.
Common acronyms like API, URL, or ID are often kept fully uppercase (e.g., API-Key, User-ID). However, some teams prefer only the first letter capitalised (Api-Key). Consistency within your project is what matters most.
A valid train‑case identifier must not start or end with a hyphen, nor contain multiple hyphens in a row.
Although train case is rarely used for variable names in programming languages (because most languages don’t allow hyphens in identifiers), it excels in other areas:
Many open‑source projects and commercial products adopt train case for their names — think My-Project or Awesome-Library. The capital letters make the name stand out more than all‑lowercase alternatives, while hyphens stay compatible with most package managers (e.g., npm technically prefers lowercase, but train case is still common on GitHub repositories).
In RESTful APIs or website paths, train case can be used to denote resource collections or versions, like /api/User-Profile or /v1/Order-Item. Though lowercase kebab is more widespread, train case gives URLs an extra layer of readability, especially for branded endpoints.
Within the BEM (Block Element Modifier) methodology, class names often use hyphens. Some teams adopt train case for Blocks or Elements to differentiate them from modifiers. For instance, .User-Profile could represent a block, while .user-profile--active might stay lowercase. This hybrid approach can be tailored to your project’s needs.
Certain configuration formats (JSON, YAML) allow hyphens in keys. Train case makes those keys more readable, e.g., "Max-Retry": 3. Just remember that in many programming languages, you’ll need to quote such keys when accessing them.
Train case sits between kebab‑case (all lowercase with hyphens) and PascalCase (no separators, capitalised). It borrows the visual clarity of hyphens from kebab and the emphatic capitals from Pascal, but it sacrifices the simplicity of all‑lowercase. Compared to macro style (all caps + underscores), train case is less shouty and more readable, making it better suited for user‑facing names and UI elements, while macro style stays in the realm of constants.
Next to snake_case (lowercase with underscores), train case feels more prominent and formal, so it’s often chosen for titles and identifiers that need to stand out. In practice, train case typically lives in namespaces, project titles, URL paths, and style hooks — it rarely crosses into internal code.
This-Is-A-Very-Long-Name hurt readability; shorten where possible.Train case isn’t an official standard from any particular language or framework; it grew out of community practice. The name “Train‑Case” comes from the visual metaphor of train cars (words) linked by couplers (hyphens). It first appeared in early web development as a way to name URL segments, and later found its way into CSS class naming as a variant. Though it never achieved the ubiquity of camelCase or snake_case, its unique readability keeps it alive in niche areas like branding, API design, and documentation.
Train case is a naming style that balances clear separation with capital‑letter emphasis. It’s a great fit for project identities, URL paths, and specific style classes. While it won’t replace internal code identifiers, it gives you a visual edge over plain lowercase kebab in the right contexts. Understanding how train case differs from macro style, kebab case, and others helps you make smarter naming decisions — and adds a touch of professionalism to your work.