kebab-case vs snake_case | Case Modify

Compare kebab-case and snake_case for URLs, CSS, Python, SQL, and APIs—with examples and a decision guide for developers and content teams.

Quick answer

Use kebab-case (hello-world) for URL slugs, CSS class names, and many CLI flags. Use snake_case (hello_world) for Python variables, SQL columns, and Ruby identifiers. The separator is not interchangeable—Python cannot use hyphens in variable names, and URLs rarely use underscores.

kebab-case in URLs and front-end code

Lowercase hyphenated paths read well in browser bars and analytics: /blog/post-title/ is easier to scan than mixed_case or CamelCase routes. CSS utilities and component classes (nav-item, card-title) follow the same pattern. When marketing hands you a Title Case headline, convert it to a slug before publishing.

snake_case in Python, data, and SQL

PEP 8 recommends snake_case for Python functions and variables. Warehouse tables and ORM models often map class names in PascalCase to snake_case columns. JSON from Python APIs may use snake_case keys while JavaScript clients expect camelCase—document the mapping at your API boundary.

How teams avoid drift

Write a one-page naming guide: public URLs kebab-case, database snake_case, JSON camelCase, TypeScript types PascalCase. When you import a spreadsheet of “Order Line Item” labels, run each through the right converter instead of retyping. Code review catches inconsistent slugs faster when generators own the first pass.

Common mistakes

Mixing separators in one project (user_profile-id) confuses search and codegen tools. Using ALL CAPS slugs creates duplicate URL variants on case-sensitive servers—lowercase first, then kebab-case. Copying snake_case column names directly into URL paths without conversion breaks analytics filters that expect hyphens.