Kebab Case Converter (+ camelCase, snake_case, and PascalCase)

Type or paste any text into the converter below and it returns kebab-case, camelCase, PascalCase, snake_case, CONSTANT_CASE and Title Case as you type, each with a copy button. Kebab case means writing every word in lowercase and joining the words with hyphens, so “User Profile Page” becomes user-profile-page.

Case converter: type or paste any text

The converter splits your text into words at spaces, hyphens, underscores and lowercase-to-uppercase boundaries (so userProfilePage works as input too), drops other punctuation, and rebuilds the words in each style. A few inputs trip up every converter, including this one; the edge cases section below shows exactly what happens with acronyms, accents and numbers.

What kebab case looks like

Kebab case has two rules: everything is lowercase, and hyphens replace the spaces between words. MDN describes it the same way and notes the name comes from words that look like meat on a skewer. You will also see it called dash-case, hyphen-case, lisp-case or spinal-case. Train-Case is a close relative that capitalizes each word.

My String               ->  my-string
Reasons to Build a Blog ->  reasons-to-build-a-blog
SCRIPTLOADER            ->  scriptloader
User Profile Page       ->  user-profile-page

A single word stays one lowercase word with no hyphen. Acronyms lose their capitals along with everything else, which is why SCRIPTLOADER comes out as one word: there is nothing in it that marks a word boundary.

Kebab case vs camel case, Pascal case, and snake case

Every naming convention answers the same two questions: what goes between words, and which letters are capitalized. Here are the six you will run into, all of which the converter above outputs.

ConventionExampleSeparatorCapitalsTypical home
kebab-caseuser-profile-pageHyphenNoneURLs, CSS, HTML attributes, CLI flags
camelCaseuserProfilePageNoneEvery word but the firstJavaScript variables and functions, JSON keys
PascalCaseUserProfilePageNoneEvery wordClasses, React components, C# and Java types
snake_caseuser_profile_pageUnderscoreNonePython, WordPress PHP functions, SQL columns
CONSTANT_CASEUSER_PROFILE_PAGEUnderscoreAllConstants and environment variables
Title CaseUser Profile PageSpaceEvery wordHeadings and labels, not identifiers
Same three words in each convention.

The short version of which one to pick:

  • Inside URLs, CSS and HTML, where hyphens are allowed and lowercase is expected, use kebab-case.
  • For JavaScript variables and function names, use camelCase.
  • Anything that acts like a class or component gets PascalCase.
  • In Python, SQL and WordPress PHP function names, use snake_case.

Kebab case and snake case are the closest pair: both are all lowercase and differ only in the separator. The separator decides where each one is allowed. A hyphen is a minus sign in most programming languages, so snake case works for variable names and kebab case does not. In URLs it flips: Google recommends hyphens over underscores because hyphens clearly signal a word boundary, while underscores are commonly read as joining a concept together.

Where you’ll actually see kebab case

Some of these are hard rules set by a spec, and some are conventions you are free to break. The table marks which is which, and includes a few places people assume use kebab case but do not.

WhereExampleRule or convention
URLs and WordPress slugs/how-to-install-wordpress/Convention, recommended by Google
CSS property namesbackground-colorRule: the CSS spec names properties this way
CSS custom properties--primary-colorRule for the -- prefix; names are case sensitive
CSS class names.site-headerConvention (BEM and utility frameworks use their own patterns)
HTML data-* and ARIA attributesdata-user-id, aria-labelRule: no uppercase letters allowed in data-* names
Command-line long options--dry-run, --skip-pluginsConvention, listed in the GNU long option table
WordPress file namesclass-wp-error.phpRule in the WordPress PHP coding standards
GitHub Actions workflow keysruns-on, timeout-minutesFixed by the workflow syntax
Docker Compose keysdepends_on, env_fileNot kebab: Compose uses snake_case
Kubernetes manifest fieldsapiVersion, containerPortNot kebab: Kubernetes object fields are camelCase
YAML is not one convention. Each tool picks its own key style, so check the schema before guessing.

