Getting started
docx-viewer is one <docx-editor> web component plus six thin framework adapters. This page installs an adapter, mounts the editor and loads and saves a document. It is Stable under the stability policy, with a preservation guarantee, but it is not Microsoft Word parity (see the support roadmap).
1. Install
Install the self-contained package for your framework. It bundles the editor UI and adapter and brings docx-core (the document model) with it.
npm install docx-react-viewer reactnpm install docx-vue-viewer vuenpm install docx-angular-viewernpm install docx-svelte-viewer sveltenpm install docx-solid-viewer solid-jsnpm install docx-vanilla-viewerInstall docx-core on its own only for headless use (parse and serialize without an editor).
2. Mount the editor
Every adapter mounts the same <docx-editor> element. Pass a DocumentModel, listen for changes and give the container a height.
import { useState } from 'react';
import { createDocument, WordEditor } from 'docx-react-viewer';
export function Editor() {
const [model, setModel] = useState(() => createDocument());
return (
<div style={{ height: '100vh' }}>
<WordEditor documentModel={model} onDocumentChange={setModel} />
</div>
);
}The other frameworks use the same options: see the framework guides and the binding contract.
3. Load and save files
The component ref (or the vanilla handle) exposes load(bytes) and save(). Loading detects DOCX and legacy .doc. Password-protected files open only through loadDocument(bytes, { password }) from ooxml-core/docx/load; the element's load() takes no password, so it reports such a file as document-error.
Loading is bounded by size limits that guard against zip bombs: 50 MiB compressed, 5,000 parts, 200 MiB inflated and 25 MiB for word/document.xml. A host that expects larger documents passes limits to loadDocx(bytes, { limits }) or loadDocument(bytes, { limits }), for example { maxDocumentPartBytes: 100 * 1024 * 1024 }; DEFAULT_DOCX_LOAD_LIMITS lists the defaults, and saving keeps the limits the document was loaded with.
const bytes = new Uint8Array(await file.arrayBuffer());
await editor.load(bytes);
// After edits:
const blob = await editor.save(); // Blob of the serialized .docxdirty and the dirty-change event report unsaved edits. See the element API for every property, method and event.
4. Try it
- The live demos run the same editor in every framework adapter.
- To run the demo from a clone of the repository (Bun required):
bun install # from the repository root
cd viewers/docx
bun run demo