How to Use the "of" property in a "block" schema type
I totally get the confusion here! The of property in the block schema can be a bit tricky because it's used in two different contexts, and the documentation doesn't always make this super clear.
When you define a Portable Text field, you're actually creating an array that can contain blocks and other content types. The of property at the array level defines what types can be in that array (like {type: 'block'}, {type: 'image'}, etc.).
But then the block type itself also has an of property! This is where it gets interesting. The of property on the block type defines inline objects - custom content that appears within your text paragraphs, not as separate blocks.
Here's a practical example:
defineField({
name: 'content',
type: 'array',
of: [
{
type: 'block',
// This 'of' defines inline objects within text
of: [
{
type: 'object',
name: 'inlineProduct',
fields: [
{name: 'productId', type: 'string'}
]
}
],
// 'marks' defines annotations (like links)
marks: {
annotations: [
{
name: 'link',
type: 'object',
fields: [
{name: 'href', type: 'url'}
]
}
]
}
},
{type: 'image'} // This is a separate block, not inline
]
})The key distinction:
- Inline objects (defined in
block.of) appear within text spans - think of them like inline components embedded in a paragraph - Annotations (defined in
block.marks.annotations) are decorators on text selections - like links, highlights, or citations - Block-level objects (defined in the array's
of) are separate content blocks that sit between paragraphs
For practical guides on working with these concepts, check out:
- Introduction to Portable Text - great overview of the whole system
- Add Inline blocks for the Portable Text Editor - walks through adding inline objects with the
ofproperty - How to add custom YouTube embed blocks - walks through adding custom block types
- Portable Text Editor configuration docs - covers customizing the editor behavior
The inline objects feature (that of property on blocks) is less commonly documented because annotations are usually the better choice for most inline use cases. If you're trying to add something like inline links or citations, you'll want to use annotations instead!
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.