Skip to main content
This API is experimental and subject to breaking changes in future versions.
Block annotations provide a way to highlight specific pieces of content in the block editor. Common use cases include commenting on text and spellchecking.

Basic usage

To annotate text within a block:

Text annotations

Text annotations highlight a range of characters within a RichText field.

Range positions

The start and end positions are calculated based only on the text content, ignoring HTML formatting:
Position 0 refers to before the “S” in “Strong”.

RichText identifier

The richTextIdentifier specifies which RichText instance to annotate:
  • Paragraph block: content
  • Quote block citation: citation
  • Quote block content: value
Check the block’s source code to find the correct identifier.

Example: Annotating text

Block annotations

Annotate an entire block by setting selector to block:

Styling block annotations

Block annotations require custom CSS:
The class name follows the pattern: .is-annotated-by-{source}

API reference

addAnnotation

Adds a new annotation. Parameters:
string
required
Unique identifier for the annotation source (e.g., your plugin name)
string
required
Client ID of the block to annotate
string
Identifier of the RichText field (required for text annotations)
object
Text range to annotate (required for text annotations)Properties:
  • start (number): Start position
  • end (number): End position
string
default:"range"
Annotation type: range for text or block for entire block

Working with positions

Use wp.richText.create to help determine correct positions:

Complete example

A spellcheck plugin that annotates misspelled words:
With CSS:

Limitations

  • Text annotations only work with RichText fields
  • Positions must be calculated carefully based on text content only
  • Block annotations require custom CSS
  • The API is experimental and may change

Use cases

Commenting

Highlight text that has comments:

Spellchecking

Mark spelling errors:

Content review

Highlight blocks requiring review: