The simplest way to keep colors when you copy code
When you copy code from a syntax-highlighted editor or website, the colors usually disappear because you are copying only the text, not the formatting. To keep the colors, you need to copy the formatted text instead — which means copying as rich text rather than plain text, or taking a screenshot, or using a tool built for sharing colored code.
The method that works depends on where the code lives and where you want to paste it. A document editor like Google Docs or Microsoft Word will accept colored text directly. A plain-text editor like Notepad will not. A chat app like Slack has its own code formatting. A blog or website needs HTML or an image.
Key Takeaways
- Copying from a code editor to a word processor preserves colors if you paste as rich text, but pasting into plain-text editors strips formatting automatically.
- Screenshot tools like Snagit, ShareX, or your operating system's built-in screenshot let you capture colored code as an image, which works anywhere but is not searchable or editable.
- Code-sharing sites like GitHub Gist, Pastebin, and Carbon.now.sh let you paste code once and generate a shareable link with colors intact.
- HTML export from your editor preserves colors as web-ready code that you can paste into blogs, wikis, or websites.
- Slack, Discord, and Teams have built-in code formatting that adds colors without needing to copy from elsewhere.
Copy and paste into word processors and documents
If you are pasting into Google Docs, Microsoft Word, Apple Pages, or similar, select the code in your editor and copy it normally. When you paste, use Paste Special or Paste and Match Formatting — the exact name varies by program. In Google Docs, right-click and choose "Paste without formatting" if you want plain text, or just paste normally to keep colors. In Word on Windows, use Ctrl+Shift+V to open Paste Special and choose "Formatted Text" or "HTML Format".
The colors will transfer because these programs store text as rich text, which includes color information. The font may change slightly depending on what fonts are installed on your computer, but the syntax highlighting colors will stay. This works from any code editor: VS Code, Sublime Text, PyCharm, Xcode, or a website with colored code.
Take a screenshot to preserve the exact appearance
A screenshot captures the code exactly as it appears on your screen, including colors, fonts, line numbers, and background. This is the most reliable way if you need the code to look identical, but the result is an image, not editable text.
On Windows, use the Snipping Tool (search for "Snipping Tool" in the Start menu) or Shift+Windows+S to open the screenshot menu. On Mac, press Shift+Command+4 and drag to select the area. On Linux, use Shift+Print Screen or open the built-in screenshot tool. You can also use third-party tools like Snagit (paid, cross-platform), ShareX (free, Windows), or Greenshot (free, Windows). These tools let you annotate, crop, and save in different formats.
Screenshots work anywhere — email, chat, documents, social media — but they cannot be searched, edited, or copied as text later. Use this method when appearance matters more than usability, such as showing someone exactly what an error looks like.
Use a code-sharing site to generate a colored link
Sites like GitHub Gist, Pastebin, Carbon.now.sh, and Replit let you paste code once and get back a link with colors built in. You share the link instead of copying the code itself.
GitHub Gist (gist.github.com) requires a GitHub account but is free. Paste your code, choose the language, and get a shareable link. The colors are preserved in the link, and anyone can view it in a browser or embed it on a website. Carbon.now.sh is designed specifically for making colored code look good — it lets you choose themes, fonts, and background colors, then generates a shareable link or downloads an image. Pastebin (pastebin.com) requires no account, detects the language automatically, and generates a link instantly.
This method is best when you want to share code with others or embed it on a website. The colors stay intact in the link, and the recipient can copy the plain text from the site if they need it.
Export as HTML to paste into websites and blogs
Most code editors can export highlighted code as HTML, which is the format websites understand. Open your code editor, select the code, and look for an export or copy option. In VS Code, install the Copy as HTML extension, then right-click and choose "Copy as HTML". In Sublime Text, use the menu: View → Syntax → Open all with current extension as HTML, then copy. In PyCharm, right-click the code and choose "Copy" — the HTML is copied automatically if you paste into a web editor.
When you paste HTML into a blog editor, website builder, or wiki, the colors appear because the HTML contains the color codes. This works in WordPress, Medium, Notion, Confluence, and most content management systems. The HTML includes <span> tags with color information, so the syntax highlighting survives the paste.
If your editor does not have an export option, you can use an online converter: paste your code into Hilite.me or Pygments, choose the language and theme, and copy the HTML output.
Format code directly in chat and messaging apps
Slack, Discord, Microsoft Teams, and similar apps have built-in code formatting that adds colors without needing to copy from an editor. You do not need to preserve colors from elsewhere — you create them in the app itself.
In Slack, type three backticks, press Enter, choose the language, paste or type your code, then close with three backticks. In Discord, use the same syntax: three backticks, language name, code, three backticks. In Teams, click the code icon in the message toolbar. These apps recognize common languages like Python, JavaScript, Java, and SQL, and apply appropriate colors automatically.
This is the fastest method if you are sharing code in a conversation. The colors appear instantly, and the recipient can copy the plain text if needed.
When colors disappear and how to fix it
Colors disappear most often when you paste into a plain-text editor like Notepad, a terminal, or an email client that strips formatting. This is by design — these programs store only text, not formatting. If you need colors in these places, use a screenshot or a code-sharing link instead.
Colors can also disappear if you copy from a website that does not use real HTML colors — for example, a website that applies colors only with CSS and does not embed them in the copied text. In this case, try copying from the browser's developer tools instead: right-click the code, choose "Inspect" or "Inspect Element", then copy from the HTML panel. Or use a screenshot.
If you are pasting into a document and colors do not appear, check the paste method. Use "Paste Special" instead of regular paste, or try pasting into a different program first (like Word) and then copying from there. Some programs require you to paste as "Unformatted Text" first, then manually reapply colors — in that case, a screenshot or code-sharing site is faster.
Frequently Asked Questions
Does copying code as HTML work in all word processors?
No. Google Docs, Microsoft Word, and Apple Pages accept HTML and preserve colors. Older programs or plain-text editors strip the HTML and leave only text. If colors disappear after pasting HTML, the program does not support rich text — switch to a screenshot or code-sharing link instead.
Can I copy colored code from a website into my code editor?
You can copy the text, but the colors will not transfer because your editor applies its own syntax highlighting based on the language. Copy the plain text from the website, paste it into your editor, and the editor will color it automatically. If the website does not let you copy plain text, use your browser's developer tools: right-click, choose "Inspect", and copy from the HTML panel.
What is the best way to share colored code with someone?
If they need to edit it, use GitHub Gist or Pastebin — they can copy the plain text from the link. If they just need to see it, use a screenshot or Carbon.now.sh. If you are chatting, use your app's built-in code formatting. The best choice depends on what they will do with the code.
Why do some code editors not have an export option?
Simpler editors focus on editing, not exporting. If your editor lacks an export feature, copy the code and paste it into an online converter like Hilite.me, or use a screenshot. VS Code and most professional editors have extensions or built-in options for exporting as HTML.
Can I copy code with colors into an email?
Most email clients strip HTML formatting, so colors will disappear. Use a screenshot instead, or paste a link to a code-sharing site. Some email programs like Outlook support rich text — try pasting as HTML and see if colors survive. If not, a screenshot is more reliable.