kebab-case is the conventional format for CSS class names, HTML attributes, and URL slugs: all lowercase, with hyphens between words. This converter turns any phrase or differently-cased identifier into clean kebab-case.
How it works
The input is normalised into a list of lowercase word tokens, then joined with hyphens. Word boundaries come from separators and from case transitions in camelCase or PascalCase input:
"User Profile Id" -> user-profile-id
"userProfileId" -> user-profile-id
"user_profile_id" -> user-profile-id
"OpenAPISpec" -> open-api-spec
Each word is lowercased before joining, producing a result that is safe to use directly as a class name or URL slug.
Where kebab-case is required — and where it is not
Understanding which context expects kebab-case saves you from naming bugs that are easy to miss:
Use kebab-case for:
- CSS class names and IDs —
.nav-bar,.user-avatar,#main-content. Hyphens are valid in CSS identifiers and are the dominant convention in vanilla CSS, BEM, and Tailwind utilities. - HTML custom data attributes —
data-user-id,data-product-slug. The HTML spec normalisesdata-camelCaseto all-lowercase anyway, so using kebab-case explicitly avoids browser inconsistencies. - URL path segments and slugs —
/blog/how-to-bake-bread. Search engines treat hyphens as word separators, makinghow-to-bake-breadmore readable and better for indexing thanhow_to_bake_breadorhowtobakebread. - NPM package names —
my-useful-package. The npm registry enforces lowercase and permits hyphens but not underscores or uppercase. - Vue component file names — the Vue style guide recommends multi-word component file names in kebab-case for case-insensitive file systems.
Do not use kebab-case for:
- JavaScript or TypeScript variable and function names — hyphens are subtraction operators in JS.
user-idis parsed asuser minus id, not a variable name. - Python identifiers — Python uses
snake_caseby convention (PEP 8). - Database column names — most databases prefer
snake_casefor column identifiers.
Acronym handling
Acronyms are lowercased during conversion. For example:
| Input | Output |
|---|---|
parseHTML | parse-html |
OpenAPISpec | open-api-spec |
getUserID | get-user-id |
XMLHttpRequest | xml-http-request |
This is the most consistent and readable approach, though some style guides prefer preserving acronym casing (e.g. get-userID). If your project has a different convention, adjust the output manually after copying.
Common mistakes to avoid
- Double hyphens — if your input has repeated spaces or punctuation, check that the output does not contain
--. The converter collapses consecutive separators, but unusual input (likeem — dash) may need manual cleanup. - Leading or trailing hyphens — inputs that start or end with a separator character can produce a leading or trailing hyphen in naive converters. This tool trims them automatically.
- Numbers in identifiers —
h1Titlebecomesh1-title, keeping the number attached to the preceding token. If you needh-1-title, split the number manually before converting.