What is a code highlighter?
A code highlighter turns plain text code into colored code: keywords in one color, strings in another, comments dimmed. This one produces three things from the same snippet. The first is HTML with every color written as an inline style, so it pastes into an e-mail, a CMS, a slide or a blog editor without any stylesheet. The second is a PNG image, handy for social posts, slides and documents that cannot hold formatted text. The third is a fenced Markdown block with the right language tag.
You choose among 40 languages, from JavaScript, TypeScript, Python, Java and Go to SQL, Bash, YAML, Dockerfile, Nginx and Diff, or leave "Detect automatically" on. Detection tries about twenty common languages, and JSON is recognised by actually parsing it, because short JSON is easy to mistake for CSS. There are eight themes, light and dark: Stdlib light and dark, GitHub light and dark, Monokai, Dracula, Sepia and Nord.
The coloring is done by highlight.js in your browser, each language loaded only when needed, and the PNG is drawn on a canvas on your device. The code is never uploaded.
How to highlight and export code
- Paste your snippet into the "Code" box. The page starts with a small TypeScript example.
- Pick the "Language", or keep "Detect automatically". The line under the box tells you "Detected: ..." or "Language: ...".
- Choose a "Theme". Each button shows a small preview of its colors.
- Adjust the look: "Line numbers", "Window dots" (the three window-style circles at the top), "Font size" (10 to 28 px), "Padding" (0 to 64 px) and "Corner radius" (0 to 32 px). The "Preview" updates immediately.
- Under "Export as", choose a tab. "HTML" gives the code with inline styles in the "HTML with inline styles" box. "Markdown" gives a fenced block.
- For "PNG", pick the "Image size" (1x, 2x or 3x), then press "Download PNG" or "Copy image".
- Press "Copy" for the HTML or Markdown. To tidy the code before coloring it, use "Format the code first".
Examples
A Markdown block
Code const total = 1 + 2; with the language set to JavaScript, exported as "Markdown", becomes three lines: an opening fence of three backticks followed by javascript, then your code, then a closing fence of three backticks. Language tags follow common usage: HTML / XML becomes html, and "Plain text" has no tag. If the code itself contains a run of three backticks, the tool opens and closes the block with four, so the Markdown does not break.
HTML that carries its own colors
The "HTML" tab returns one pre element with code inside. Each colored word is a span such as <span style="color:#...">const</span>, and the box has the background, border, padding and rounded corners of the theme. Words with the default text color stay unwrapped. Since nothing refers to a class or a file, you can paste it into an e-mail signature or a CMS block as it is.
The size of a PNG
Take 3 lines of code at the defaults: font 14 px, padding 20 px, no "Window dots". The line height is 22 px (1.6 times the font), so the image is 20 + 66 + 20 = 106 px tall. At "2x" the file is 212 px tall. Turning on "Window dots" adds a 36 px title strip, so it becomes 142 px at 1x. The width depends on the longest line and on the width of the monospaced font in your browser.
JSON detection
The text {"id": 7, "tags": ["a", "b"]} is detected as JSON, because it parses. A broken version, such as one with a missing closing brace, goes through normal detection and may be guessed as something else. In that case choose "JSON" yourself.
Common mistakes
- Trusting detection on short snippets. Two lines can look like several languages. Choose the language when the colors look wrong.
- Pasting code that is too long. Above 200,000 characters the preview refuses to run. Paste the part you want to show.
- Making a PNG that is too big. The picture cannot pass 8,000 px on a side after scaling. Use "1x" or fewer lines.
- Forgetting the long lines. Code is not wrapped in the image, so a very wide line makes a very wide picture. Format the code first.
- Using the HTML where scripts are stripped. Some editors remove
styleattributes. If colors vanish, use the PNG or a Markdown block. - Choosing a theme without looking at the page around it. The image and the HTML block carry their own background. Check that the box stands out where you paste it.
Frequently asked questions
Does the HTML need a stylesheet or a script?
No. The colors are inline styles, with no classes, scripts or external files, so it works wherever HTML is accepted and styles are kept.
Is my code sent to a server?
No. Highlighting and image drawing happen in your browser. You can use it on private code.
Can I copy the image instead of downloading it?
Yes, press "Copy image" on the PNG tab. If your browser refuses, the tool says so and you can use "Download PNG".
Which languages are supported?
Forty, listed in the "Language" menu, including web languages, systems languages, data formats, shell and configuration files such as Dockerfile and Nginx.
Can I clean up the code before coloring it?
Yes. Use the code beautifier, or shrink it with the minifier. The "Continue with" chip carries the code to the formatter.