Skip to main content
Block Selectors allow blocks to customize the CSS selectors used when generating styles for theme.json (Global Styles). Selectors can be customized at three levels:
  • Root - The block’s primary CSS selector
  • Feature - Selectors for block supports (color, typography, etc.)
  • Subfeature - Selectors for individual style properties

Root selector

The root selector is the block’s primary CSS selector. If not specified, it defaults to .wp-block-<name>.
For layout to work correctly, the block should have a classname that matches its selector.

Feature selectors

Feature selectors apply styles for specific block supports (border, color, typography, etc.) to different elements.

Example: Different elements for color and typography

This applies:
  • Color styles to .my-custom-block
  • Typography styles to .my-custom-block > h2

Subfeature selectors

Subfeature selectors target individual style properties within a feature.

Example: Typography with different selectors

This applies:
  • Most typography styles to .my-custom-block > h2
  • Text decoration to .my-custom-block > h2 span

Shorthand syntax

Instead of using an object with a root key, use a string for simpler feature selectors:

Fallback behavior

Selectors fall back in this order:
  1. Subfeature selector
  2. Feature root selector
  3. Block root selector

Example with fallbacks

This applies:
  • color.text to .my-custom-block p (explicit subfeature selector)
  • color.background to .my-custom-block (falls back to root)
  • typography.fontSize to .my-custom-block > h2 (falls back to feature root)
  • typography.text-decoration to .my-custom-block > h2 span (explicit subfeature)

Custom CSS selector

The css selector controls which selector is used for custom CSS rules from theme.json’s styles.blocks.<block-type>.css.

As a string

As an object

If not set, the block’s root selector is used.

Available features

Feature selectors can be defined for:
  • border
  • color
  • dimensions
  • filter
  • shadow
  • spacing
  • typography

Complete example

Use cases

Applying typography to inner heading

Separating background and text colors

Fine-grained spacing control

Best practices

  • Use descriptive class names for custom selectors
  • Ensure selectors match the actual block HTML structure
  • Keep selectors specific enough to avoid conflicts
  • Test selectors with theme.json Global Styles
  • Document custom selectors for theme developers