Code Screenshot: Make Clean Images of Your Code

November 11, 2026 · 10 min read

Code Screenshot: How to Make Clean Images of Your Code

A code screenshot is a styled image of source code, with syntax colors, a window frame and padding, made for slides, social posts and newsletters. The quickest ways to make one are the CodeSnap extension in VS Code, Carbon or Ray.so in a browser, or our Code to Image tool. For READMEs and docs, a fenced code block works better.

What Makes a Good Code Screenshot (and Why Print Screen Isn't It)

Pressing Print Screen grabs your whole screen: editor tabs, sidebar, lint squiggles and a file tree nobody asked to see. A proper code image is rendered from the code text itself. The tool lays your snippet on a clean canvas, colors it with a syntax theme and adds padding, so it looks deliberate at any size.

You'll see these images in conference slides, blog headers, newsletters and posts on X or LinkedIn, where a Markdown code block wouldn't render at all. This post is about turning code into a picture. Tools that turn a picture of a web page into HTML solve the opposite problem.

Three habits separate a readable image from a mushy one:

  • Crop hard. Keep only the lines that make your point and drop imports, logging and boilerplate.
  • Keep the code honest. Screenshot code that actually runs, because readers will retype it and trust it.
  • Show one idea. If the snippet needs scrolling or a second image, link to a gist or repo instead.

How Do I Take a Screenshot of Code in VS Code?

To take a Visual Studio Code screenshot of just your code, install the CodeSnap extension (published by adpyke). Other apps also use the CodeSnap name, so check the publisher before you install. CodeSnap copies your selection with VS Code's own highlighting, so the image matches the theme and font you already use. CodeSnap captures the code as it looks in your editor, so run the VS Code formatter first to tidy the indentation.

The workflow from its README:

  1. Open the Command Palette with Ctrl+Shift+P (Cmd+Shift+P on macOS) and run CodeSnap. Right-clicking a selection also shows a CodeSnap entry.
  2. Select the lines you want in the image.
  3. In the panel that opens beside your code, drag the edge of the code window to adjust the image width.
  4. Click the shutter button to save the image to disk.

Styling lives in your settings.json. Here's a setup for slides with a plain background:

{
  "codesnap.shutterAction": "copy",
  "codesnap.showLineNumbers": false,
  "codesnap.showWindowControls": false,
  "codesnap.transparentBackground": true
}

With these settings the shutter copies the image to your clipboard instead of opening a save dialog. Line numbers and the macOS-style window buttons disappear, and the colored backdrop turns transparent so the snippet sits on your slide's own background. If you keep line numbers on, set codesnap.realLineNumbers to true so numbering matches the file rather than starting at 1.

To launch it from the keyboard, bind the codesnap.start command in Keyboard Shortcuts. CodeSnap's source shows it saves PNG files only, rendered at twice the on-screen size. Carbon also lists a community VS Code extension that sends your file to Carbon, if you'd rather use Carbon's styling.

Carbon Code Snippets: Paste, Style and Export

Carbon at carbon.now.sh is the tool most people mean when they search for Carbon code images. You can type or paste into its editor, drop a file onto it, or append a GitHub gist ID to the URL to load that gist. Then you adjust the syntax theme, background color, window theme, padding, shadow and font.

When your Carbon code snippet looks right, open the Export menu to download a PNG or SVG, or use Copy, then Image, to put it on your clipboard. Carbon is open source under the MIT license. Signing in is only needed if you want saved snippets you can come back to and edit.

If you live in a terminal, the community carbon-now-cli package sends files through Carbon for you:

npm i -g carbon-now-cli
carbon-now app.js --start 12 --end 30 --to-clipboard

This renders lines 12 to 30 of app.js with Carbon and copies the result to your clipboard instead of saving a file. Add --interactive to pick a theme and font through prompts first, or --preset to reuse saved settings. Carbon's README also lists community plugins for IntelliJ IDEA, Vim, Emacs and Sublime Text that open a selection in Carbon.

Carbon vs Ray.so vs CodeSnap vs Code to Image

All four produce a framed, highlighted image. They differ in where they run and what they export.

ToolWhere it runsExportsBest forWatch out for
CarbonBrowser, plus a CLI and editor pluginsPNG, SVG, copy imageFine control over fonts, backgrounds and shadowsMore options to click through for a quick shot
Ray.so (by Raycast)BrowserPNG at 2x, 4x or 6x, SVG, copy image, copy URLPolished results with few decisionsPadding comes in four fixed steps
CodeSnapInside VS CodePNG, saved or copiedCode that's already open in your editorStyling only through settings
Code to ImageBrowserPNG with a scale option, SVG, copy imageA quick image with nothing to install6 themes and common languages only

Ray.so is Raycast's take on the idea, and its source is public on GitHub. Its export menu saves PNG or SVG, copies the PNG where the browser allows it, and copies a link to the current setup.

We prefer CodeSnap when the code is already open in VS Code, because it skips the copy and paste step and keeps your editor theme. When the code lives somewhere else, such as a pull request or a chat message, a browser tool is faster.

Make a Code Screenshot in Your Browser With Code to Image

Our Code to Image tool runs in your browser with no usage limit. Paste your code, pick one of its 6 themes and a window frame, and choose a PNG scale. Then download a PNG or SVG, or copy the image straight to your clipboard.

Two caveats. Copying an image depends on your browser's clipboard support, so the download buttons are the safer route. Highlighting uses the common languages bundled with highlight.js, so a niche language may not be recognized. The tool page has the full step-by-step walkthrough.

PNG or SVG, 2x or 4x: Getting a Sharp Code Image

Pick the format by where the image is going:

  • PNG for social posts and chat. Nearly every platform accepts it. Export at 2x or higher so text stays crisp on high-density screens. Ray.so offers 2x, 4x and 6x, and carbon-now-cli offers 1x, 2x and 4x.
  • SVG for slides and web pages you control. Vector text scales to any size without blurring. Most social platforms expect PNG or JPEG uploads, so keep SVG for decks and your own site.

A few layout choices matter as much as resolution. Aim for roughly 10 to 20 lines at a 14 to 16 px font, which stays legible when a feed scales the image down. Keep lines short, because a wide image gets shrunk harder. Use a light theme for projectors and print, where dark themes often lose contrast. In feeds either works, so pick the one that matches your brand.

When a Fenced Code Block Beats a Code Screenshot

An image of code is a picture of text. Readers can't copy it, search it, translate it or resize the font, and a screen reader only hears the alt text. WCAG 2.2 Success Criterion 1.4.5, Images of Text (Level AA), asks you to use real text whenever the technology can present it. The only exceptions are customizable images and cases where the look is essential.

Markdown can present code as text, so READMEs, tutorials and docs should use a fenced code block with a language identifier for highlighting. Readers can select and copy the snippet, and search engines index it. Our code documentation examples include a README usage section built this way.

The honest limitation of images: a screenshot freezes the code. Fix a typo or rename a variable and you have to re-export, re-upload and replace every copy, while a code block is a one-line edit. Save images for places where Markdown doesn't render.

Adding a Code Screenshot to Markdown With Useful Alt Text

Sometimes you want both: an eye-catching image in a blog post or changelog, plus code people can copy. Write alt text that says what the code does, not just the word screenshot, and put the real code in a collapsible block underneath.

![Python function that tries an HTTP request up to three times with a growing delay](https://example.com/images/retry.png)

<details>
<summary>Show the code</summary>

```python
import time
import requests

def get_with_retry(url, attempts=3):
    for i in range(attempts):
        try:
            return requests.get(url, timeout=5)
        except requests.RequestException:
            time.sleep(2 ** i)
    raise RuntimeError("all retries failed")
```

</details>

This renders the image first, then a collapsed Show the code toggle. Clicking it reveals the function as selectable text. Keep the blank line after the summary line, or GitHub won't parse the fenced block inside the toggle.

The image has to be hosted somewhere and linked by URL, since our editor doesn't host images. Swap in your own image URL, paste the snippet into the editor and the preview renders the image and the toggle, though it shows the code without colors. For sizing, captions and hosting options, see our Markdown image guide.

A good code screenshot is short, large and cropped to one idea, and it lives where Markdown can't. Use CodeSnap when the code is open in VS Code, and Carbon or Ray.so when you want more styling. Our Code to Image tool gives you a quick PNG or SVG in the browser. For docs and READMEs, write a fenced code block in the editor instead, so readers can copy every line.