Attribute Definition
Attributes are defined in theattributes 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:
nullbooleanobjectarraystringintegernumber(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
Thesource field determines where and how attribute values are stored and extracted.
No Source (Comment Delimiter)
When nosource is specified, data is stored in the block’s comment delimiter:
Attribute Source
Extract values from HTML element attributes:'attribute'
Must be used with
selector and attribute fieldsBoolean Attributes
For existence checks (e.g.,disabled attribute), use type: 'boolean':
Text Source
Extract inner text content usingtextContent:
HTML Source
Extract inner HTML usinginnerHTML:
Rich-Text Source
ForRichText components that support formatting:
Query Source
Extract arrays of objects by matching multiple elements:Real-World Examples
Paragraph Block Attributes
Frompackages/block-library/src/paragraph/block.json:
Button Block Attributes
Frompackages/block-library/src/button/block.json:
Group Block Attributes
Frompackages/block-library/src/group/block.json:
Using Attributes in Components
In Edit Function
In Save Function
Meta Attributes (Deprecated)
Old approach (deprecated):Attribute Selectors
Theselector field uses CSS selectors to target elements:
Best Practices
Use source whenever possible
Use source whenever possible
Store data in HTML markup rather than comment delimiters. This makes blocks more portable and reduces database overhead.
Define appropriate types
Define appropriate types
Always specify the
type field to ensure proper validation and prevent data corruption.Use role for content attributes
Use role for content attributes
Mark user-editable content with
role: 'content' to enable content-only editing modes.Provide sensible defaults
Provide sensible defaults
Use the
default field to ensure your block works even when attributes are undefined.Use enum for fixed values
Use enum for fixed values
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