URLs and WordPress slugs

Every WordPress permalink ends in a kebab case slug by default. Publish “How to Install WordPress” and WordPress runs the title through sanitize_title() to get how-to-install-wordpress. If you build slugs in code, the guide to getting and generating page slugs covers sanitize_title() and how to keep a generated slug unique.

CSS and HTML attributes

CSS itself is written in kebab case, from font-family to custom properties like --primary-color, so class names that match (.primary-button, .site-header) read naturally next to them. That is a habit rather than a requirement, and it is the pattern you will see when you add custom CSS in WordPress and inspect core classes like .wp-block-list.

HTML data-* attributes are stricter: the name after data- cannot contain uppercase letters. When JavaScript reads them through dataset, the browser converts kebab case to camelCase for you:

<div id="card" data-user-id="42" data-is-admin="true"></div>

const card = document.getElementById('card');
card.dataset.userId;   // "42"
card.dataset.isAdmin;  // "true"

MDN also warns against a digit right after a hyphen, like data-test-1, because dataset does not convert it to a usable property name.

Command-line flags

Long command-line options are kebab case with two leading dashes. GNU publishes a table of standard long option names such as dry-run and ignore-case so tools stay consistent, and WP-CLI follows the same style. A safe database search-and-replace looks like this:

wp search-replace 'http://example.test' 'https://example.com' --dry-run --skip-columns=guid

Global flags like --skip-plugins and --skip-themes work the same way across every WP-CLI command.

Why JavaScript can’t use kebab case for variable names

In JavaScript, PHP, Python and the rest of the C family, a hyphen is the subtraction operator. The parser reads user-name as user minus name, and the error depends on where you wrote it. Running both lines in Node 26:

let user-name = 1;     // SyntaxError: Unexpected token '-'
console.log(user-name); // ReferenceError: user is not defined

Kebab case is still fine as a string. Object keys work with bracket notation (obj['user-id']), and the DOM bridges the two worlds: el.style.setProperty('background-color', 'red') takes the CSS name, while el.style.backgroundColor is the camelCase property for the same thing.

A few languages were designed to allow hyphens in identifiers. Lisp, Scheme and Clojure all accept names like get-user-by-id, which is where the “lisp-case” alias comes from.

When to use kebab case (and when not to)

Reach for kebab case when:

  • You’re creating a URL or a WordPress slug
  • You’re naming a CSS class, ID or custom property
  • You’re adding a data-* attribute in HTML
  • You’re naming a long command-line option for a script or WP-CLI command
  • You’re naming a theme, plugin or PHP file in WordPress

Avoid kebab case when:

  • You’re naming a variable or function in JavaScript, Python, PHP or any language where the hyphen is a minus sign
  • You’re naming a SQL table or column (snake_case is the usual choice)
  • You’re naming a class or component (PascalCase is the norm)
  • You’re writing config keys for a tool whose schema uses another style, like Docker Compose or Kubernetes

How the converter handles edge cases

Converters disagree on acronyms, accents and digits, so we ran real inputs instead of describing rules, the same way our sentence counter documents its edge cases. Here is what the same inputs produce in the JavaScript that powers the converter on this page (in Node 26) and in WordPress core’s _wp_to_kebab_case() (copied from trunk and run on PHP 8.4):

InputThis converter_wp_to_kebab_case()
XMLHttpRequestxmlhttp-requestxml-http-request
getHTTPResponseget-httpresponseget-http-response
iPhone 15 Proi-phone-15-proi-phone-15-pro
white2whitewhite2whitewhite-2-white
Don't Stopdon-t-stopdont-stop
Café Menucaf-menucafé-menu
100% Pure100-pure100-pure
Output from both functions on November 9, 2026.

