Guide

How to Convert Markdown to DOCX (Word)

Updated

Run pandoc input.md -o output.docx. Pandoc writes a real Word document: Markdown headings become Word heading styles, tables become Word tables, and footnotes become Word footnotes. To control fonts and spacing, export Pandoc's reference document, restyle it in Word, and pass it back with --reference-doc. Unlike PDF output, no LaTeX install is needed.

Markdown to Word in five steps

  1. 1

    Install Pandoc

    Word output is built into Pandoc. Unlike PDF, it needs no LaTeX or other engine.

  2. 2

    Convert the file

    pandoc input.md -o output.docx. The .docx extension selects Word output.

  3. 3

    Export the default reference document

    pandoc -o custom-reference.docx --print-default-data-file reference.docx writes the style sheet Pandoc uses.

  4. 4

    Restyle it in Word

    Open custom-reference.docx, change the styles (Heading 1, Body Text, Title, Table and so on), not the text, and save.

  5. 5

    Convert with your styles

    pandoc input.md -o output.docx --reference-doc=custom-reference.docx. Every document now comes out in your fonts, colours and spacing.

What each Markdown element becomes in Word

Pandoc maps Markdown to named Word styles rather than hard-coding formatting. That's why the reference document works: change a style once and every document that uses it follows.

MarkdownIn the .docx
# Heading, ## Heading Heading 1, Heading 2 (real Word heading styles, so the navigation pane and a Word TOC work)
YAML title: and author: Title and Author styles at the top of the document
Paragraphs First Paragraph for the first one after a heading, Body Text after that
Pipe tables Word tables using a style called Table; column alignment is kept
Fenced code blocks Source Code style, with syntax colouring applied as character styles
> Blockquotes Block Text style
[^1] footnotes Real Word footnotes at the bottom of the page
$math$ Native Word equations
Links Clickable hyperlinks in the Hyperlink style
Images Embedded in the .docx (if Pandoc can find the file)

Worked example: a house style for client documents

Say every proposal you send has to use the client-facing font and your brand colour for headings. Do it once:

pandoc -o custom-reference.docx --print-default-data-file reference.docx

Open custom-reference.docx in Word. In the Styles pane, modify Heading 1 and Heading 2 (font, colour, spacing), Body Text and First Paragraph (body font and line spacing), Title, and the Table style. Save. Then:

pandoc proposal.md -o proposal.docx --reference-doc=custom-reference.docx

Add --toc if you want a table of contents. Pandoc inserts a Word TOC field, which Word fills in when fields are updated.

Where this goes wrong: formatting text directly instead of editing styles. If you select a heading in the reference document and make it bold and blue, nothing changes in the next conversion, because Pandoc copies the style definitions, not the formatting on the sample text. Right-click the style and choose Modify. A mistyped path fails loudly, at least: File 'missing.docx' not found in resource path, and no output is written.

What doesn't make it across

Inline HTML styling
A <div style="color:red"> keeps its text but loses the colour. Word output ignores HTML styling.
Task-list checkboxes
- [ ] becomes a ☐ character in a bullet list, not a clickable Word checkbox.
Images Pandoc can't find
Pandoc warns "Could not fetch resource img/x.png: replacing image with description" and still writes the file, with the alt text where the image should be. Relative paths resolve from the folder you run the command in.
Your Markdown editor's theme
The look comes from the reference document, not from how the file looked in your editor's preview.

GitHub-flavoured Markdown

Pandoc reads its own Markdown dialect by default, which covers tables, footnotes and task lists. If your files were written for GitHub and something renders oddly, tell Pandoc so with -f gfm: pandoc README.md -f gfm -o README.docx.

FAQ

Can I convert Markdown to Word without installing anything?
Online converters take a file upload and return a .docx. They're fine for one-off documents that aren't confidential. For anything you'll repeat, or anything under NDA, a local Pandoc install keeps the file on your machine and lets you reuse a reference document.
How do I make the Word file use my company's fonts and styles?
Use a reference document. Export Pandoc's default with --print-default-data-file reference.docx, edit its styles in Word, and pass it with --reference-doc. Pandoc copies styles from it, not content, so whatever text is in the file is ignored.
Will my tables, footnotes and equations survive?
Yes. Pipe tables become real Word tables (using the Table style), footnotes become Word footnotes, and LaTeX math like $E = mc^2$ becomes a native Word equation you can edit in Word's equation editor.
Can I convert the Word file back to Markdown?
pandoc output.docx -o back.md works and keeps headings, emphasis, links, lists, footnotes and tables. Expect some noise: tables may come back in a different Markdown table syntax, and images are extracted under media/ with explicit sizes.
Should I send clients a .docx or a PDF?
A PDF when the document is final, such as a proposal, a scope of work or a report, because it looks the same everywhere and can't be edited by accident. A .docx when the client needs to mark it up with tracked changes, typically a contract draft.

Related templates

← Back to home All templates All guides See pricing