Code Syntax Highlighter

Create beautiful, shareable images of your code snippets instantly.

Preview
PNG size

Rate this tool

How useful was this tool?

Code Syntax Highlighter

Paste a snippet into Code, or load the Example, and the Preview shows it as a finished image: highlighted code in a window, on a background of your choice. Under the code box, a line tells you what the tool sees, such as 7 lines, 226 characters; detected as JavaScript.

When it looks right, you can:

  • Download PNG at the size you choose, or Copy image straight to the clipboard.
  • Download HTML for a standalone page with the highlighted code.
  • Copy HTML to get the code with its colours written inline, ready to paste into a blog post or document.

Everything happens in your browser. Nothing is uploaded, and no third-party scripts are loaded.

Example

The Example loads a short JavaScript function:

async function fetchUser(id) {
  const res = await fetch(`/api/users/${id}`);
  if (!res.ok) throw new Error(`HTTP ${res.status}`);
  return res.json(); // { name, email }
}

fetchUser(42).then(user => console.log(user.name));

with these settings:

  • Language: Detect automatically, which gives JavaScript.
  • Theme: Atom One Dark.
  • Background: Violet to pink.
  • Font: Fira Code at 14 px.
  • Padding: 48 px. Corners: 12 px.
  • Title: fetch-user.js, with Title bar with window buttons and Shadow on.

The preview shows a dark window with three coloured buttons and the file name, on a violet-to-pink gradient. Keywords such as async, const and return are purple, function names blue, and strings green. The comment is faded and in italics.

The settings

Language. Leave it on Detect automatically, or pick one of the 54 languages yourself, from JavaScript to Dockerfile. Detection is a guess, and it gets better with longer snippets. Two lines of code can look like several languages, so pick the language yourself when the colours look wrong.

Theme. There are 16:

  • Dark: Atom One Dark, GitHub Dark, Monokai, Nord, Visual Studio Dark, Tokyo Night Dark, Stack Overflow Dark, Android Studio, A11y Dark and Solarized Dark.
  • Light: Atom One Light, GitHub Light, Tokyo Night Light, Stack Overflow Light, A11y Light and Solarized Light.

The two A11y themes are high contrast, the best choice when the image needs to be readable for everyone.

Background. One colour, Violet to pink, Ocean, Sunset, Forest, Graphite, Candy, or Transparent. A transparent PNG sits cleanly on a slide or a page of any colour.

Font. Fira Code or your system’s monospace font, from 12 to 20 px. Fira Code joins some character pairs into single symbols, called ligatures: => becomes an arrow, and != a crossed equals sign. That looks tidy, but if you’re teaching beginners, who need to see exactly which characters to type, choose System monospace.

Padding and Corners set the space around the window and how rounded it is.

Title sets the text in the title bar, usually the file name. Caption adds an optional line under the code, for example a source or a short explanation.

Title bar with window buttons, Line numbers and Shadow turn those parts on or off. Line numbers are worth adding whenever your text refers to “line 3”.

Image or HTML?

For social media, slides and chat, use the image. PNG size offers 1x, 2x (sharp on phones and retina screens) and 3x. 2x is right for most uses. 3x is for large screens and printing, but each step makes the file noticeably bigger. Copy image puts the picture on the clipboard, ready to paste into a chat, an email or a document. It’s drawn from exactly what you see in the preview.

For blog posts and documentation, use HTML. Readers can then select and copy the code, search engines can read it, and screen readers can read it aloud. None of that works with an image. Copy HTML gives you the code with its colours written into each piece, so it keeps them when pasted into a rich-text editor or a CMS’s HTML block. Download HTML saves a whole page with the highlighted code and the theme’s colours.

Making code images easy to read

  • Keep it short. A code image works best at about 15 lines or fewer. Longer code belongs in a text block or a link to the full file.
  • Keep lines short. Long lines make the image wide, and the text shrinks when it’s shown on a phone.
  • Use 14 px or more if the image will mostly be seen on phones.
  • Add alt text when you post the image, with the code itself or a short description of it. People using screen readers can’t read the picture.
  • Check the contrast. Comments in some themes are faint by design. The A11y themes are easiest to read.

FAQ

Which languages are supported?

54, including JavaScript, TypeScript, Python, PHP, HTML, CSS, SQL, JSON, YAML, Bash and Dockerfile. Leave the language on Detect automatically, or choose it from the list.

Why are => and != shown as single symbols?

That’s Fira Code’s ligatures, as described under “The settings” above. The characters themselves are unchanged, and anything copied from the HTML still has two separate characters. To show them separately in the image, choose System monospace.

Is my code uploaded anywhere?

No. Highlighting, the image and the HTML are all made in your browser, and the page loads no third-party scripts.

Is this the same as formatting code?

No. Highlighting colours the code as it is. To fix indentation and layout first, run it through the JS Formatter, the CSS Formatter or the HTML Formatter. To try HTML with a live preview, use the HTML Code Editor.

Note: All processing is done client-side. We do not store or see your data.

Contact

Missing something?

Feel free to request missing tools or give some feedback using our contact form.

Contact Us