String to Kebab Case Converter
Convert camelCase, PascalCase, snake_case, or space-separated strings to kebab-case (dash-separated) instantly. Supports diacritics and condensing.
About
Kebab-case (also called dash-case or lisp-case) is the standard naming convention for CSS classes, URL slugs, and HTML attributes. A single inconsistent identifier - myComponentName instead of my-component-name - breaks CSS selectors, causes 404 errors on case-sensitive servers, and violates BEM methodology. This converter handles the four primary input patterns: camelCase, PascalCase, snake_case, and space-separated strings. It splits on uppercase boundaries using the regex pattern ([a-z\d])([A-Z]), normalizes separators, and lowercases the result. Diacritics (e.g., São → são) are preserved by default, unlike most slugify libraries that strip them. The optional condense mode collapses consecutive dashes into one, which matters when processing machine-generated identifiers that may contain artifacts like double underscores or mixed delimiters.
Limitation: this tool operates on single-string input. It does not parse entire codebases or batch-rename files. Acronyms like XMLHTTPRequest are split heuristically - the algorithm inserts breaks before uppercase letters that precede a lowercase letter, yielding xmlhttp-request. For acronym-aware splitting, manual review is recommended. The conversion is purely lexical. It does not validate whether the output is a legal CSS identifier or URL slug (e.g., leading digits remain).
Formulas
The conversion algorithm applies a deterministic pipeline of four regex transformations executed in strict order. Each stage handles a distinct structural pattern.
Where the four regex stages are:
Stage R1 inserts a dash between a lowercase letter or digit followed by an uppercase letter. This splits standard camelCase boundaries: fooBar → foo-Bar.
Stage R2 handles consecutive uppercase sequences (acronyms). HTMLElement → HTML-Element after R2.
Stage R3 replaces all whitespace, underscores, dots, and slashes with a single dash.
Optional stage R4 collapses consecutive dashes into one. Applied only when the condense flag is TRUE.
Where s = input string, lower = String.prototype.toLowerCase(), trim = removal of leading and trailing dashes via ^-+|-+$.
Reference Data
| Input Pattern | Example Input | Kebab Output | Convention Origin |
|---|---|---|---|
| camelCase | backgroundColor | background-color | JavaScript, Java |
| PascalCase | MyComponent | my-component | C#, React components |
| snake_case | user_first_name | user-first-name | Python, Ruby, SQL |
| SCREAMING_SNAKE | MAX_RETRY_COUNT | max-retry-count | Constants (C, Java) |
| Space Separated | Hello World | hello-world | Natural language |
| Dot Notation | com.example.app | com-example-app | Java packages, DNS |
| Mixed Delimiters | foo_bar-baz qux | foo-bar-baz-qux | Legacy code |
| Diacritics | São Tomé | são-tomé | Portuguese, French |
| Acronyms | XMLParser | xml-parser | API naming |
| Consecutive Uppercase | HTMLElement | html-element | DOM API |
| Numbers Mixed | test123Value | test123-value | Versioned identifiers |
| Leading Uppercase | FooBar | foo-bar | PascalCase |
| Single Word | hello | hello | Already valid |
| Already Kebab | already-kebab | already-kebab | No-op |
| Consecutive Dashes (condensed) | Foo----Bar | foo-bar | Condense option ON |
| Consecutive Dashes (raw) | Foo----Bar | foo----bar | Condense option OFF |
| Tabs & Newlines | foo\tbar\nbaz | foo-bar-baz | Whitespace normalization |
| Title Case | The Quick Brown Fox | the-quick-brown-fox | English titles |