Best HTML to Image APIs in 2026: Convert HTML to PNG, JPEG, WebP
Compare the top HTML-to-image APIs and libraries. Client-side, server-side, and cloud-based options for converting HTML to images.
Last updated: 2026-03-25
Try ScreenshotAPI free
5 free credits. No credit card required.
Converting HTML to images is needed for social media cards, certificates, email previews, reports, and dynamic graphics. The challenge is that HTML rendering requires a browser engine for full fidelity. This guide compares every viable approach: client-side libraries, server-side tools, and cloud APIs.
Comparison Table
| Tool/API | Type | Full CSS | JavaScript | Fonts | Formats | Cost |
|---|---|---|---|---|---|---|
| ScreenshotAPI | Cloud API | Full | Yes | Yes | PNG, JPEG, WebP | $20/500 credits |
| Urlbox | Cloud API | Full | Yes | Yes | PNG, JPEG, WebP, PDF | $19/month |
| ScreenshotOne | Cloud API | Full | Yes | Yes | PNG, JPEG, WebP | $17/month |
| html2canvas | Client-side lib | Partial | Current page | Partial | PNG, JPEG | Free |
| dom-to-image | Client-side lib | Partial | Current page | Partial | PNG, JPEG, SVG | Free |
| Satori | Server-side lib | Limited | No | Manual | SVG | Free |
| Puppeteer | Server-side tool | Full | Yes | Yes | PNG, JPEG, WebP | Free + infra |
| Playwright | Server-side tool | Full | Yes | Yes | PNG, JPEG | Free + infra |
Cloud APIs (Best for Production)
ScreenshotAPI
ScreenshotAPI converts any URL to an image with full Chrome rendering. For HTML-to-image workflows, host your HTML template at a URL and capture it:
javascript// Host your HTML template, then capture it const templateUrl = `https://yoursite.com/template?title=${encodeURIComponent('My Card')}`; const params = new URLSearchParams({ url: templateUrl, width: '1200', height: '630', type: 'png', waitUntil: 'networkidle' }); const response = await fetch( `https://screenshotapi.to/api/v1/screenshot?${params}`, { headers: { 'x-api-key': 'sk_live_your_api_key' } } ); const image = Buffer.from(await response.arrayBuffer());
Pros: Full CSS/JS rendering, web fonts, dark mode, all formats, no infrastructure. Cons: Requires hosting HTML at a URL, 2-5s response time.
Urlbox
Mature service with built-in HTML rendering endpoint. Supports passing HTML directly in the API request.
Pros: Direct HTML input (no hosting needed), retina rendering, S3 upload. Cons: No free tier, subscription pricing.
ScreenshotOne
Supports custom JavaScript and CSS injection, allowing you to modify the page before capture.
Pros: JS/CSS injection, interactive playground, proxy network. Cons: Monthly subscription, HTML must be at a URL.
Client-Side Libraries
html2canvas
The most popular client-side option. Reconstructs the visible DOM onto a canvas element.
javascriptimport html2canvas from 'html2canvas'; const element = document.getElementById('card'); const canvas = await html2canvas(element, { scale: 2, // Retina quality useCORS: true, backgroundColor: null }); canvas.toBlob((blob) => { const url = URL.createObjectURL(blob); // Use the image }, 'image/png');
Pros: No server required, works in the browser, free. Cons: Cannot render external URLs, limited CSS Grid support, font rendering issues, no JS execution context.
dom-to-image
An alternative to html2canvas using SVG foreignObject:
javascriptimport domtoimage from 'dom-to-image'; const node = document.getElementById('card'); const dataUrl = await domtoimage.toPng(node, { quality: 1.0 });
Pros: Better SVG support than html2canvas, lighter library. Cons: Same limitations as html2canvas, plus worse cross-browser support.
Server-Side Libraries
Satori (JSX to SVG)
Converts React/JSX components to SVG without a browser:
javascriptimport satori from 'satori'; import { Resvg } from '@resvg/resvg-js'; const svg = await satori( <div style={{ display: 'flex', fontSize: 48, color: 'white', background: '#1a1a2e', width: '100%', height: '100%', alignItems: 'center', justifyContent: 'center' }}> Hello World </div>, { width: 1200, height: 630, fonts: [{ name: 'Inter', data: fontData }] } ); const resvg = new Resvg(svg); const png = resvg.render().asPng();
Pros: Extremely fast (<100ms), no browser needed, React component syntax. Cons: Very limited CSS (no Grid, limited Flexbox, no pseudo-elements, no animations), requires manual font loading.
Puppeteer / Playwright
Full browser rendering with page.setContent() for raw HTML:
javascriptimport puppeteer from 'puppeteer'; const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.setViewport({ width: 1200, height: 630 }); await page.setContent(htmlString, { waitUntil: 'networkidle0' }); await page.screenshot({ path: 'output.png' }); await browser.close();
Pros: Full CSS/JS rendering, free software, raw HTML input. Cons: Requires Chrome binary (~300 MB), memory-intensive, Docker complexity.
Decision Matrix
| Use Case | Best Tool | Reason |
|---|---|---|
| Social media cards | ScreenshotAPI or Satori | API for full fidelity, Satori for speed |
| Email previews | ScreenshotAPI | Full email CSS rendering |
| Client-side export | html2canvas | Only option without a server |
| Dynamic certificates | ScreenshotAPI | Web fonts + complex layouts |
| OG images (Vercel) | @vercel/og | Free, fast, integrated |
| OG images (general) | ScreenshotAPI | Works on any platform |
| High-volume (10K+/day) | Puppeteer + queue | Cost-effective at scale |
CSS Feature Support
| CSS Feature | html2canvas | Satori | Puppeteer | ScreenshotAPI |
|---|---|---|---|---|
| Flexbox | Partial | Basic | Full | Full |
| Grid | No | No | Full | Full |
| Web Fonts | Partial | Manual | Full | Full |
| Gradients | Yes | Basic | Full | Full |
| Box Shadows | Yes | No | Full | Full |
| Pseudo-elements | No | No | Full | Full |
| Animations | No | No | Yes | Yes |
| Media queries | No | No | Yes | Yes |
Verdict
For production HTML-to-image conversion with full rendering fidelity, ScreenshotAPI or Puppeteer are the best options. ScreenshotAPI removes infrastructure management. Puppeteer is free but requires server management.
For simple, template-based images without complex CSS, Satori is the fastest option.
For client-side only (no server), html2canvas is the only practical choice.
Next Steps
- Read the HTML to image conversion guide for implementation details
- See the OG image generators comparison for social card tools
- Check ScreenshotAPI pricing for credit packages
- Browse the API documentation for all parameters
Frequently asked questions
What is the best way to convert HTML to an image?
For full rendering fidelity, use a headless browser (Puppeteer/Playwright) or a cloud API (ScreenshotAPI). For simple layouts without JavaScript, Satori converts JSX to SVG/PNG. Client-side libraries like html2canvas work for basic use cases.
Can html2canvas convert any HTML to an image?
No. html2canvas has significant limitations: it does not support CSS Grid fully, cannot render external iframes, has issues with web fonts, and only works on the current page's DOM (cannot load external URLs).
How do I convert an HTML email template to an image?
Host the HTML template at a URL (even a local server works), then use ScreenshotAPI to capture it at the desired dimensions. This gives you pixel-perfect rendering with full CSS and font support.
Is Satori the same as @vercel/og?
@vercel/og uses Satori under the hood. Satori converts React/JSX to SVG, and @vercel/og wraps it in an Edge Function that converts SVG to PNG. You can use Satori directly if you are not on Vercel.
Related resources
Start capturing screenshots today
Create a free account and get 5 credits to try the API. No credit card required. Pay only for what you use.