Getting started
If you use Slate.js and need to store or display rich text outside the editor, these packages cover the common paths: HTML round-trip, React rendering, a DOM stage before HTML, and template / custom serializers for non-HTML targets.
Install only the packages you need. Each serializer is published under @slate-serializers/ on npm. The umbrella package slate-serializers re-exports the HTML and DOM serializers and their default configs—useful if you want a single dependency for server-side HTML ↔ Slate workflows.
DOM types and constructors
When you write custom transforms, import DOM types and constructors from the serializers — not from domhandler directly:
The same exports are available from slate-serializers and @slate-serializers/dom.
Packages at a glance
| npm package | Role |
|---|---|
| @slate-serializers/html | slateToHtml, htmlToSlate, and shared configs (depends on DOM internally). |
| @slate-serializers/dom | slateToDom — htmlparser2 DOM nodes before stringifying to HTML. Use when you need to inspect or tweak the DOM first. Docs |
| @slate-serializers/react | <SlateToReact /> for React output: same top-level keys as slateToHtml, plus elementTransforms for React nodes. |
| @slate-serializers/template | slateToTemplate — top-level nodes as HTML strings or custom serializers (e.g. JSX). Docs |
| @slate-serializers/utilities | Small helpers (e.g. style object handling) used by the serializers; rarely needed directly unless you extend them. |
| slate-serializers | Meta package: re-exports htmlToSlate, slateToHtml, slateToDom, and related configs from the HTML/DOM packages. |
Install
Minimal examples
HTML round-trip:
React output:
Slate version
These packages target Slate's modern document model (Slate ≥ 0.50). This site uses Slate ~0.101 and slate-react ~0.101 with @slate-serializers/* ^2.7.0.
slateToHtmlConvert Slate JSON to HTML.
htmlToSlateConvert HTML to Slate JSON.
slateToReactConvert Slate JSON to React.
slateToTemplateConvert Slate JSON to an array of HTML strings mixed with custom serializers (e.g. JSX).
slateToDomConvert Slate JSON to a
htmlparser2DOM before serializing to HTML—useful when you need to manipulate the tree first.