DevTools Pro · All tools · About

Code Snippet Formatter

About the Code Snippet Formatter

This code snippet formatter turns plain code into a syntax-highlighted card with a theme, line numbers and an optional window frame, ready to export as a PNG image. It supports 22 languages and also copies the highlighted markup as HTML for blogs and docs.

Code image or code text: which to share?

Images of code look consistent everywhere, which is why they are popular in slides, social posts and newsletters. The trade-off is that readers cannot copy the code and screen readers cannot read it. When you post an image, put the code as text in an alt attribute, a caption or a linked gist too.

For documentation and blog posts, use Copy HTML instead. It gives you real text wrapped in <span class="token keyword"> style elements that any Prism.js theme stylesheet can color.

How the highlighting works

Highlighting uses Prism.js grammars, which split code into tokens such as keywords, strings, numbers, functions and comments. Each theme assigns a color to each token type. The available themes are Dracula, Monokai, Nord, GitHub Light and Brutal Yellow.

The PNG export renders the preview card at 2x resolution, so text stays sharp on high-density screens and in slide decks. Snippets wider than the preview are captured in full, not cropped.

Tips for a readable code screenshot

Keep snippets short, ideally under 20 lines, and aim for lines under about 80 characters so the image does not need to be scaled down. Use Remove common indent when you paste a block copied from inside a function, so it does not start halfway across the card.

Set the file name in the window title (for example debounce.ts) to give readers context, and turn line numbers on when you will refer to specific lines in your text.

How to Use the Code Snippet Formatter

  1. Paste your code into the Code & options box. Click Remove common indent if every line starts with extra spaces.
  2. Pick the Language and a Theme.
  3. Type a File name / title, adjust Font size (10-22 px), and toggle Line numbers and Window frame.
  4. Check the Preview, which updates as you type.
  5. Click Export PNG to download the image, or Copy HTML / Copy code to grab the snippet as text.

Frequently Asked Questions

Is my code uploaded to make the image?
No. Highlighting and PNG rendering both happen in your browser. Your code is never sent to a server.
Does it format or re-indent my code?
It highlights code as written and can remove indentation shared by all lines. It does not reformat code; use the Code Beautifier first if the layout itself needs fixing.
Why are tabs converted to spaces?
Remove common indent converts tabs to two spaces so that tab and space indentation can be compared and trimmed evenly.
Can I use a white background?
The card always uses the background of the selected theme. Choose GitHub Light for a white card, or Brutal Yellow for a light warm one.
How do I use the copied HTML?
Paste it into your page and include any Prism.js theme CSS. The markup uses standard Prism token classes such as token keyword and token string.
Which language should I pick for Vue or Svelte files?
Use HTML / XML for the template part. There is no dedicated Vue or Svelte grammar, so script blocks inside them are not highlighted as JavaScript.

Related tools