How to Convert HTML to JPG (Step-by-Step)
By Sachin Jagtap · Builder of HTMLtoImage.online · Updated October 2026
Need to turn a block of HTML and CSS into a shareable image? Whether you are saving a UI component for a design doc, exporting an email template preview, or attaching a styled card to a ticket, this guide shows you exactly how to convert HTML to JPG — first with a free online tool (no install, no sign-up), then with a few lines of JavaScript if you are a developer looking to automate it.
What "convert HTML to JPG" actually means
HTML is code; a JPG is a flat raster image. "Converting" means rendering your markup exactly as a browser would paint it, then capturing those pixels into a .jpg file. JPG is the right choice when your design is colorful and photographic and you want a small file size — it uses lossy compression, so it trades a little detail for big savings in kilobytes. The one catch: JPG cannot store transparency, so any transparent background becomes solid white. (If you need transparency, use our HTML to PNG converter instead.)
How to convert HTML to JPG (the fast way)
The quickest method runs entirely in your browser, so your code never leaves your computer:
- Open the converter. Go to the free HTML to JPG converter.
- Paste your code. Drop your HTML (with any inline CSS or SVG) into the editor. You can also click Upload File to load a local
.htmldocument, or Load Sample to try it instantly. - Pick your settings. Choose a Resolution Scale (use 2× or 3× for crisp, retina-quality output) and a Compression Level (80% is the sweet spot for web — small file, no visible quality loss).
- Generate. Click Generate Optimized JPG. The tool renders your code and shows a live preview with the exact dimensions and file size.
- Save it. Click Download JPG, or Copy to Clipboard to paste the image straight into Slack, Gmail, or a design tool.
How to convert HTML to JPG with JavaScript (for developers)
If you want to generate JPGs programmatically inside a web app or script, you can do it client-side with the modern-screenshot library:
import { domToCanvas } from 'modern-screenshot'
// The element you want to capture
const node = document.querySelector('#invoice-card')
// Render at 2x scale for retina sharpness (transparent background)
const rendered = await domToCanvas(node, { scale: 2 })
// JPG has no transparency, so flatten onto white before encoding
const flat = document.createElement('canvas')
flat.width = rendered.width
flat.height = rendered.height
const ctx = flat.getContext('2d')
ctx.fillStyle = '#ffffff'
ctx.fillRect(0, 0, flat.width, flat.height)
ctx.drawImage(rendered, 0, 0)
// Encode at 80% quality and trigger a download
const link = document.createElement('a')
link.href = flat.toDataURL('image/jpeg', 0.8)
link.download = 'invoice-card.jpg'
link.click()
Why not just use domToJpeg(node, { backgroundColor: '#ffffff' })? That option also overrides the captured element's own background color, so a dark or colored card would come out white. Flattening the finished canvas onto white only fills the genuinely transparent areas.
Common problems (and how to fix them)
My background came out white, not transparent
That is expected — the JPG format has no alpha channel. If you need a transparent background, export as PNG or WebP instead.
My dark card turned white
If you're writing your own code, you're probably passing a backgroundColor option to your capture library, which can repaint the card itself. Use the flatten-onto-white approach shown above instead. (Our converter already does this.)
My web font didn't load
Browsers block reading pixels from cross-origin resources unless they allow CORS. Ensure your font is loaded via standard Google Fonts @import or self-hosted as base64.
The text looks blurry
Raise the Resolution Scale to 2× or 3×. A 500px card rendered at 2× produces a crisp 1000px image that stays sharp on high-DPI retina displays.
Frequently Asked Questions
Is it free to convert HTML to JPG?
Does my code get uploaded to a server?
Can I convert a full .html file to JPG?
About the author — Sachin Jagtap is a builder and the creator of HTMLtoImage.online, a free, privacy-first tool for converting HTML, CSS, and SVG code into PNG, JPG, and WebP images.