Code Screenshot Generator

Paste a snippet, pick a language and theme, and export a syntax-highlighted PNG for slides, docs or social posts.

Preview

debounce.ts
// Debounce: run fn only after calls stop for `wait` ms
export function debounce<T extends (...args: unknown[]) => void>(fn: T, wait = 300) {
let timer: ReturnType<typeof setTimeout> | undefined;
return (...args: Parameters<T>) => {
clearTimeout(timer);
timer = setTimeout(() => fn(...args), wait);
};
}

What it does and when to use it

Social networks, slide decks and many CMSs flatten code into proportional text with no colours, so a 10-line snippet becomes hard to read. This generator renders your code in a monospace font with real syntax highlighting, wraps it in an editor-style window and exports it as a PNG image you can drop into a post, a presentation, a README banner or a blog hero image.

It is meant for short, illustrative snippets: a function you want to explain, a before/after refactor, or a configuration example in a talk. For documentation that people will copy from, a real code block is still the better choice — see the accessibility tip below.

How to use it

  1. Paste your snippet into Code, or press Load example to see a TypeScript sample.
  2. Pick the Language so the highlighter knows which keywords, strings and comments to colour.
  3. Choose a Theme and a Background (gradient, solid, your own hex colour, or transparent).
  4. Adjust Padding and Font size, set a Window title such as the file name, and toggle Window chrome or Line numbers.
  5. Select the Export scale and press Download PNG, or Copy image to paste it straight into Slack, a doc or a slide.

Worked example

Paste this Python snippet and select Python, theme One Dark, line numbers on:

def fib(n: int) -> int:
    """Return the n-th Fibonacci number."""
    a, b = 0, 1
    for _ in range(n):
        a, b = b, a + b
    return a

The preview colours def, for and return as keywords (purple), fib as a function name (blue), the docstring as a string (green) and the numbers in orange, with line numbers 1–6 in a muted gutter. With padding 48 px and 2× scale, the downloaded file is named code-python@2x.png and is twice the pixel size of the preview, so it stays sharp on high-density screens.

Options explained

  • Theme sets the editor background and the colour of each token type (keywords, strings, comments, numbers, functions, classes). Comments are italic in the dark themes.
  • Background is the frame around the window. Transparent exports a PNG with an alpha channel and removes the drop shadow.
  • Padding is the space between the window and the image edge; 32–64 px looks good in social previews.
  • Window chrome adds the three macOS-style dots and the optional title; turn it off for a cleaner look in docs.
  • Export scale multiplies the pixel density: 1× matches the preview, 2× suits most screens, 3× is for projectors and print.

Limitations

Long lines are not wrapped: the image grows as wide as the longest line, so reformat wide code before exporting. Snippets are limited to 400 lines and 20,000 characters. The image uses your system's monospace font (Menlo, Consolas, SF Mono…), so the exact typeface can differ between computers. Highlighting is token-based, not a full compiler, so unusual syntax or very new language features may be coloured imperfectly.

Tips for readable code images

  • Keep it short. 5–20 lines is readable on a phone; cut boilerplate and imports.
  • Format first. Run JSON through the JSON formatter or SQL through the SQL formatter before taking the screenshot.
  • Use contrast. Dark themes on a bright gradient stand out in feeds; GitHub Light works best on white slides.
  • Mind accessibility. Screen readers cannot read code in an image, and nobody can copy it. Add alt text and include the code itself or a gist link in the post.

Frequently Asked Questions

Which languages and themes are supported?

Highlighting uses the Prism tokenizer for JavaScript, TypeScript, JSX, TSX, Python, JSON, CSS, HTML/XML, Bash, SQL, Go, Rust, Java, C, C++, C#, YAML and plain text. Five themes are available: Dracula, One Dark, Monokai, Nord and GitHub Light.

What resolution is the exported PNG?

The image is rendered at the preview's size multiplied by the export scale you choose: 1×, 2× or 3×. 2× is sharp on Retina and most phone screens; 3× is useful for large slides or print.

Can I export with a transparent background?

Yes. Choose Transparent in the Background menu and the PNG keeps an alpha channel around the code window, so it blends into any slide or page background.

Why does Copy image not work in my browser?

Copying images requires the asynchronous Clipboard API with ClipboardItem support, which current Chrome, Edge and Safari provide but some browsers or privacy settings block. When it is unavailable the tool shows a message and you can use Download PNG instead.

Is my code uploaded anywhere?

No. Highlighting and PNG export run entirely in your browser with Prism and html-to-image. Your code is never sent to a server, so it is safe to use with private or unreleased code.