Skip to main content

Introduction to components

The @wordpress/components package provides a library of generic WordPress components for creating common UI elements shared between screens and features of the WordPress dashboard.
These components are designed to be reusable, accessible, and consistent with WordPress design patterns.

Installation

Install the components package:
This package requires an ES2015+ environment. Use the polyfill from @wordpress/babel-preset-default if needed.

Basic usage

Import components from the package root:

Loading component styles

Many components include CSS styles that must be loaded for proper appearance.

In WordPress

Add the wp-components stylesheet as a dependency:

In non-WordPress projects

Link directly to the built stylesheet:
The file is located at node_modules/@wordpress/components/build-style/style.css.

Component categories

The components package includes various UI elements:

Input Components

  • Button - Buttons with various styles and sizes
  • TextControl - Text input fields
  • TextareaControl - Multiline text areas
  • CheckboxControl - Checkbox inputs
  • RadioControl - Radio button groups
  • SelectControl - Dropdown selects
  • ToggleControl - Toggle switches

Layout Components

  • Panel - Collapsible panel containers
  • PanelBody - Panel sections
  • PanelRow - Panel rows
  • Card - Card containers
  • CardBody - Card content areas

Feedback Components

  • Notice - User notifications
  • Snackbar - Temporary notifications
  • Spinner - Loading indicators
  • Placeholder - Content placeholders

Advanced Components

  • Popover - Floating popovers
  • Modal - Modal dialogs
  • Dropdown - Dropdown menus
  • ColorPicker - Color selection
  • DatePicker - Date selection

Block editor components

The @wordpress/block-editor package provides specialized components for the block editor.
Components in @wordpress/block-editor are customized for editor use. Use @wordpress/components for general-purpose UI unless building an editor.

Key block editor components

Component examples

Button component

Panel components

ColorPicker component

Popover system

By default, Popover components render in an element appended to the document body.

Controlling popover placement

Use Popover.Slot to control where popovers render:
Wrap your app with SlotFillProvider and add Popover.Slot where you want popovers to render.

TypeScript usage

The package exports TypeScript types for components. Extract props types using React.ComponentProps:

Block editor specific components

The @wordpress/block-editor package provides components designed specifically for block development:

RichText component

For editable rich text content:

InspectorControls

For block sidebar settings:

BlockControls

For block toolbar controls:

InnerBlocks

For nested block structures:
The InnerBlocks API governs child block usage and enables hierarchical block structures.

Block hooks

The @wordpress/block-editor package provides essential hooks:

useBlockProps

Marks an element as a block wrapper:
Use of useBlockProps on the outermost element is required for blocks using API version 2 or higher.

useInnerBlocksProps

Marks an element as an inner blocks wrapper:

useBlockEditContext

Access block edit context:

Component documentation

Comprehensive component documentation and interactive examples are available in Storybook:
Browse component docs and examples at https://wordpress.github.io/gutenberg/

Accessibility

WordPress components follow accessibility best practices:
  • Keyboard navigation support
  • ARIA attributes for screen readers
  • Focus management
  • Color contrast compliance
  • Semantic HTML structure
Always test your components with keyboard navigation and screen readers to ensure accessibility.

Using components in WordPress

When building WordPress plugins, enqueue component dependencies:
Access components via the wp global:

Component status and transitions

The components package is evolving:
WordPress is rewriting global components for the new @wordpress/ui package. However, this is work in progress—continue using @wordpress/components until further notice.
Check component status in Storybook documentation for up-to-date usage guidance. The Storybook status is the most accurate signal, above experimental tags or prefixes.

Form components and validation

DataForm integration

For editing dataset items, consider using DataForm from @wordpress/dataviews:

Validated form components

For validation, use validated form components:

Best practices

  1. Use semantic components - Choose components that match your intent
  2. Load required styles - Always enqueue component stylesheets
  3. Follow accessibility patterns - Use ARIA labels and keyboard navigation
  4. Check component status - Verify component stability in Storybook
  5. Use TypeScript types - Leverage TypeScript for type safety
  6. Test interactivity - Verify keyboard and screen reader support
  7. Manage dependencies - Properly declare script dependencies
  8. Use SlotFill for popovers - Control popover rendering locations

Next steps