A collection of short, self-contained JavaScript articles and code snippets for learning everyday programming patterns in 30 seconds or less.
mwilliamson/mammoth.js
A JavaScript library and CLI that converts .docx Word documents into clean, semantic HTML.
- Stars
- 6,330
- Forks
- 673
- Open issues
- 60
- Last commit
- 5 days ago
What is it?
Mammoth converts .docx files, such as those created by Microsoft Word, Google Docs and LibreOffice, into HTML. It relies on the semantic information in a document, such as paragraph styles, and ignores most visual formatting, so a paragraph styled as Heading 1 becomes an h1 element rather than a copy of its font and size.
It runs in Node.js and in the browser, and can be used through a library API or a command-line tool. Custom style maps let you map your own Word styles to HTML elements and classes, and a document transform hook lets you modify the parsed document before HTML is generated. Images can be inlined as data URIs or written to a separate output directory.
Because the output is not sanitised, untrusted input should be handled carefully. External file access is disabled by default. Ports for Python, Java/JVM and .NET are maintained as separate projects.
Key features
- 01Converts headings, lists, tables, images, links, footnotes and endnotes to HTML.
- 02Maps custom Word styles to HTML elements through style maps.
- 03Supports bold, italic, underline, strikethrough, superscript and subscript.
- 04Provides a CLI and a Node.js/browser library API.
- 05Extracts raw text from documents, ignoring formatting.
- 06Allows document transforms before HTML generation.
Use cases
- Importing Word-authored articles or documentation into a website or CMS.
- Previewing .docx content in a browser without a Word install.
- Batch converting Word files to HTML in a Node.js build or server pipeline.
Quick start
- 1
Install the library from npm
npm install mammoth - 2
Convert a .docx file to HTML with the CLI
mammoth document.docx output.html
Things to know
- Mammoth performs no sanitisation of source documents, so untrusted input needs care.
- Conversion is unlikely to be perfect for complicated documents because .docx and HTML structures differ.
- Markdown output is deprecated.
Topics
FAQ
- What is mammoth.js?
- A JavaScript library and CLI that converts .docx Word documents into clean, semantic HTML. Mammoth converts .docx files, such as those created by Microsoft Word, Google Docs and LibreOffice, into HTML. It relies on the semantic information in a document, such as paragraph styles, and ignores most visual formatting, so a paragraph styled as Heading 1 becomes an h1 element rather than a copy of its font and size.
- Is mammoth.js free to use? What license does it have?
- mammoth.js is open source under the BSD-2-Clause license. Check the license terms before using it in commercial products.
- Is mammoth.js still maintained?
- Actively maintained. The last commit to mammoth.js was on Oct 16, 2026.
- What can I use mammoth.js for?
- Importing Word-authored articles or documentation into a website or CMS. Previewing .docx content in a browser without a Word install. Batch converting Word files to HTML in a Node.js build or server pipeline.
- How do I install mammoth.js?
- Install the library from npm: npm install mammoth Convert a .docx file to HTML with the CLI: mammoth document.docx output.html
- Where can I get mammoth.js?
- The source code and installation instructions are on GitHub: https://github.com/mwilliamson/mammoth.js
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A framework for building cross-platform desktop apps with JavaScript, HTML and CSS, based on Node.js and Chromium.
Node.js is an open-source, cross-platform JavaScript runtime for running JavaScript outside the browser.
A fast all-in-one JavaScript and TypeScript toolkit: runtime, bundler, test runner, and package manager in a single executable.
A progressive Node.js framework for building efficient, scalable server-side applications in TypeScript or JavaScript.
Fast, unopinionated, minimalist web framework for Node.js for building web apps and HTTP APIs.