---
id: html2docx
version: "1.6.0"
license: MIT
license_treatment: permissive
maintenance: dormant
---
# html2docx — Convert valid HTML input to docx.
License: permissive · Maintenance: dormant · Downloads: 119.7K/mo
## What it is and what it does
html2docx is a Python library that transforms valid HTML documents into Microsoft Word (.docx) files. It takes HTML as input and returns a BytesIO object containing the Word document, which you can then write to disk or process further. The package wraps python-docx for document generation and tinycss2 for CSS parsing, handling the translation from web markup to Office Open XML format.
The library is straightforward to use: read or construct your HTML, pass it to the html2docx() function with optional metadata like a title, and get back a binary buffer ready to save. It is marked Production/Stable and supports Python 3.7 through 3.10, though maintenance has been dormant since early 2023. The main constraint is that your HTML must be valid; the package does not attempt to repair or work around malformed markup.
Use it for:
- Export HTML reports or templates generated by a web application into Word documents for distribution or archival.
- Convert email HTML content to .docx files for offline storage or sharing with non-technical users.
- Generate Word documents programmatically from HTML templates in data processing or document generation pipelines.
- Build a document conversion microservice that accepts HTML and returns downloadable .docx files.
- Transform HTML documentation or help content into Word format for print or formal distribution.
## Worth the install?
AI-flagged interpretation of the facts above — verify before relying.
Converts valid HTML to Microsoft Word (.docx) format, returning a BytesIO object that can be written to disk or processed further.
Yes, if you need straightforward HTML-to-Word conversion and can work with valid HTML input. The low install friction, permissive MIT license, and Production/Stable status make it a reasonable choice. However, dormant maintenance (last release January 2023) means you should verify that it works with your specific HTML/CSS requirements and check for any compatibility issues with current versions of its dependencies before committing to production use.
## Install
pip install html2docx
uv add html2docx
poetry add html2docx
## Installing html2docx
Before you install: Low friction installation with only two runtime dependencies (python-docx and tinycss2). Maintenance is dormant—last release was 2023-01-19 and last commit 2024-01-16—but the package is marked Production/Stable and the repository remains active and unarchived.
License in practice: MIT license is permissive, allowing commercial and private use with minimal restrictions; you may use, modify, and distribute the package freely provided you include the license notice.
Quickstart:
pip install html2docx
from html2docx import html2docx
with open("my.html") as fp:
html = fp.read()
buf = html2docx(html, title="My Document")
with open("my.docx", "wb") as fp:
fp.write(buf.getvalue())
HTML input must be valid; malformed HTML will cause conversion to fail.
Verify before relying:
- What HTML features and CSS properties are actually supported by the conversion (the fact sheet does not detail the scope of HTML/CSS handling).
- Whether tinycss2 dependency is used for CSS parsing and what styling limitations exist in the output.
- Current compatibility with recent versions of python-docx and tinycss2.
## Package facts
- License: MIT (permissive)
- Python support: supports_current
- Install friction: low
- Maintenance: dormant
- Downloads: 119.7K/month (top 15,000 on PyPI)
- Known vulnerabilities: none known
## Tags
html to docx conversion, convert html to word document, html to microsoft word, generate docx from html, html document export, create word files from html, html2docx, document-generation, format-conversion
[View on SkillFed](https://skillfed.io/packages/html2docx) · [View on PyPI](https://pypi.org/project/html2docx/)