HTML fragments → native Word documents
dom-docx maps semantic HTML to real OOXML — paragraphs, lists, tables, and links you can edit in Word. Try the live converter in your browser; no upload, no API key.
import { writeFile } from "node:fs/promises";
import { convertHtmlToDocx } from "dom-docx";
const html = `<h1 style="color:#1a1a2e">Quarterly Report</h1>
<p>Revenue grew <strong>12%</strong> year over year.</p>
<ul>
<li>North America</li>
<li>EMEA</li>
</ul>`;
const docx = await convertHtmlToDocx(html);
await writeFile("output.docx", docx);
import { convertHtmlToDocx } from "dom-docx/browser";
const html = `<h1 style="color:#1a1a2e">Quarterly Report</h1>
<p>Revenue grew <strong>12%</strong> year over year.</p>
<ul>
<li>North America</li>
<li>EMEA</li>
</ul>`;
const blob = await convertHtmlToDocx(html, {
styleSource: "inline",
});
# convert an HTML fragment file
npx dom-docx report.html -o report.docx
# or pipe from stdin
cat fragment.html | npx dom-docx - -o -
# stylesheet/class HTML (needs playwright installed)
npx dom-docx input.html -s computed
# prefer it on your PATH?
npm install -g dom-docx
Built for agents and apps
Word-friendly HTML in, editable .docx out
- Live demo Paste HTML and download a .docx — conversion runs client-side via the dom-docx browser bundle.
- Showcase gallery Financial statements, essays, dashboards, React apps, and stylesheet layouts — each with a DOCX preview.
- Node or browser npm package for servers; IIFE bundle for in-app “Export to Word” — computed styles use the live DOM, not Playwright.
Why dom-docx exists
It started as a question: could an autoresearch loop brute-force its way to a higher-fidelity HTML→DOCX converter? 40+ real-world test cases, a machine-scored fidelity loop and a lot of testing later, dom-docx achieved layout fidelity in the mid-90s percent versus the mid-60s for the established libraries.
Read the origin storyJoin the dom-docx waitlist
A hosted DOCX conversion API and more are on the roadmap. Leave your email for early access.
hmr-serve
Preview live HTML while you build it, then hand the HTML to dom-docx for an editable Word file. Hot-reload any folder in the browser.