Developer and Text Tools

How to Share Code Beautifully: Highlighted HTML and Code Images

Turn source code into syntax-highlighted HTML for blogs and docs, or a crisp SVG or PNG image for slides and social posts, with themes and line numbers.

Saizul Amin
Saizul Amin30 Oct 2026 · 3 min read
How to Share Code Beautifully: Highlighted HTML and Code Images

How to Share Code Beautifully: Highlighted HTML and Code Images

Code is easier to understand when keywords, strings, numbers and comments stand out from each other. Every editor does this, but the colours disappear the moment you paste code into a blog post, an email, a slide or a social post. The free Code Syntax Highlighter restores them. It produces self-contained highlighted HTML for web pages and documentation, or an SVG or PNG image for places where only pictures survive.

HTML or image?

Choose the format by asking whether readers will want to copy the code.

  • HTML keeps the code as text. Readers can select and copy it, search engines can index it, and screen readers can read it aloud. Use HTML for blogs, documentation, knowledge bases and email clients that support inline styles. The output uses inline colours, so it needs no stylesheet or JavaScript and looks the same wherever you paste it.
  • Images look identical everywhere, including slide software, chat apps, social networks and printed handouts. The trade-off is that readers cannot copy the code. When you post a code image, link to the source or a gist as well.

SVG images stay sharp at any zoom level and are small for short snippets. PNG is the safest choice for social networks and presentation tools that do not accept SVG.

Themes

Four themes cover most needs: a light theme for documents and printed pages, a dark theme similar to popular editors, the warm Monokai palette, and the low-contrast Solarized light palette. Pick a theme that matches the background where the code will appear. Dark images on a white slide can look heavy, and light code on a dark presentation can glare.

Line numbers and titles

Line numbers help when you refer to specific lines in a talk or a tutorial ("on line 12 we open the connection"). Leave them off for short snippets that readers might copy, since numbers in HTML output can get in the way. For images, you can add a window title, such as the file name, shown in a simple title bar above the code.

Making code readable in a picture

A few habits make code images much more effective:

  • Keep it short. Ten to twenty lines is the most an audience can read on a slide. Cut boilerplate, imports and error handling that is not the point.
  • Keep lines narrow. Long lines force tiny text. Break lines at about 60 to 80 characters.
  • Use real names. Meaningful variable names explain more than any comment.
  • Highlight the change. If you are showing a fix, show the before and after as two images side by side.

Accessibility

If you publish a code image, describe what the code does in the alt text or in the surrounding paragraph, because screen readers cannot read text inside a picture. Good contrast between the background and the code colours also helps readers with low vision.

How the highlighting works

The highlighter tokenises code by language rules: keywords, strings, comments, numbers, types and punctuation each get a colour. It supports thirty languages. Like most web highlighters, it uses lexical rules rather than a full compiler, so very unusual syntax or embedded languages, such as SQL inside a string, may be coloured as plain text. That rarely matters for readability.

Step by step

  1. Paste your code.
  2. Choose the language of the code.
  3. Pick a theme and decide on line numbers.
  4. Copy the HTML for a web page, or download an SVG or PNG image.
  5. Add the image or HTML to your post, slide or documentation.

Privacy

Highlighting and image rendering happen in your browser. Unpublished code and internal snippets are never uploaded.

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages