Skip to main content
Every block in the Block Editor must be contained within an HTML wrapper with specific attributes to function correctly. WordPress provides useBlockProps() to manage these wrapper attributes.
Proper wrapper attributes are essential when using custom styling or block supports.

Types of block markup

A block can have three distinct types of markup:
  1. Editor markup: Visual representation in the Block Editor (via Edit component)
  2. Save markup: HTML saved to the database (via save function)
  3. Dynamic render markup: Server-generated content (via render_callback or render.php)

Editor markup

Use the useBlockProps() hook in your Edit component to define the wrapper:

What useBlockProps() provides

The useBlockProps() hook automatically adds:
  • Unique id attribute
  • Accessibility attributes (role, aria-label, tabindex)
  • Data attributes for block identification
  • The wp-block class
  • Block-specific class (e.g., wp-block-my-plugin-my-block)
  • Classes and styles from block supports (color, spacing, etc.)

Generated editor markup

Adding custom attributes

Pass additional classes and attributes to useBlockProps():
Block supports automatically add their classes and styles to the useBlockProps() return value.

Save markup

Use useBlockProps.save() in your save function to ensure proper wrapper attributes:

What useBlockProps.save() provides

  • Block-specific class name
  • Classes and inline styles from block supports
  • Any custom attributes passed as arguments

Generated save markup

With block supports enabled:

Adding custom save attributes

Dynamic render markup (PHP)

For server-rendered blocks, use get_block_wrapper_attributes() in PHP:

Adding custom PHP attributes

Pass an array of custom attributes:
get_block_wrapper_attributes() automatically includes classes from block supports like color, spacing, and typography.

Wrapper requirements

For both Edit and save, the wrapper must be: ✅ A standard DOM element (e.g., <div>, <p>, <section>)
✅ A React component that forwards all props to native DOM elements
❌ Not a React Fragment (<Fragment>)
❌ Not <ServerSideRender> component

Valid wrappers

Invalid wrappers

Complete example

Edit component

Save function

Render callback (PHP)

Block supports integration

When you enable block supports in block.json, the wrapper automatically receives the generated classes:
Resulting markup:

Next steps

Block supports

Learn about available block supports

Rendering

Understand static vs dynamic rendering