DOCX Editor React component for Tailwind CSS v4
v1.0.0Added in 1.5.0
A React Word (.docx) editor with real pages, styles, tables, images, find and replace, comments and tracked changes, saved as .docx.
Click on a page to place the caret and type; drag, double-click (word) or triple-click (paragraph) to select, Shift+click to extend. Arrow keys move by the lines you see on the page; Tab inserts a tab and Escape moves focus to the toolbars. The formatting bar sets the paragraph style (each style previews in a card), the font (the document's own fonts first), the size (type it, or A- / A+, Shift+Ctrl / ⇧⌘ + < >), bold, italic, underline, strikethrough, superscript, subscript, text color, highlight, links (Ctrl / ⌘+K opens a bar: Enter applies, Escape cancels), alignment, lists, indent (Ctrl / ⌘ + [ ]), line and paragraph spacing, images (pick or drop one, then drag a corner to resize), tables (a 10 x 8 grid; inside a table a menu adds, deletes, merges and splits), page breaks (Ctrl / ⌘+Enter), borders and clear formatting. What does not fit folds into the ⋯ menu; on a phone the bar sits at the bottom, above the keyboard. Ctrl / ⌘+F finds (Enter / Shift+Enter step, 2 of 6), Shift+Ctrl / ⇧⌘+H replaces one or all. Select text and add a comment (Ctrl+Alt / ⌥⌘+M): cards sit beside the pages where they fit, in a panel otherwise, with replies, resolve and reopen; tracked changes have Accept and Reject. The mode menu switches Editing, Suggesting (your edits become tracked changes under author) and Viewing. Zoom with - and +, the zoom menu (fit width, fit page), Ctrl / ⌘ + scroll, pinch, or Ctrl / ⌘ + = / -. The sidebar lists live page thumbnails (Up / Down, Home / End). Save (Ctrl / ⌘+S, with onSave), download, print (Ctrl / ⌘+P) and open another .docx from the toolbar; opening one over unsaved edits asks first.
DOCX Editor is a Pro React component in the React media components category, written in TypeScript for React 19 and Tailwind CSS v4. It installs as source with npx wingo-ui@latest add docx-editor, together with Alert Dialog, Button, Color Picker, Dropdown Menu, Kbd and 6 more and the npm packages @eigenpal/docx-editor-core, prosemirror-state, prosemirror-view, prosemirror-model, prosemirror-history, prosemirror-tables, jszip and lucide-react.
Add to a project
Requirements: React 19 and Tailwind CSS v4, in Next.js (App Router or Pages), Vite or React Router. Installation guide · Next.js setup · Vite setup
npx wingo-ui@latest add docx-editorDOCX Editor is part of Pro, with 298 more Pro items: $8 a month or $150 once. 14-day refund before you download any Pro item. See plans
Usage
Import DocxEditor from @/components/ui/docx-editor.
import { useRef } from "react"
import { DocxEditor, type DocxEditorHandle } from "@/components/ui/docx-editor"
export function AgreementEditor() {
const editor = useRef<DocxEditorHandle>(null)
return (
<DocxEditor
ref={editor}
src="/demo/northwind-supply-agreement.docx"
author="Emma Carter"
height="80dvh"
onSave={async (blob, { fileName }) => {
const body = new FormData()
body.append("file", blob, fileName)
await fetch("/api/documents", { method: "POST", body })
}}
onDirtyChange={(dirty) => console.log(dirty ? "Unsaved changes" : "Saved")}
/>
)
}Props
srcdefault"/demo/northwind-supply-agreement.docx"stringURL of the .docx: same origin, a CORS-enabled URL or a blob: URL. Empty shows the open-a-document state. The playground value is the sample agreement.
fileNamedefault""stringName for downloads, onSave and the document's accessible label. Falls back to the last part of src or the opened file's name.
authordefault"You"stringThe name on comments you add and on suggestions made in Suggesting mode; its initials sit in the status bar.
defaultReadOnlydefaultfalsebooleanOpens in view-only mode: no caret, no formatting bar; Download and Print still work. The mode menu can switch back. Use readOnly to control it.
defaultSuggestingdefaultfalsebooleanOpens in Suggesting mode: insertions and deletions become tracked changes by author. Use suggesting to control it.
dirtydefaultfalsebooleanAdds your own unsaved state to the status bar. Switching it from true to false after you stored ref.exportDocx() marks the content as saved.
defaultZoomdefault"automatic"number | "fit-page" | "fit-width" | "automatic"The zoom each document opens at: a scale (1 is 100%) or a fit mode. Automatic fits the width up to 100%, so a phone shows the whole page width.
defaultSidebarOpendefaulttruebooleanOpens with the page thumbnails beside the pages. An editor narrower than 520px starts closed, since there the sidebar covers the page.
defaultDarkPagesdefaultfalsebooleanOpens with the pages inverted for reading at night; images keep their colors. Pages are white otherwise, in both themes.
webFontsdefaultfalsebooleanLoads metric-compatible fonts (Carlito for Calibri, Caladea for Cambria) from Google Fonts for closer line breaks. Off by default: no third-party requests.
localedefault"en-US"stringLocale for the dates on comments and changes. Unset, it follows the UIProvider locale, then the browser's (en-US here).
variantdefault"surface""surface" | "outline" | "plain"surface is a raised panel, outline a bordered box, plain has no frame for app panes that bring their own.
radiusdefault"md""none" | "sm" | "md" | "lg"Corner radius of the frame: 0, 12, 16 or 24px.
highlightColordefault"rgba(250, 204, 21, 0.45)"stringFill of every find hit (--docx-editor-highlight). Keep it translucent so the text stays readable.
activeHighlightColordefault"rgba(249, 115, 22, 0.5)"stringFill of the current find hit and of text waiting for a new comment (--docx-editor-active-highlight).
selectionColordefault"rgba(59, 130, 246, 0.28)"stringThe text selection drawn on the page (--docx-editor-selection).
showToolbardefaulttruebooleanThe document toolbar: thumbnails, page, mode, zoom, find, view switches, save and the ⋯ menu.
showFormatBardefaulttruebooleanThe formatting bar. Hidden in view-only mode; below 600px of width it moves to the bottom, above the keyboard.
showThumbnailsdefaulttruebooleanThe page thumbnails sidebar and its toggle.
showStatusBardefaulttruebooleanThe bottom line with the page, the word count, the mode and the saved state.
showCommentsdefaulttruebooleanComment cards, Add comment and their switch.
showChangesdefaulttruebooleanTracked change cards with Accept / Reject, their switch and Suggesting in the mode menu.
showDarkPagesdefaulttruebooleanThe dark pages switch (in the ⋯ menu when narrow).
showFinddefaulttruebooleanFind and replace, and Ctrl / ⌘+F inside the editor.
showImportdefaulttruebooleanOpen a document and New blank document in the ⋯ menu, and dropping a .docx onto the editor (not in view-only mode).
showDownloaddefaulttruebooleanDownload .docx with your edits (in the ⋯ menu when narrow).
showPrintdefaulttruebooleanPrint in the ⋯ menu and Ctrl / ⌘+P inside the editor.
showReadOnlyToggledefaulttruebooleanViewing in the mode menu, so people can switch to view-only themselves.
heightdefault640number | stringHeight of the editor: px as a number, or any CSS length ("100%", "80dvh") to fill a pane.
fileFile | Blob | ArrayBufferA document you already hold in memory; wins over src. A new object opens a new document.
readOnlybooleanControls view-only mode: no caret, no formatting bar, Download and Print still work. Pair it with onReadOnlyChange so the mode menu can switch it.
onReadOnlyChange(readOnly: boolean) => voidCalled when the mode menu or ref.setReadOnly switches view-only mode.
suggestingbooleanControls Suggesting mode. Pair it with onSuggestingChange so the mode menu can switch it.
onSuggestingChange(suggesting: boolean) => voidCalled when the mode menu switches Suggesting on or off.
zoomLevelsdefault"[0.5, 0.75, 0.9, 1, 1.1, 1.25, 1.5, 1.75, 2]"number[]Steps of the zoom menu and the - / + buttons. The first and last are the zoom limits.
sidebarOpenbooleanControls the thumbnails sidebar. Inline from 520px of editor width, an overlay below it.
onSidebarOpenChange(open: boolean) => voidCalled when the sidebar opens or closes.
onDirtyChange(dirty: boolean) => voidCalled when the document gets unsaved edits, and again when they are saved or undone.
onChange(details: DocxEditorChangeDetails) => voidCalled 400 ms after the last edit, with the page count, word count and dirty flag. Get the file with ref.exportDocx().
onSave(blob: Blob, info: DocxEditorSaveInfo) => (void | Promise<unknown>)Shows a Save button and binds Ctrl / ⌘+S. Gets the .docx and its file name, page and word counts. Return a promise to show Saving and then Saved, or the error.
onDocumentLoadSuccess(document: DocxEditorDocument) => voidCalled when a document is ready, with its page and word counts, comments and tracked changes.
onDocumentLoadError(error: unknown) => voidCalled when a document cannot be fetched or parsed. The editor shows the error state with Try again.
onError(error: unknown) => voidCalled when an export, a save, an image or a layout pass fails.
onDocxUpload(file: File) => voidCalled with the File someone opened or dropped.
onActivePageChange(pageNumber: number) => voidCalled with the page in view as you scroll or jump.
onCommentAdd(comment: DocxEditorComment) => voidCalled when someone adds a comment or a reply.
onCommentResolve(comment: DocxEditorComment) => voidCalled when a comment is resolved.
onChangeAccept(change: DocxEditorChange) => voidCalled when a tracked change is accepted.
onChangeReject(change: DocxEditorChange) => voidCalled when a tracked change is rejected.
toolbarActionsReactNodeYour own buttons at the end of the toolbar, before the ⋯ menu: share, send for signature, publish.
refRef<DocxEditorHandle> (a useRef object or an (handle) => void callback)exportDocx(), download(fileName?), getText(), insertText(text), focus(), undo(), redo(), scrollToPage(n), find(query), setReadOnly(readOnly), isDirty(), markSaved(), getPageCount() and getWordCount().
labelsPartial<DocxEditorLabels>Every string, English by default (DEFAULT_DOCX_EDITOR_LABELS): toolbar and menu names, tooltips, find and replace, comments and changes, states, the discard dialog. Strings with numbers are functions, like findResults(active, total), wordCount(words) and tableSize(rows, columns).
classNamesPartial<Record<"toolbar" | "formatBar" | "sidebar" | "thumbnail" | "viewport" | "page" | "annotation" | "statusBar" | "findBar" | "state", string>>Extra classes for the toolbar, the formatting bar, the sidebar, each thumbnail, the scrolling viewport, the pages, each card, the status bar, the find bar and the states.
classNamestringExtra classes for the frame, merged last. Other div props are forwarded to it.
Parts
DocxEditorHandle
typeWhat the ref gets: exportDocx(): Promise<Blob>, download(fileName?), getText(), insertText(text), focus(), undo(), redo(), scrollToPage(pageNumber), find(query) (opens find and returns the count), setReadOnly(readOnly), isDirty(), markSaved(), getPageCount() and getWordCount().
DocxEditorDocument
typeWhat onDocumentLoadSuccess receives: pageCount, wordCount, comments (DocxEditorComment[]) and changes (DocxEditorChange[]).
DocxEditorComment
typeA comment or reply: id, author, initials, date, text, anchorText (the commented passage), parentId (for replies) and resolved.
DocxEditorChange
typeA tracked change: id (the revision), kind ("insertion" | "deletion" | "replacement" | "formatting" | "structure"), author, date, text and deletedText.
DocxEditorChangeDetails
typeWhat onChange receives: pageCount, wordCount and dirty.
DocxEditorSaveInfo
typeThe second argument of onSave: fileName, pageCount and wordCount.
DocxEditorSource
typeWhat file accepts: File | Blob | ArrayBuffer.
DocxEditorZoom
typeA scale or "fit-page" | "fit-width" | "automatic".
DocxEditorMode
type"editing" | "suggesting" | "viewing", the three modes of the mode menu.
DocxEditorLabels
typeThe shape of labels: every string the editor renders.
DEFAULT_DOCX_EDITOR_LABELS
constantThe English labels. Spread it to translate a few strings.
Examples
Save with an unsaved indicator
onSave adds Save and Ctrl / ⌘+S; onDirtyChange drives the indicator above the editor.
Read-only, unlocked from outside
readOnly hides the formatting bar and the caret; Download and Print keep working.
Review: suggesting, comments, accept and reject
defaultSuggesting tracks edits as author; cards beside the pages accept, reject, reply and resolve.
Start from a blank page
Without src the editor offers to open a .docx or start a new blank document.
Your own toolbar actions, no sidebar
toolbarActions adds Share and Send for signature; showThumbnails={false} drops the sidebar.
Export to a Blob through the ref
ref.exportDocx() returns the edited .docx; its size, word and page counts show above.
On a phone
One-row toolbars, formatting at the bottom above the keyboard, fit-width pages and sheets for menus.
Dependencies
Files
- components/ui/docx-editor.tsx
FAQ
Is the React DOCX Editor component free?
The preview, props and docs are free; copying the source needs a Pro plan. See plans.
How do I install DOCX Editor?
Run npx wingo-ui@latest add docx-editor. It also adds the Wingo UI items it builds on (Alert Dialog, Button, Color Picker, Dropdown Menu, Kbd and 6 more) and the npm packages @eigenpal/docx-editor-core, prosemirror-state, prosemirror-view, prosemirror-model, prosemirror-history, prosemirror-tables, jszip and lucide-react. With shadcn, add the @wingo-ui registry with your API key, then run npx shadcn@latest add @wingo-ui/docx-editor.
How does DOCX Editor behave on phones?
What does not fit folds into the ⋯ menu; on a phone the bar sits at the bottom, above the keyboard.
See also
More React media components
Articles using this component
- React DOCX Viewer: Real Pages, Comments, Tracked Changes
Component guides9 min read
New components by email
New posts, product news and occasional offers from Wingo UI. We count clicks to keep it relevant.