How to Fix Word Pasting Code Without Syntax Colors
Question details
The user needs to paste programming code from a website into a document while retaining the original syntax highlighting, indentation, and capitalization.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- Copying code snippets from programming websites (such as W3Schools) and pasting them into a Word document.
- Observed behavior
- The pasted text appears as plain black text, losing all its original HTML syntax colors, indentation, and specific formatting.
Ensure your clipboard settings allow rich-text copying and check that your document is not currently restricted to plain-text formatting.
Use the Keep Source Formatting Paste Option
Force Word to retain the original HTML formatting and colors attached to your clipboard data.
By default, Microsoft Word might adjust pasted text to match the destination style. Using the 'Keep Source Formatting' option ensures that Word attempts to preserve the exact colors, bolding, and indentation provided by the website.
Highlight the desired code on the programming website and press Ctrl + C (or Cmd + C on Mac) to copy it.
Right-click on the exact spot in your Word document where you want to insert the code.
Under the 'Paste Options' menu, click the icon that features a paintbrush (Keep Source Formatting). Alternatively, paste the text using Ctrl + V, click the small clipboard icon that appears next to the pasted text, and select the 'Keep Source Formatting' icon.

Use a Rich-Text Editor as an Intermediary
Bypass clipboard limitations from specific websites by copying the code through another rich-text supported editor.
Use WPS Writer to Retain Code Syntax Colors
WPS Writer provides robust clipboard management, making it incredibly easy to paste programming code from websites while perfectly preserving the original syntax highlighting, indentation, and HTML layout.
- 1. Copy the Code Snippet: Select the formatted programming text from the website and copy it to your clipboard.
- 2. Open WPS Writer: Launch WPS Office and open your document in WPS Writer.
- 3. Paste with Source Formatting: Right-click your document, navigate to Paste Options, and choose 'Keep Source Formatting' to retain all syntax colors and indentation.

Frequently Asked Questions
Why does Word only offer the 'Keep Text Only' paste option for some web code?
This happens when the source website restricts its clipboard output to plain text. If the website's code block doesn't export HTML or rich-text data to your system's clipboard, Word has no color or formatting information to retrieve.
How do I set 'Keep Source Formatting' as my default paste option?
In Word, go to File > Options > Advanced. Scroll down to the 'Cut, copy, and paste' section. Change the setting for 'Pasting from other programs' to 'Keep Source Formatting' and click OK.
Why do some parts of a webpage paste with colors while others do not?
Different sections of a website can be developed using varying HTML structures. For instance, an interactive code terminal might use custom JavaScript that copies plain text, whereas a static preformatted text block might allow native HTML rich-text copying.




