What is Train-Case?
Train-Case is a naming convention where words are capitalized and separated by hyphens. It resembles a train with each word being a "car" connected by hyphens. It's commonly used for HTTP headers and formal titles.
Examples:
Content-Type
User-Agent
Accept-Language
Cache-ControlWhen to Use Train-Case
- HTTP Headers: Standard format for request and response headers
- Email Headers: Subject lines and custom headers
- Meta Tags: Some HTML meta property names
- API Headers: Custom API authentication headers
- Configuration Keys: Some configuration file formats
- Formal Titles: Document headings requiring formality
Examples in Code
HTTP Request Headers:
Content-Type: application/json
Authorization: Bearer token123
Accept-Language: en-US
Cache-Control: no-cacheJavaScript Fetch API:
fetch('/api/data', {
headers: {
'Content-Type': 'application/json',
'X-Api-Key': 'your-key',
'User-Agent': 'MyApp/1.0'
}
});Custom HTTP Headers:
X-Request-Id: abc123
X-Forwarded-For: 192.168.1.1
X-Custom-Header: valueTrain-Case vs Other Cases
Train-Case: Content-Type - Capitalized with hyphens
kebab-case: content-type - Lowercase with hyphens
PascalCase: ContentType - Capitalized, no separators
Best Practices
- ✓ Use for HTTP and email headers
- ✓ Follow established header name conventions
- ✓ Prefix custom headers with X- when appropriate
- ✓ Be consistent with capitalization
- ✗ Don't use for programming variable names
- ✗ Avoid mixing with other casing styles