📸 Code Screenshot — Beautiful Code Images
Turn your code into beautiful screenshots with syntax highlighting, custom themes, gradient backgrounds, and window chrome. Export as PNG. Free code image generator.
onhtml.com
How to Use
Choose theme and background
Select a syntax theme (Dracula, VS Dark, Night Owl…) and a gradient background. Toggle mac window dots and adjust padding to taste.
Paste your code
Type or paste code into the input area. The preview card updates instantly as you type.
Export as PNG
Click Export PNG. html2canvas renders the card at 2× resolution — sharp on Retina displays and ready for social media or blog posts.
Frequently Asked Questions
Complete Guide: Code Screenshot — Beautiful Code Images
Why Code Screenshots Matter
In an era where developers share knowledge across Twitter/X, LinkedIn, dev.to, Hashnode, and hundreds of technical newsletters, plain text code blocks often fail to make an impression. A well-crafted code screenshot, on the other hand, immediately communicates professionalism, care, and clarity. It renders beautifully in any feed, regardless of whether the platform supports Markdown or syntax highlighting. The image is what people see first — and first impressions drive engagement.
Consider the everyday scenarios where code screenshots add real value. When writing a blog post or tutorial, embedding a styled screenshot instead of a raw code fence gives your readers a visual pause point, makes the article look polished, and lets you caption or annotate specific lines. In presentations and slide decks (Google Slides, PowerPoint, Keynote), a screenshot with a tasteful gradient background beats a plain white code block every time. Documentation pages benefit from high-resolution screenshots that show exactly what the code looks like in a real editor environment, complete with line numbers and familiar window chrome.
On social media, especially Twitter/X where character limits constrain explanation, a code screenshot communicates an entire concept in a single glance. Engineers who post consistently on social platforms know that a beautiful screenshot earns far more retweets and saves than a thread of raw text. The image format also preserves indentation perfectly — no more copying code into a tweet only to watch the whitespace collapse.
Pull request descriptions are another underrated use case. Pasting a screenshot of the key changed function into the PR description helps reviewers immediately understand the intent without parsing the full diff. Teaching and live coding sessions benefit similarly: projected code on a screen needs high contrast and a clean background to be readable from the back of a room or a small Zoom window.
How to Use the Tool: Step by Step
- Paste your code. Click into the editor area and paste (or type) any code snippet. The editor accepts all languages — Python, JavaScript, TypeScript, Rust, Go, SQL, Bash, HTML, CSS, and more. Syntax highlighting is applied automatically based on the language detected from the first meaningful tokens.
- Select a syntax theme. Use the theme dropdown to choose from seven professionally curated themes. Each theme changes the color of keywords, strings, comments, operators, and variable names. Pick the one that matches your personal brand or the context of the image.
- Pick a background gradient. The background behind the code window is one of eight gradient options. Gradients give depth and visual interest to the exported image, making it pop against any feed background. You can also choose a solid neutral if you want something minimal.
- Toggle the mac window dots. Enable or disable the red/yellow/green macOS-style traffic-light buttons in the window chrome. Enabling them adds a familiar editor feel; disabling them produces a cleaner, more abstract look.
- Adjust padding. Choose Small, Medium, Large, or XL padding around the code window. More padding makes the gradient more prominent and gives the image a spacious, poster-like quality. Less padding focuses entirely on the code.
- Set the font size. Use the font size selector to make the code larger (great for presentations and mobile-first images) or smaller (better for dense, multi-line snippets).
- Click Export PNG. The tool uses html2canvas at 2× pixel density to produce a Retina-quality PNG. The download starts immediately — no sign-up, no watermark that obscures content, just a small "onhtml.com" credit in the corner.
Theme Guide: When to Use Each Theme
Dracula — Purple-and-pink tones with a dark navy background. This is the most popular dark theme on social media because of its bold, distinctive palette. Ideal for JavaScript, TypeScript, and CSS where string literals (pink) and keywords (purple) get maximum contrast. Best with cool-toned gradient backgrounds (blue, purple, midnight).
VS Dark (Visual Studio Dark+) — The default dark theme of the world's most-used editor. Its muted blues and yellows feel instantly familiar to a wide developer audience. Great for professional blog posts where you want the code to look "real" rather than stylized. Works with any gradient.
Night Owl — Designed specifically for low-light readability by Sarah Drasner. Rich teal and warm yellow tones. Excellent choice for languages with lots of string literals (Python, JSON). Pairs beautifully with deep ocean or aurora gradients.
One Dark — Atom editor's legendary dark theme, now everywhere. Balanced greens, oranges, and reds. Best for languages with heavy operator use like Go or Rust where the varied palette helps differentiate token types. Use with sunset or forest gradients.
GitHub Dark — The official dark theme used on GitHub.com. Subtle and understated. Perfect for PR descriptions and anything you want to look native to a developer workflow. Pairs with neutral or minimal backgrounds.
Monokai — The classic. Yellow-green keywords, magenta strings, orange numbers. Instantly recognizable from the Sublime Text era. Great nostalgia-factor for long-time developers. Use with dark or warm gradients.
VS Light — The light theme option. Blue keywords on white background. Ideal for print media, documentation sites with white backgrounds, or any context where dark backgrounds look out of place. Export on a light or soft-pastel gradient.
Background Gradient Selection Tips
The gradient is the frame around your code art. A few principles help: use gradients with enough contrast against the code window's background color. A light gradient under a white VS Light theme creates almost no separation — go darker or use a drop shadow. For social sharing, saturated gradients (aurora, sunset, neon) perform better because they attract the eye in a scrolling feed. For documentation and teaching materials, subtler gradients (nordic, pastel, ocean) keep the focus on the code. For presentation slides, choose a gradient that matches your slide deck's color palette to maintain visual continuity.
Export Quality: 2× Retina PNG
The export engine renders the code window at twice the screen pixel density using html2canvas configured with scale: 2. This means a code window that appears 600×400 pixels on screen exports as a 1200×800 pixel PNG. On a Retina display (MacBook, iPhone, modern Android) the image is perfectly crisp. On standard displays, the 2× resolution provides generous downscaling headroom — text stays sharp even after social media compression artifacts.
The file is generated entirely in your browser. No code is uploaded to any server. The PNG download is instant and private.
Use Cases in Depth
Documentation: API reference docs, README files for open-source projects, and internal wikis all benefit from consistent, high-quality code images. Use VS Dark or GitHub Dark with minimal padding for a professional, editor-native look.
Social media sharing: Post code tips, gotchas, one-liners, or clever patterns. Dracula and Night Owl themes perform best on Twitter/X and LinkedIn because their colors reproduce well after JPEG re-compression. Keep snippets under 20 lines for maximum readability at thumbnail size.
Teaching and courses: Online course platforms like Udemy and Teachable use fixed-width video frames where plain code is hard to read. A screenshot with large font size and XL padding fills the frame and keeps every student focused on exactly what matters.
Pull request descriptions: GitHub supports image uploads in PR descriptions. A quick screenshot of the core changed function, with the key lines visible, helps reviewers understand the change before they dive into the diff.
How It Compares to carbon.now.sh and ray.so
Carbon (carbon.now.sh) was the first major code-screenshot tool and is still widely used. It requires an external network request to render. Ray.so (by Raycast) produces very polished images but has a limited free tier and is optimized for macOS users. This tool runs entirely offline in the browser — no internet connection after page load is required, no API limits, no account needed. The gradient options and theme selection are comparable to both alternatives, and the 2× export quality matches ray.so's output at no cost.
Frequently Asked Questions
Does the watermark cover my code? No. The "onhtml.com" credit is a small, semi-transparent label in the bottom corner of the gradient background, never overlapping the code window itself.
What resolution is the PNG? 2× the rendered screen size. Typical exports are 1200–1600 pixels wide, suitable for HiDPI screens and social media platforms.
Does it support automatic syntax highlighting? Yes. The editor detects the language from the code content. You can also manually set the language in the language selector if auto-detection picks the wrong one.
Is my code sent to any server? No. All processing happens in your browser via html2canvas. Your code never leaves your device.
Can I use the exported image commercially? Yes. There are no restrictions on how you use the exported PNG.
For formatting your code before screenshotting, try Code Beautifier. To preview Markdown documentation, use Markdown Preview. For database-related screenshots, format your queries first with SQL Formatter.