A code snippet in a conference slide, a LinkedIn post about a handy one-liner, a tutorial thumbnail or an internal newsletter all have one thing in common: plain text will not look right. Social platforms strip formatting and indentation, slide software mangles tabs, and a raw screenshot of your editor comes with sidebars, tabs, your file tree and a random line from the minimap.
This guide explains when an image of code is the right choice and when it is not, what makes a code image readable at small sizes, and how to create one with syntax highlighting, a clean frame and a sharp export.
When an image is the right choice
Images of code have a clear job: to be looked at, not copied. Good uses include:
- Slides and talks, where the audience reads from a distance and you control the layout.
- Social posts, where formatting and indentation are lost in plain text.
- Thumbnails and article headers, where the code is illustration.
- Printed material, such as posters and handouts.
Poor uses include documentation, answers to technical questions, bug reports and tutorials people follow step by step. There, readers need to copy, search and translate the code, and screen reader users need to hear it. Use text code blocks in those places, and if you do post an image, put the code as text alongside it.
What makes a code image readable
Fewer lines, larger text
A code image that works on a phone typically shows 5 to 20 lines. If your snippet is longer, cut it to the lines that matter and replace the rest with a comment such as // …. Keep lines short, ideally under about 60 to 70 characters, so the image does not become too wide to read when scaled down.
Font size and resolution
On slides, code usually needs a larger font than feels natural at your desk; test it from the back of a room if you can. For social media, export at 2x resolution so the text stays crisp on high-density phone screens, where a 1x image looks soft.
Contrast
Low-contrast themes look stylish at full size and become unreadable when compressed. Choose a theme where comments are still clearly legible and the background contrasts strongly with the main text.
Format it first
Consistent indentation and spacing matter more in an image, because nobody can reformat it. Run the snippet through the JavaScript Formatter or a formatter for your language first.
A short, image-friendly snippet looks like this:
function debounce(fn, wait = 300) {
let timer;
return (...args) => {
clearTimeout(timer);
timer = setTimeout(() => fn(...args), wait);
};
}
Create an image with Code to Image
Our Code to Image generator draws your code with syntax highlighting onto a canvas in your browser and exports a PNG.
- Open Code to Image. A sample
debounce.jssnippet is loaded. - Paste your code into Your code. Tabs and indentation are preserved.
- Choose the Language. Auto-detect usually works; pick one manually from the list (JavaScript, TypeScript, Python, HTML / XML, CSS, JSON, SQL, Bash / Shell, Java, C#, C / C++, Go, Rust, PHP, Ruby, YAML or Plain text) if the colours look wrong.
- Pick a Theme: Midnight, Dracula, Monokai, Nord or GitHub Light.
- Choose a Background: gradients such as Sunset, Ocean, Grape, Forest, Candy and Slate, plain White, or Transparent.
- Adjust Padding (0 to 128 px) and Font size (10 to 28 px).
- Turn Window controls on for a macOS-style title bar, and type a Window title such as a file name. Turn Line numbers on if you will refer to specific lines.
- Choose the export resolution (1x resolution, 2x (retina) or 3x) and click Download PNG, or Copy image to paste it straight into a slide or chat. Some browsers do not allow copying images; use the download in that case.
Keeping code images accessible
An image of code is invisible to screen readers and search engines unless you describe it.
- Write alt text that states the purpose, for example "JavaScript debounce function that delays calling fn until 300 ms after the last call". Reading every symbol aloud is rarely helpful.
- Provide the code as text in a link, a comment, the post body or a gist, so people can copy it.
- Avoid colour-only meaning. If you highlight a changed line, also mention it in the caption.
Other ways to make code images
Editor screenshots
A screenshot of your editor is quick. To make it presentable, increase the editor font size, hide the sidebar and minimap, and use a focus or zen mode. For framing and backgrounds afterwards, the Screenshot Beautifier adds padding and gradients to any screenshot.
Slide software
Presentation apps can hold code as text with a monospaced font. That keeps it editable and accessible in the slide file, but syntax colouring must be done by hand or pasted from an editor that copies rich text.
Editor extensions and online services
Many editors have extensions that export the selection as an image, and several web services do the same. They vary in themes and export options; the principles above apply to all of them.
Rendered HTML
For documentation sites, a syntax-highlighted HTML code block is better than any image. You can prototype one in the HTML CSS JS Editor.
Tips and pitfalls
Social platforms compress images
Platforms recompress uploads, which blurs fine text. Export at 2x, keep padding generous and avoid tiny font sizes. If a PNG is too large for a platform's limit, the Image Compressor can reduce it.
Transparent backgrounds
A transparent background looks great on slides with a matching colour, but some apps display transparency as black or white. Check it where it will be used, or choose a solid background.
Do not include secrets
It is easy to forget that a snippet contains an API key, internal hostname or customer email. Review every line before exporting; images are shared and copied widely.
Keep the source
Save the text of the snippet with the image. When you need to fix a typo later, recreating the image takes seconds if you have the code.
Frequently asked questions
What resolution should I export code images at?
Use 2x for social media and screens, and 3x if the image will be printed or shown on very large displays. 1x is fine only for small inline previews.
How many lines of code fit in a good code image?
Roughly 5 to 20 short lines stay readable on a phone. Longer snippets should be trimmed to the important part.
Can I copy the image directly into slides?
Yes, click Copy image and paste it into your presentation, if your browser allows copying images to the clipboard. Otherwise download the PNG and insert it.
Is it bad for accessibility to post code as an image?
It is when the image is the only copy. Add descriptive alt text and share the code as text somewhere readers can reach it.
Does the tool upload my code?
No. The image is drawn on a canvas in your browser, so your code never leaves your device.