Title: @wordpress/kebab-case
Published: August 10, 2026

---

# @wordpress/kebab-case

## In this article

 * [Installation](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-kebab-case/?output_format=md#installation)
 * [Usage](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-kebab-case/?output_format=md#usage)
    - [kebabCase](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-kebab-case/?output_format=md#kebabcase)
 * [API](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-kebab-case/?output_format=md#api)
    - [kebabCase](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-kebab-case/?output_format=md#kebabcase-2)
 * [Contributing to this package](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-kebab-case/?output_format=md#contributing-to-this-package)

[ Back to top](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-kebab-case/?output_format=md#wp--skip-link--target)

Convert strings to kebab-case, matching WordPress Core’s [`_wp_to_kebab_case()`](https://developer.wordpress.org/reference/functions/_wp_to_kebab_case/).

This package exists because no off-the-shelf library matches the semantics of WordPress
Core’s `_wp_to_kebab_case()` function, which WordPress needs to preserve for backwards
compatibility.

## 󠀁[Installation](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-kebab-case/?output_format=md#installation)󠁿

Install the module

    ```bash
    npm install @wordpress/kebab-case --save
    ```

## 󠀁[Usage](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-kebab-case/?output_format=md#usage)󠁿

### 󠀁[kebabCase](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-kebab-case/?output_format=md#kebabcase)󠁿

Converts any string to kebab-case.

The conversion is designed to match WordPress Core’s [`_wp_to_kebab_case()`](https://developer.wordpress.org/reference/functions/_wp_to_kebab_case/)
function (and, transitively, Lodash’s [`_.kebabCase()`](https://lodash.com/docs/4.17.15#kebabCase)):
the package’s test suite covers every test case of the Core function. These semantics
differ from other kebab-case implementations in how numbers are handled (`'white23'`
becomes `'white-23'`, `'font2xl'` becomes `'font-2-xl'`, yet `'white4th'` stays `'
white-4th'`).

    ```javascript
    import { kebabCase } from '@wordpress/kebab-case';

    kebabCase( 'whiteToWhite' ); // 'white-to-white'
    kebabCase( 'white2white' ); // 'white-2-white'
    kebabCase( 'font2xl' ); // 'font-2-xl'
    kebabCase( '#ffffff' ); // 'ffffff'
    kebabCase( "i've done" ); // 'ive-done'
    ```

## 󠀁[API](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-kebab-case/?output_format=md#api)󠁿

### 󠀁[kebabCase](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-kebab-case/?output_format=md#kebabcase-2)󠁿

Converts any string to kebab case. Backwards compatible with Lodash’s `_.kebabCase()`.
Backwards compatible with `_wp_to_kebab_case()`.

_Related_

 * [https://lodash.com/docs/4.17.15#kebabCase](https://lodash.com/docs/4.17.15#kebabCase)
 * [https://developer.wordpress.org/reference/functions/_wp_to_kebab_case/](https://developer.wordpress.org/reference/functions/_wp_to_kebab_case/)

_Parameters_

 * _str_ `unknown`: String to convert.

_Returns_

 * Kebab-cased string

## 󠀁[Contributing to this package](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-kebab-case/?output_format=md#contributing-to-this-package)󠁿

This is an individual package that’s part of the Gutenberg project. The project 
is organized as a monorepo. It’s made up of multiple self-contained software packages,
each with a specific purpose. The packages in this monorepo are published to [npm](https://www.npmjs.com/)
and used by [WordPress](https://make.wordpress.org/core/) as well as other software
projects.

To find out more about contributing to this package or Gutenberg as a whole, please
read the project’s main [contributor guide](https://github.com/WordPress/gutenberg/tree/HEAD/CONTRIBUTING.md).

First published

August 10, 2026

Last updated

August 10, 2026

Edit article

[ Improve it on GitHub: @wordpress/kebab-case ](https://github.com/WordPress/gutenberg/edit/trunk/packages/kebab-case/README.md)

[  Previous: @wordpress/jest-preset-default](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-jest-preset-default/)

[  Next: @wordpress/keyboard-shortcuts](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-keyboard-shortcuts/)