Skip to main content
Block Transforms allow blocks to be converted from and to other blocks, as well as from other entities like shortcodes, files, regular expressions, and raw DOM nodes.

Transform Directions

Transforms work in two directions:
  • to: Transform this block into other block types
  • from: Create this block from other sources
Declare transforms in the block configuration:

Transform Types

Gutenberg supports six types of transformations:
  1. block - Convert between block types
  2. enter - Create blocks from keyboard input (Enter key)
  3. files - Create blocks from dropped files
  4. prefix - Create blocks from text prefixes
  5. raw - Create blocks from raw HTML/DOM
  6. shortcode - Create blocks from shortcodes

Block Transforms

Convert between different block types using toolbar controls.

Basic Block Transform

This allows transforming a paragraph into a heading while preserving content.

Block Transform Properties

type (required)

Must be 'block'.

blocks (required)

Array of block types this transform applies to. Use '*' for all blocks.

transform (required)

Function that receives block attributes and returns new block(s).

isMatch (optional)

Function to determine if transform should be available.

isMultiBlock (optional)

Allow transforming multiple selected blocks at once.

priority (optional)

Control transform order (lower = higher priority). Default: 10.

Block Transform Examples

Transform with InnerBlocks

Multi-Block Transform

Enter Transform

Create blocks when users type and press Enter.
Typing --- and pressing Enter creates a separator block.

Enter Transform Properties

  • type: 'enter'
  • regExp: Regular expression to match
  • transform: Function returning block(s)
  • priority: Optional priority (default: 10)

Enter Transform Examples

Files Transform

Create blocks from dropped or pasted files.

Files Transform Properties

  • type: 'files'
  • transform: Function receiving array of files
  • isMatch: Optional function to check if files should be handled
  • priority: Optional priority (default: 10)

Files Transform Examples

Prefix Transform

Create blocks from text prefixes followed by a space.
Typing ? creates a question block.

Prefix Transform Properties

  • type: 'prefix'
  • prefix: String to match
  • transform: Function receiving remaining content
  • priority: Optional priority (default: 10)

Prefix Transform Examples

Raw Transform

Create blocks from raw HTML or DOM nodes (paste, drop, convert to blocks).

Raw Transform Properties

  • type: 'raw'
  • transform: Optional function receiving DOM node
  • schema: Optional HTML content model for validation
  • selector: Optional CSS selector (shorthand for isMatch)
  • isMatch: Optional function to check if node matches
  • priority: Optional priority (default: 10)

Schemas and Content Models

Define which HTML elements and attributes are allowed:
This matches:

Raw Transform Examples

Shortcode Transform

Create blocks from WordPress shortcodes.

Shortcode Transform Properties

  • type: 'shortcode'
  • tag: Shortcode tag (string or array)
  • transform: Optional function receiving shortcode attributes
  • attributes: Optional attribute mapping object
  • isMatch: Optional function to check if shortcode should transform
  • priority: Optional priority (default: 10)

Using transform Function

Using attributes Mapping

Ungroup Transform

Define how a container block should be ungrouped:
For nested structures:

Complete Transform Example

Best Practices

  1. Preserve user content: Always try to maintain user data during transforms
  2. Use isMatch wisely: Prevent unwanted transforms with appropriate conditions
  3. Set appropriate priority: Lower priority for fallback transforms
  4. Handle edge cases: Test with empty content, special characters, etc.
  5. Provide two-way transforms: Allow users to undo transforms when possible
  6. Document transforms: Comment why each transform exists
  7. Test thoroughly: Verify transforms work with various content types

Common Patterns

Bidirectional Transform

Wildcard Transform