Skip to main content
The Editor class is the core of Tiptap. It manages the editor state, handles transactions, and provides methods to interact with your content.

Creating an Editor

The simplest way to create an editor is to instantiate the Editor class:

Editor Options

The Editor constructor accepts a configuration object with the following options:
HTMLElement | null
The DOM element where the editor should be mounted. Can be null if you want to mount it later.
string | JSONContent
The initial content of the editor. Can be HTML string or JSON.
Extension[]
default:"[]"
An array of extensions to use in the editor. Extensions add functionality like nodes, marks, and commands.
boolean
default:"true"
Whether the editor is editable.
boolean | 'start' | 'end' | number
default:"false"
Whether the editor should be focused on initialization.
  • true or 'start': Focus at the start
  • 'end': Focus at the end
  • number: Focus at a specific position
boolean
default:"true"
Whether to inject the default Tiptap CSS styles.
boolean
default:"true"
Whether to enable input rules (e.g., markdown shortcuts).
boolean
default:"true"
Whether to enable paste rules.
boolean
default:"true"
Whether to enable core extensions (required for basic functionality).

Event Handlers

The editor emits events at different stages of its lifecycle:
({ editor }) => void
Called when the editor is created and ready.
({ editor, transaction }) => void
Called whenever the document changes.
({ editor }) => void
Called when the selection changes.
({ editor, transaction }) => void
Called for every transaction (even if the document didn’t change).
({ editor, event }) => void
Called when the editor receives focus.
({ editor, event }) => void
Called when the editor loses focus.
() => void
Called when the editor is destroyed.

Core Methods

Content Methods

(content: string | JSONContent, options?: SetContentOptions) => Editor
Replace the entire document with new content.
Source: /home/daytona/workspace/source/packages/core/src/commands/setContent.ts:35
() => string
Get the current document as HTML.
Source: /home/daytona/workspace/source/packages/core/src/Editor.ts:737
() => JSONContent
Get the current document as JSON.
Source: /home/daytona/workspace/source/packages/core/src/Editor.ts:727
(options?: { blockSeparator?: string }) => string
Get the current document as plain text.
Source: /home/daytona/workspace/source/packages/core/src/Editor.ts:744

Focus Methods

(position?: 'start' | 'end' | number | boolean) => Editor
Focus the editor at a specific position.
() => Editor
Remove focus from the editor.

Lifecycle Methods

(element: HTMLElement) => void
Mount the editor to a DOM element.
Source: /home/daytona/workspace/source/packages/core/src/Editor.ts:161
() => void
Unmount the editor from the DOM (but keep it in memory for later remounting).
Source: /home/daytona/workspace/source/packages/core/src/Editor.ts:190
() => void
Destroy the editor and clean up all resources.
After calling destroy(), the editor instance cannot be reused. Create a new editor if needed.
Source: /home/daytona/workspace/source/packages/core/src/Editor.ts:766

Properties

SingleCommands
Access to all registered commands.
Source: /home/daytona/workspace/source/packages/core/src/Editor.ts:232
Schema
The ProseMirror schema generated from your extensions.
Source: /home/daytona/workspace/source/packages/core/src/Editor.ts:65
EditorView
The ProseMirror editor view.
Source: /home/daytona/workspace/source/packages/core/src/Editor.ts:305
EditorState
The current ProseMirror editor state.
Source: /home/daytona/workspace/source/packages/core/src/Editor.ts:353
boolean
Whether the editor currently has focus.
Source: /home/daytona/workspace/source/packages/core/src/Editor.ts:69
boolean
Whether the editor is editable.
Source: /home/daytona/workspace/source/packages/core/src/Editor.ts:295
boolean
Whether the editor content is empty.
Source: /home/daytona/workspace/source/packages/core/src/Editor.ts:759
boolean
Whether the editor has been destroyed.
Source: /home/daytona/workspace/source/packages/core/src/Editor.ts:777
Storage
Access to extension storage.
Source: /home/daytona/workspace/source/packages/core/src/Editor.ts:225

Advanced Usage

Making the Editor Read-only

Checking Active State

Getting Attributes

Working with Selection

TypeScript Types

Best Practices

Clean Up Resources

Always call editor.destroy() when you’re done with an editor instance to prevent memory leaks.

Batch Updates

Use command chains to batch multiple updates into a single transaction.

Check Before Acting

Use editor.can() to check if a command can be executed before running it.

Commands

Learn about the command system

Extensions

Learn about extensions

Schema

Learn about the ProseMirror schema

Nodes & Marks

Learn about content structure