Skip to main content
Block attributes provide the structured data needs of a block. They define how data is stored and extracted from saved content.

Attribute definition

Attributes are specified in an object where each key is the attribute name:

Attribute schema

Each attribute definition must include either type or enum, and may include additional fields.

Type validation

The type field indicates the data type. Must be one of:
  • null
  • boolean
  • object
  • array
  • string
  • integer
  • number (same as integer)

Enum validation

Restricts values to a fixed set:

Value sources

The source field determines where attribute data is stored.

No source (comment delimiter)

Without a source, data is stored in the block’s comment delimiter:
Saved as:

attribute source

Extracts values from HTML element attributes:
Given this HTML:
Returns:

Boolean attributes

For existence checks like disabled:

text source

Extracts inner text using textContent:
Given:
Returns:

html source

Extracts inner HTML using innerHTML:
Given:
Returns:

query source

Extracts arrays of objects from multiple elements:
Given:
Returns:

meta source (deprecated)

Meta attribute sources are deprecated. Use EntityProvider and related hooks instead.
Extracts values from post meta:
Requires server-side registration:

Selectors

The selector field uses CSS selector syntax:
Without a selector, the source runs against the block’s root element.

Default values

Provide fallback values with the default field:

Attribute roles

The role property provides semantic meaning:

content role

Marks user-editable content:

local role

Marks temporary, non-persistent data:
Local attributes are never saved to post content.

Using attributes

In the edit function

In the save function

Attributes with a source must be saved correctly:
Attributes without a source are saved automatically in the comment delimiter.

Complete example

Best practices

  • Store as much data as possible in HTML rather than comment delimiters
  • Use appropriate type values for validation
  • Provide default values for optional attributes
  • Use role: 'content' for user-editable content
  • Use descriptive attribute names
  • Consider deprecations when changing attributes