Kebab Case vs Snake Case: Differences and When to Use Each

Content owner: WordCaseFix Editorial · Page structure last modified: August 9, 2026 · Review standards

Short answer: use snake_case for variables, functions, database fields, and other names evaluated as code. Use kebab-case for URLs, CSS classes, HTML data attributes, file names, and command-line flags.

The exception is a language or ecosystem with its own convention. Follow the project's formatter and style guide when one exists.

Snake case and kebab case differ by one character, but the separator changes where each style is valid. An underscore is normally allowed inside a programming identifier; a hyphen is normally parsed as subtraction. The comparison below shows the practical choice by context.

Snake Case Converter Convert text and identifiers to clean snake_case format instantly.
Open converter

What Is Snake Case?

Snake case writes multi-word identifiers in lowercase with underscores between words: user_profile, get_total_amount, max_retry_count. The name comes from the way underscores resemble a snake slithering between the words. Snake case has been around since the earliest days of C and is deeply embedded in the Unix and scientific computing ecosystems.

It is the conventional style for variables, functions, and module names in Python (PEP 8), Ruby, Rust, and most database systems. Constants typically use an uppercase variant called SCREAMING_SNAKE_CASE or CONSTANT_CASE.

What Is Kebab Case?

Kebab case writes identifiers in lowercase with hyphens between words: user-profile, get-total-amount, max-retry-count. The name comes from the way the words look skewered on a hyphen, like meat on a kebab. Kebab case is also called "dash-case," "lisp-case," or "spinal-case."

It is the standard for URL slugs, CSS class names, HTML attribute values, package names in npm, command-line flags, and most configuration file keys. Lisp dialects (Clojure, Scheme) use kebab-case for variables and functions because the hyphen is a legal identifier character in those languages.

Same concept, three styles:

snake_case: customer_account_id
kebab-case: customer-account-id
camelCase: customerAccountId

The Critical Difference: Where You Can Use Each

The single most important fact about kebab case is that the hyphen is a subtraction operator in almost every mainstream programming language. That means user-profile is parsed as "the variable user minus the variable profile," not as a single identifier. As a result, kebab case is illegal as a variable or function name in JavaScript, Python, Java, C, C++, C#, Go, Rust, Ruby, and PHP.

Snake case has no such conflict. The underscore is a regular identifier character in every major language, so snake_case works everywhere a name is required.

Contextsnake_case OK?kebab-case OK?
Python variablesYes (PEP 8)No (syntax error)
JavaScript variablesYesNo (parsed as subtraction)
CSS class namesYesYes (preferred)
HTML attributesNo (non-standard)Yes (data-user-id)
URL pathsAllowedPreferred (SEO)
npm package namesAllowedAllowed and common
Database column namesStandardRequires quoting
Environment variablesSCREAMING_SNAKENo
JSON keysCommonAllowed but rare

When to Use snake_case

Use snake_case when the identifier must be referenced from program code. That includes Python and Ruby variables and methods, Rust functions and modules, database table and column names, JSON API keys consumed by Python or Ruby backends, environment variables (uppercase), and most file names in scientific Python codebases. If you are starting a new Python project, snake_case is non-negotiable for functions and variables — linters will flag anything else.

You can quickly normalize messy input into snake_case with our . It strips punctuation, lowercases letters, and joins words with underscores.

When to Use kebab-case

Use kebab-case when the name appears in a context that does not parse it as a normal code identifier. The big four are URLs, CSS, HTML attributes, and file names on disk. Google recommends hyphens rather than underscores to separate words in URLs because they make concepts easier to identify. npm package names must be lowercase and may contain hyphens, dots, or underscores; hyphens are common but not mandatory. Most CLIs also use kebab-case for long flags such as --dry-run.

Kebab Case Converter Generate URL-safe, hyphen-separated slugs from any text.
Open converter

Mixing the Two in One Project

Most real codebases use both. A typical web application might use camelCase for JavaScript variables, kebab-case for CSS classes and URL slugs, and snake_case for the Python or Ruby backend and the SQL database. The trick is to be consistent within each layer and to apply translation cleanly at the boundaries. For example, a backend that returns user_id in JSON might be normalized to userId in the JavaScript client. Learn more in our JSON key naming guide.

Rule of thumb: If the identifier will be evaluated by a compiler or interpreter, use snake_case or camelCase. If it will be consumed by a browser, search engine, or human reader of a URL, use kebab-case.

Five-Second Decision Checklist

Frequently Asked Questions

Is kebab-case faster to read than snake_case?

There is no universal readability winner. Both separators make word boundaries visible, while language syntax and project conventions determine which form is valid. Choose based on the context table above rather than assuming one style is always faster to read.

Why can't I use kebab-case in JavaScript variable names?

Because the hyphen is the minus operator. let user-id = 5 is parsed as "assign 5 to the expression user-id," which is invalid syntax. Use camelCase or snake_case instead.

Which is better for SEO, snake_case or kebab-case URLs?

Use kebab-case. Google recommends hyphens instead of underscores to separate URL words because they help users and search engines identify concepts. Treat this as a URL clarity practice, not a guarantee that changing a separator will improve rankings.

Primary references: Python PEP 8 naming conventions, Google URL structure guidance, and npm package name requirements. Last reviewed August 9, 2026.