Three takeaways from that table:

  • A run of capitals glues onto the next word in this converter. If you paste a camelCase name with an acronym in it, check the result or add a space before the acronym.
  • Apostrophes become a hyphen here (don-t) but vanish in WordPress (dont). Delete them before converting if that matters.
  • Accented letters are dropped by this converter and kept by _wp_to_kebab_case(). For URL slugs, use sanitize_title() instead, which turns “Déjà vu” into deja-vu.

How to Convert a String to Kebab Case

The general approach: insert a break at camelCase boundaries, lowercase everything, replace any run of non-alphanumeric characters with a single hyphen, then trim hyphens from the ends. Here it is in the three languages you’ll most likely need. Every example output below was checked by running the code.

JavaScript

function toKebabCase(str) {
    return str
        .replace(/([a-z])([A-Z])/g, '$1-$2')  // camelCase boundaries
        .replace(/[\s_]+/g, '-')              // spaces and underscores
        .toLowerCase()
        .replace(/[^a-z0-9-]/g, '')            // drop everything else
        .replace(/-+/g, '-')                   // collapse repeats
        .replace(/^-|-$/g, '');                // trim ends
}

toKebabCase('User Profile Page');     // 'user-profile-page'
toKebabCase('userProfilePage');       // 'user-profile-page'
toKebabCase('USER_PROFILE_PAGE');     // 'user-profile-page'

The first replace handles camelCase input by inserting a hyphen at every lowercase-then-uppercase boundary. Without it, 'userName' would collapse to 'username' instead of 'user-name'.

Python

import re

def to_kebab_case(s):
    s = re.sub(r'([a-z])([A-Z])', r'\1-\2', s)
    s = re.sub(r'[\s_]+', '-', s).lower()
    s = re.sub(r'[^a-z0-9-]', '', s)
    return re.sub(r'-+', '-', s).strip('-')

to_kebab_case('User Profile Page')     # 'user-profile-page'
to_kebab_case('userProfilePage')       # 'user-profile-page'

PHP (and WordPress)

// Generic PHP version
function to_kebab_case($s) {
    $s = preg_replace('/([a-z])([A-Z])/', '$1-$2', $s);
    $s = preg_replace('/[\s_]+/', '-', strtolower($s));
    $s = preg_replace('/[^a-z0-9-]/', '', $s);
    return trim(preg_replace('/-+/', '-', $s), '-');
}

// WordPress: use the built-ins instead
echo sanitize_title( 'User Profile Page' ); // 'user-profile-page'
echo _wp_to_kebab_case( 'User Profile Page' ); // 'user-profile-page'

Inside WordPress, prefer sanitize_title() for anything that becomes a URL slug. It is what WordPress itself uses for post slugs and it transliterates accented characters. _wp_to_kebab_case() is a private function (the underscore prefix means core can change it), and its own docs say it exists to generate preset class names that match what the block editor produces in JavaScript.

The one WordPress rule that catches people out: numbers

_wp_to_kebab_case() does not behave like a typical hand-rolled converter, and the difference is entirely about digits. It inserts a separator wherever letters meet numbers, so a run of digits becomes its own word:

Input_wp_to_kebab_case()What most converters give you
white2whitewhite-2-whitewhite2white
font2xlfont-2-xlfont2xl
white4thwhite-4thwhite4th
Post Title 2026post-title-2026post-title-2026
WordPress splits letter-to-digit boundaries but keeps a digit run together. Examples from the September 2026 developer roundup.

The reason is historical rather than deliberate design, and core’s own documentation for the function says so outright. It exists to “replicate what lodash’s kebabCase (JS library) does in the client,” because WordPress generates preset class names on both the server and in the editor and the two have to agree. As the source comment puts it: “We can’t remove or update the client’s library due to backward compatibility (some of the output of lodash’s kebabCase is saved in the post content). We have to make the server behave like the client.”

