Title: @wordpress/ui
Published: November 11, 2025
Last modified: November 5, 2026

---

# @wordpress/ui

## In this article

 * [Installation](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-ui/?output_format=md#installation)
 * [Setup](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-ui/?output_format=md#setup)
    - [Within standard WordPress editor screens](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-ui/?output_format=md#within-standard-wordpress-editor-screens)
    - [Elsewhere](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-ui/?output_format=md#elsewhere)
 * [Usage](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-ui/?output_format=md#usage)
    - [Component names](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-ui/?output_format=md#component-names)
    - [Basic Component Usage](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-ui/?output_format=md#basic-component-usage)
 * [Core Design Principles](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-ui/?output_format=md#core-design-principles)
    - [Custom Rendering](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-ui/?output_format=md#custom-rendering)
    - [Ref Forwarding](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-ui/?output_format=md#ref-forwarding)
    - [Automatic className Merging](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-ui/?output_format=md#automatic-classname-merging)
    - [Controlled and Uncontrolled Modes](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-ui/?output_format=md#controlled-and-uncontrolled-modes)
 * [Contributing to this package](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-ui/?output_format=md#contributing-to-this-package)

 This package is still experimental. “Experimental” means this is an early implementation
subject to drastic and breaking changes.

A package that provides React UI components for the WordPress Design System, built
on themeable design tokens.

While similar in scope to `@wordpress/components`, there are a few key differences:

 * `@wordpress/components` grew organically as a collection of unrelated UI elements
   for WordPress screens. In contrast, this package is an implementation of a design
   system that guarantees user- and developer-facing cohesion between components.
 * Unlike `@wordpress/components`, this package is not bundled as a WordPress script
   available on the `window.wp` global and is instead distributed as an npm package
   that follows [semantic versioning](https://semver.org/) for release changes.

`@wordpress/theme`, `@wordpress/ui`, and `@wordpress/icons` form the foundational
layer of the Design System. Higher-level compositional packages, including `@wordpress/
dataviews` and `@wordpress/admin-ui`, build common solutions from those foundations.
See the version-matched [Design System introduction](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-ui/../../storybook/stories/design-system/introduction.mdx?output_format=md)
in a Gutenberg checkout, or the [latest copy on Gutenberg trunk](https://github.com/WordPress/gutenberg/blob/trunk/storybook/stories/design-system/introduction.mdx)
when reading this package outside the monorepo.

This package includes many common UI components, but equivalent components can still
live in `@wordpress/components`. For current component-by-component guidance, including
when an existing `@wordpress/components` component remains the recommended choice,
see the version-matched [`use-recommended-components` rule documentation](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-ui/../eslint-plugin/docs/rules/use-recommended-components.md?output_format=md)
in a Gutenberg checkout, or the [latest copy on Gutenberg trunk](https://github.com/WordPress/gutenberg/blob/trunk/packages/eslint-plugin/docs/rules/use-recommended-components.md)
when reading this package outside the monorepo.

This is a companion to the `@wordpress/theme` package that provides:

 * **Design Tokens**: A comprehensive system of design tokens for colors, spacing,
   typography, and more
 * **Theme System**: A flexible theming provider for consistent theming across applications

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

Install using NPM:

    ```bash
    npm install @wordpress/ui
    ```

## 󠀁[Setup](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-ui/?output_format=md#setup)󠁿

As an implementation of the design system and companion to the `@wordpress/theme`
package, these components depend on CSS custom properties defined by the theme package.
What you need to set up depends on whether you’re building for a WordPress context,
and how much of the theming features you want to use.

### 󠀁[Within standard WordPress editor screens](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-ui/?output_format=md#within-standard-wordpress-editor-screens)󠁿

In standard WordPress editor screens (such as the post editor or the site editor),
stylesheets, isolation styles, and layout styles are managed centrally by Gutenberg.
You don’t need to add any setup yourself — and you should avoid doing so in this
shared context to prevent conflicts.

### 󠀁[Elsewhere](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-ui/?output_format=md#elsewhere)󠁿

The components ship with built-in fallback values for all CSS custom properties,
so they work out of the box without any theme setup. For full theming capabilities,
it’s recommended that you install and load the design tokens stylesheet:

    ```bash
    npm install @wordpress/theme
    ```

    ```javascript
    import '@wordpress/theme/design-tokens.css';
    ```

This stylesheet is universal and does not have a separate RTL version.

To ensure that portaled popovers appear correctly, add these isolation styles to
your application’s layout root element:

    ```language-css
    .root {
        isolation: isolate;
    }
    ```

In order to support overlay elements such as backdrops to correctly cover the whole
browser viewport even when scrolled, add the following style to your global styles:

    ```language-css
    body {
        position: relative;
    }
    ```

Components in this package use [CSS cascade layers](https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Styling_basics/Cascade_layers)
when defining their styles, which can conflict in some applications which apply 
styles on bare element selectors (for example, `input { border-color: #aaa; }`).
You should avoid these kinds of bare element selector styling if you can, preferring
CSS classes instead where possible.

If you need to customize the cascade layer order relative to your own CSS cascade
layers, the component styles are scoped under the `wp-ui` layer, which you can use
when defining your own layer order:

    ```language-css
    @layer wp-ui, example-app;
    ```

#### 󠀁[Mixing with @wordpress/components](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-ui/?output_format=md#mixing-with-wordpress-components)󠁿

If your app pairs `@wordpress/ui` with `@wordpress/components` overlays and bundles
both packages directly (i.e. without relying on the `window.wp.components` global
exposed by WordPress’s script-loader), call `useEnableWpCompatOverlaySlot()` once
from a long-lived root component:

    ```language-tsx
    import { useEnableWpCompatOverlaySlot } from '@wordpress/ui';

    function App() {
        useEnableWpCompatOverlaySlot();
        return <YourApp />;
    }
    ```

This opts the app into a shared body-level overlay container so `@wordpress/ui` 
overlays reliably stack above `@wordpress/components` overlays. The opt-in is one-
way and idempotent. It is shared across React roots and `@wordpress/ui` package 
copies in the same window and remains enabled after the calling component unmounts.
Explicit portal containers still take precedence. It is not needed in standard WordPress
editor screens, where the slot auto-enables based on `window.wp.components`.

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

### 󠀁[Component names](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-ui/?output_format=md#component-names)󠁿

Component names describe what the component is, with modifiers for its appearance
or purpose. `IconButton` is a button that displays an icon. `ButtonLink` is a link
styled as a button. `Dialog.CloseIconButton`, `Drawer.CloseIconButton`, and `Notice.
CloseIconButton` provide icon buttons for close or dismiss actions.

Compound components group related parts under one name. For example, `ButtonLink.
Icon` renders an icon inside `ButtonLink`, and `Menu.LinkItem` is a link item within
a menu. See [Component naming](https://github.com/WordPress/gutenberg/tree/HEAD/packages/ui/CONTRIBUTING.md#component-naming)
for contributor guidance.

### 󠀁[Basic Component Usage](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-ui/?output_format=md#basic-component-usage)󠁿

    ```language-tsx
    import { Stack } from '@wordpress/ui';

    function MyComponent() {
        return (
            <Stack gap="sm">
                <div>Item 1</div>
                <div>Item 2</div>
            </Stack>
        );
    }
    ```

## 󠀁[Core Design Principles](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-ui/?output_format=md#core-design-principles)󠁿

All components in the design system follow consistent patterns for maximum flexibility
and developer experience:

### 󠀁[Custom Rendering](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-ui/?output_format=md#custom-rendering)󠁿

Every component supports the `render` prop for complete control over the underlying
HTML element:

    ```language-tsx
    import { Stack } from '@wordpress/ui';

    function MyComponent() {
        // Render Stack as a <section /> instead of the default <div />
        return <Stack render={ <section /> }>{ /* ... */ }</Stack>;
    }
    ```

### 󠀁[Ref Forwarding](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-ui/?output_format=md#ref-forwarding)󠁿

All components forward refs to their underlying DOM elements:

    ```language-tsx
    import { useRef } from '@wordpress/element';
    import { Stack } from '@wordpress/ui';

    function MyComponent() {
        const stackRef = useRef< HTMLDivElement >( null );

        return <Stack ref={ stackRef }>{ /* ... */ }</Stack>;
    }
    ```

### 󠀁[Automatic className Merging](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-ui/?output_format=md#automatic-classname-merging)󠁿

Components merge provided `className` props with their internal styles:

    ```language-tsx
    import { Stack } from '@wordpress/ui';

    function MyComponent() {
        // Your custom CSS className is merged with component styles
        return <Stack className="my-custom-class">{ /* ... */ }</Stack>;
    }
    ```

### 󠀁[Controlled and Uncontrolled Modes](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-ui/?output_format=md#controlled-and-uncontrolled-modes)󠁿

Interactive components that manage internal state (such as open/closed, selected
value, etc.) follow a consistent prop naming convention that supports both **controlled**
and **uncontrolled** usage.

#### 󠀁[Prop naming pattern](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-ui/?output_format=md#prop-naming-pattern)󠁿

For a given state `x`, the convention is:

  |  Prop |  Purpose |  
   |  `defaultX` |  Sets the initial value in **uncontrolled** mode. The component manages subsequent state changes internally. |  
 |  `x` |  Sets the current value in **controlled** mode. The consumer is responsible for updating the value in response to changes. |  
 |  `onXChange` |  Callback invoked when the state changes. Receives the new value as its first argument. Works in both controlled and uncontrolled modes. |

For example, a component with an open/closed state would expose:

 * `defaultOpen` — initial open state (uncontrolled)
 * `open` — current open state (controlled)
 * `onOpenChange` — called when the open state changes

And a component with a selectable value would expose:

 * `defaultValue` — initial value (uncontrolled)
 * `value` — current value (controlled)
 * `onValueChange` — called when the value changes

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

In uncontrolled mode, the component manages its own state. Use `defaultX` to set
the initial value, and optionally `onXChange` to react to changes:

    ```language-tsx
    import { Tabs } from '@wordpress/ui';

    function MyTabs() {
        return (
            <Tabs.Root
                defaultValue="tab1"
                onValueChange={ ( value ) => console.log( value ) }
            >
                <Tabs.List>
                    <Tabs.Tab value="tab1">Tab 1</Tabs.Tab>
                    <Tabs.Tab value="tab2">Tab 2</Tabs.Tab>
                </Tabs.List>
                <Tabs.Panel value="tab1">Content 1</Tabs.Panel>
                <Tabs.Panel value="tab2">Content 2</Tabs.Panel>
            </Tabs.Root>
        );
    }
    ```

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

In controlled mode, the consumer owns the state and passes it via `x`. State changes
are handled through `onXChange`:

    ```language-tsx
    import { useState } from '@wordpress/element';
    import { CollapsibleCard } from '@wordpress/ui';

    function MyCard() {
        const [ isOpen, setIsOpen ] = useState( false );

        return (
            <CollapsibleCard.Root open={ isOpen } onOpenChange={ setIsOpen }>
                <CollapsibleCard.Header>Details</CollapsibleCard.Header>
                <CollapsibleCard.Content>
                    Collapsible content here.
                </CollapsibleCard.Content>
            </CollapsibleCard.Root>
        );
    }
    ```

When both `x` and `defaultX` are provided, `x` takes precedence and the component
behaves in controlled mode. When neither is provided, the component uses its own
internal default (typically documented via a `@default` JSDoc tag on the `defaultX`
prop).

#### 󠀁[Difference from native onChange](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-ui/?output_format=md#difference-from-native-onchange)󠁿

The `onXChange` callback is distinct from the native DOM `onChange` event handler.
Native `onChange` fires a `React.ChangeEvent` tied to a specific DOM element, while`
onXChange` provides the new **value** directly — making it simpler to use and consistent
across all components, including compound and non-form components.

Components that wrap native form elements may still support native event handlers(
like `onChange`, `onInput`) for interoperability, but `onXChange` is the recommended
approach within this package.

For guidance on implementing this pattern in new components, see [Controlled and uncontrolled props](https://github.com/WordPress/gutenberg/tree/HEAD/packages/ui/CONTRIBUTING.md#controlled-and-uncontrolled-props).

## 󠀁[Contributing to this package](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-ui/?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

November 11, 2025

Last updated

November 5, 2026

Edit article

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

[  Previous: @wordpress/token-list](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-token-list/)

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