contenteditable: Editable DOM In Place

Write in Rara’s contenteditable notebook: beforeinput and the inputType of every keystroke, a paste kept as plain text, and where the caret goes when…

Why it matters

Every comment box, caption or note richer than a <textarea> meets contentEditable sooner or later. Knowing that its state is innerHTML, that beforeinput is the gate of every change, and that a paste carries HTML explains why the caret jumps in React, why plaintext-only is often the rescue, and why modern editors (Lexical, ProseMirror, TipTap) are built on beforeinput, not the obsolete document.execCommand.

The key idea

A contentEditable editor’s state is its innerHTML, and beforeinput is its gate

Common mistakes

Try it in this playground