Skip to main content
Block attributes define the data structure and persistence layer for your blocks. They specify what data your block stores and how that data is extracted from saved post content.

Attribute Definition

Attributes are defined in the attributes object of your block configuration. Each attribute has a key and a definition object:

Attribute Properties

Type Validation

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

Enum Validation

array
Restricts the attribute to a fixed set of allowed values

Default Value

any
Default value used when no matching content is found

Role

string
Designates the conceptual purpose of the attribute:
  • content - User-editable content (enables content-only editing)
  • local - Temporary, non-persistable data (not saved to post content)

Attribute Sources

The source field determines where and how attribute values are stored and extracted.

No Source (Comment Delimiter)

When no source is specified, data is stored in the block’s comment delimiter:
Saved as:

Attribute Source

Extract values from HTML element attributes:
'attribute'
Must be used with selector and attribute fields
Extracts from:
Results in:

Boolean Attributes

For existence checks (e.g., disabled attribute), use type: 'boolean':

Text Source

Extract inner text content using textContent:
Extracts from:
Results in:

HTML Source

Extract inner HTML using innerHTML:
Extracts from:
Results in:

Rich-Text Source

For RichText components that support formatting:

Query Source

Extract arrays of objects by matching multiple elements:
Extracts from:
Results in:

Real-World Examples

Paragraph Block Attributes

From packages/block-library/src/paragraph/block.json:

Button Block Attributes

From packages/block-library/src/button/block.json:

Group Block Attributes

From packages/block-library/src/group/block.json:

Using Attributes in Components

In Edit Function

In Save Function

Meta Attributes (Deprecated)

Meta attributes are deprecated. Use EntityProvider and related hooks from @wordpress/core-data instead.
Old approach (deprecated):
New approach:

Attribute Selectors

The selector field uses CSS selectors to target elements:

Best Practices

Store data in HTML markup rather than comment delimiters. This makes blocks more portable and reduces database overhead.
Always specify the type field to ensure proper validation and prevent data corruption.
Mark user-editable content with role: 'content' to enable content-only editing modes.
Use the default field to ensure your block works even when attributes are undefined.
When an attribute should only accept specific values, use enum for validation.

TypeScript Support

Migration and Deprecation

When changing attributes, use block deprecation to migrate old content:

Next Steps

Block Supports

Enable automatic attributes for common features

Inner Blocks

Build blocks that contain other blocks