How to paste code into Word without losing formatting

Microsoft Word strips indentation, ignores monospace fonts and shows zero colours when you paste code. Here's every method that exists to fix this — and which one actually works in 2025.

Contents
  1. Why Word breaks code formatting
  2. Method 1: Screenshots
  3. Method 2: Word's built-in code block
  4. Method 3: Paste special from an IDE
  5. Method 4: Online formatters like FormatCode
  6. Which method is best?
  7. Step-by-step with FormatCode

Why Word breaks code formatting

When you copy code from an IDE and paste it into Word, several things go wrong simultaneously:

Method 1: Screenshots

Method 01

Take a screenshot of your IDE

Press Ctrl+Shift+S (or use Snipping Tool), capture the code, paste the image into Word.

Speed: Fast Quality: Medium Editable: No Searchable: No
OK for quick, single-use docs

Images are not searchable, not copyable, don't scale cleanly and look blurry when printed. Any update requires a fresh screenshot.

Method 2: Word's built-in code block

Method 02

Insert → Styles → Code

Word has a "Code" character style that switches to a monospace font. No syntax highlighting.

Speed: Slow Quality: Low Editable: Yes
Not recommended

Method 3: Paste special from IDE

Method 03

Copy from VS Code → Paste Special → HTML Format

VS Code copies rich HTML to the clipboard. In Word: Edit → Paste Special → HTML Format.

Speed: Medium Quality: Fails
Looks promising but doesn't work

VS Code's HTML uses CSS classes with a stylesheet. Word ignores the stylesheet and only reads inline style="" attributes — so colours disappear. Indentation also collapses because VS Code uses regular spaces.

Method 4: Online formatters — FormatCode

Method 04 — Recommended

Use FormatCode to generate Word-compatible HTML

FormatCode converts code to HTML with inline styles, solid colours, and non-breaking spaces that Word reads correctly.

Speed: Very fast Quality: High Editable: Yes Free: Yes
Best overall — recommended

Which method is best?

For anything beyond a three-line snippet, Method 4 is the only reliable approach. Screenshots are non-editable. Word's code style has no colours. IDE copy-paste loses colours and indentation. A purpose-built formatter is the only tool that solves all problems at once.

Key insight: Word's HTML renderer only respects style="color:#hex" inline attributes, not CSS classes or variables. Any tool that generates code with CSS classes (including VS Code's native copy) will lose colours in Word.

Step-by-step guide with FormatCode

  1. Go to formatcode.app
  2. Paste your code into the left panel
  3. Select your programming language (or use Auto-detect)
  4. Choose a background colour
  5. Click Copy for Word
  6. In Word: press Ctrl+V, choose Keep Source Formatting if prompted

Try FormatCode now — it's free

Paste your first snippet and copy it to Word in under 30 seconds.

Open FormatCode →