In September 2026 WordPress closed the loop from the other direction by publishing @wordpress/kebab-case, a JavaScript package whose stated job is to convert strings “matching WordPress Core’s _wp_to_kebab_case().” If you are generating slugs in JavaScript that have to line up with ones PHP produced, use that rather than reaching for lodash or writing your own.

For ordinary slugs none of this matters, because sanitize_title() does not split letter-to-digit boundaries at all. It only bites when you are naming block attributes, preset slugs or theme.json values that contain digits, which is exactly where a mismatch between PHP and JavaScript output shows up as a class name that does not apply.

How to Convert Kebab Case to camelCase, PascalCase, or snake_case

Going the other direction is simpler. Split on the hyphens, then rejoin with the target convention’s rules:

// kebab-case to camelCase
const kebabToCamel = (s) => s.replace(/-(.)/g, (_, c) => c.toUpperCase());
kebabToCamel('user-profile-page');     // 'userProfilePage'

// kebab-case to PascalCase
const kebabToPascal = (s) => s
    .split('-')
    .map(w => w[0].toUpperCase() + w.slice(1))
    .join('');
kebabToPascal('user-profile-page');    // 'UserProfilePage'

// kebab-case to snake_case
const kebabToSnake = (s) => s.replace(/-/g, '_');
kebabToSnake('user-profile-page');     // 'user_profile_page'

These come in handy when data arrives in kebab case (URL parameters, CSS custom property names, HTML attributes) and you need it as a variable name. For data-* attributes specifically, skip the conversion and let dataset do it.

Why “kebab”?

The name comes from the look: words skewered on hyphens the way meat and vegetables sit on a kebab stick. Snake case slithers along its underscores, and camel case has humps where the capitals are. The programming community, once in a while, is delightful.

Frequently asked questions

What is kebab case?

Kebab case is a naming convention where every word is lowercase and words are separated by hyphens. “User Name” becomes user-name and “My Page” becomes my-page. It is the standard style for URLs, CSS properties and HTML attributes.

What is an example of kebab case?

Common examples are my-awesome-page as a URL slug, background-color as a CSS property, data-user-id as an HTML attribute, and --dry-run as a command-line flag. Any phrase written in lowercase with hyphens instead of spaces is kebab case.

What is the difference between kebab case and snake case?

Kebab case separates words with hyphens (user-profile-page), snake case with underscores (user_profile_page). Kebab case is used in URLs, CSS and HTML. Snake case is used for variable and function names in Python, WordPress PHP and SQL, because underscores are legal in identifiers and hyphens are not.

What is the difference between camelCase and PascalCase?

Only the first letter. camelCase starts lowercase (userProfilePage) and PascalCase starts uppercase (UserProfilePage). In JavaScript, camelCase is used for variables and functions, and PascalCase for classes and React components.

Should URLs use hyphens or underscores?

Hyphens. Google’s URL structure guidelines recommend hyphens because they clearly mark word boundaries, while underscores are often read as joining words together. WordPress uses hyphens in slugs by default.

Can I use kebab case in JavaScript?

Not for variable or function names, because the hyphen is parsed as a minus sign. It works fine in strings: CSS custom properties, data-* attribute names, object keys in bracket notation, and any class name or slug your code generates.

Wrapping Up

Kebab case is the web’s default casing for anything a browser or server reads as text: URLs, CSS, HTML attributes and command-line flags. Code that runs uses camelCase, PascalCase or snake_case instead, because a hyphen in an identifier is a minus sign.

Use the converter at the top of this page for quick conversions, or this space-to-hyphen tool if you only need to swap spaces for hyphens. Inside WordPress, sanitize_title() is the function to use for slugs.

Picture of Andy Feliciotti

Andy Feliciotti

Andy has been a full time WordPress developer for over 15 years. Through his years of experience has built 100s of sites and learned plenty of tricks along the way. Found this article helpful? Buy Me A Coffee

Leave a Reply

Your email address will not be published. Required fields are marked *

WordPress Tips Monthly
Get the latest from SmartWP to your inbox.