How to Share Code as an Image and Keep It Accessible
Updated December 2026
Written by the Toolpuffin team. Tools in this guide are tested in the browser.
A picture of code is handy for a slide or a social post, where pasted code loses its layout. But an image of text has drawbacks: it cannot be copied, and a screen reader cannot read it without help. This guide shows when to use an image, when to use text and how to make the image accessible.
When an image makes sense
- A slide or a post where code would lose its layout or colours.
- A short example, a few lines, that people only need to read.
- A place where you cannot paste formatted code.
For anything people may want to copy, such as a command or a long script, post the code as text or link to it, and use the image as an extra.
Why text in an image needs care
The W3C accessibility tutorial on images says that if an image is not a logo, you should avoid text in images. If you do use an image of text, the text alternative should contain the same words as in the image. WCAG success criterion 1.4.5 says that text, not images of text, should be used to convey information, except in a few cases.
Source: W3C WAI: Images tutorial
Source: W3C WAI: Images of text
Add alt text with the code
- Put the same code in the alt text, or in the text next to the picture, so everyone gets the same words.
- W3C notes that there is no need to start the alt text with words such as image or picture, because screen readers already announce an image.
- For a long script, link to the code as text instead of repeating all of it in the alt text.
- Keep secrets such as keys and passwords out of the picture.
Source: W3C WAI: Image tips and tricks
Make the image with the tool
The tool draws your code with simple colours, line numbers and a window bar, and gives you a PNG. The colours are basic and based on word patterns, so they will not match a full code editor. The first 200 lines are used, and very long lines make a wide image that is hard to read on a phone, so split long lines first.