# HTML to Image API (html2img.com): Full Reference > REST API that converts HTML, CSS, or any URL into a PNG image. Authenticate with one header, POST JSON, receive a CDN-hosted PNG URL. 50 free renders at signup (no credit card). Paid plans from $9/month for 1,000 renders up to $300/month for 100,000. Paid renders are hosted permanently; free-tier renders are hosted for 7 days, and upgrading to any paid plan makes existing renders permanent. This file bundles the full documentation for LLMs and other automated readers. The shorter index is at [/llms.txt](https://html2img.com/llms.txt). The site sitemap is at [/sitemap.xml](https://html2img.com/sitemap.xml). --- ## What you can do with html2img.com - **Open Graph and social share images** generated on demand (Twitter, LinkedIn, Facebook, Instagram, Pinterest, YouTube thumbnails). - **Invoices, receipts, tickets and certificates** as PNG attachments for transactional email. - **Screenshots of any public URL**, full-page or cropped to a CSS selector, with cookie banners stripped via injected CSS. - **Code screenshots, GitHub repo cards, GitHub social previews** for launches, release notes and changelogs. - **Charts, dashboards and embed cards** exported to PNG with full JavaScript support up to a 30-second budget. - **Real estate listings, product cards, weather widgets, QR codes** and other parameterized image shapes via named templates. Anywhere your stack already speaks HTTP, you can render an image: PHP, Laravel, Rails, Python, Node.js, Express, Next.js, Remix, Vue, Nuxt, FastAPI, Flask, Django. ## Pricing Free: 50 credits at signup (one-time allowance, no monthly reset), no credit card. Every feature available except the MCP server, which is on paid plans only. Free renders are hosted for 7 days; paid renders are hosted permanently. - $9/month: 1,000 credits - $25/month: 3,000 credits - $60/month: 10,000 credits - $120/month: 30,000 credits - $225/month: 65,000 credits - $300/month: 100,000 credits One credit = one render, image or PDF. Running out returns HTTP 402 `insufficient_credits`, carrying the renewal date on a paid plan or the upgrade URL on the free tier, so there is no surprise billing and no automatic overage charge. There is no rate-limit response. No per-seat pricing. Cancel from the dashboard at any time. Yearly invoicing available with a small discount. Non-profit and open-source discounts considered case by case. [Pricing page](https://html2img.com/pricing) · [Compare to alternatives](https://html2img.com/compare) ## Frequently asked **Free tier?** 50 renders at signup, no credit card required, all available immediately. Every feature on paid plans is available on the free plan, including templates, webhooks and DPI control, except the MCP server (paid plans only). Free renders are hosted for 7 days; upgrading makes everything already rendered permanent. **Which languages?** Any language that can make an HTTP request. Worked examples published for PHP, Laravel, Ruby on Rails, Python, JavaScript, Node.js, React and Vue. **HTML vs Screenshot endpoint?** HTML accepts raw markup and runs your inline JavaScript. Screenshot accepts a URL and captures the rendered page without running user-supplied JavaScript. Pick HTML for full control, Screenshot for capturing existing pages. **Rendering accuracy?** Real Chrome: flexbox, grid, custom properties, custom fonts and JavaScript all behave as they do in the browser. **What's a template?** A named, parameterized image design hosted on our side. POST a JSON payload to its endpoint, receive a styled PNG, skip the HTML step. **Limits?** 30-second budget on sync requests. For longer renders use `webhook_url`. Viewport up to 5000x5000. DPI 1–4 (forced to 1 when `fullpage` is true). --- ## The three endpoints Base URL: `https://app.html2img.com` ### 1. HTML and CSS API: `POST /api/html` Send raw HTML and CSS. We render it in Chrome and return a PNG URL. Inline `", "wait_for_selector": "#chart canvas" } ``` ### Screenshot endpoint Cannot run user-supplied JavaScript. The target page runs its own scripts; we capture the result. Use `wait_for_selector` for elements that load late, or `ms_delay` for iframes/embeds where the selector isn't visible from the outer document. --- ## Testing and debugging ### Reproducing renders locally 1. Save HTML to a file and open in Chrome. 2. DevTools → device toolbar → set width/height to match what you'll send. 3. Verify fonts load. If Inter falls back to Times locally, it'll fall back the same way in the API. 4. Use Chrome's "Capture screenshot" in DevTools to compare against what the API produces. ### Why a render differs from your browser 1. **Missing fonts**: use Google Fonts via `` or self-host with a public `@font-face` URL. 2. **JS timing**: pair `wait_for_selector` or `ms_delay` with the marker your code sets after data is ready. 3. **User-agent-dependent CSS**: hover, focus, prefers-color-scheme behave differently in headless. Inject `prefers-color-scheme: dark` overrides via `css` if needed. 4. **Slow third-party assets**: strip them with `css { display: none !important }` for ad slots and analytics overlays. ### Webhook testing in development - [webhook.site](https://webhook.site) for a free temporary URL. - ngrok (`ngrok http 3000`) to expose your local server with a stable HTTPS URL. --- ## Language guides Every example assumes the API key lives in `HTML2IMG_API_KEY` (or your platform's equivalent env var). All examples return the same JSON shape (`success`, `credits_remaining`, `id`, `url`). The snippets below are raw HTTP. Most stacks also have an official package, each documented in full at https://html2img.com/integrations : PHP (`html2img/html2img-php`), Laravel (`html2img/html2img-laravel`), JavaScript (`@html2img/client`), Python (`html2img-client`), Django (`html2img-django`), Ruby and Rails (`html2img-client`), plus plugins for WordPress, Statamic and Craft CMS and an Action for GitHub workflows. ### PHP (cURL) ```php true, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => [ 'Content-Type: application/json', 'X-API-Key: ' . getenv('HTML2IMG_API_KEY'), ], CURLOPT_POSTFIELDS => json_encode(array_merge(['html' => $html], $options)), ]); $response = curl_exec($ch); $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); $result = json_decode($response, true); if ($statusCode !== 200 || empty($result['success'])) { throw new Exception($result['message'] ?? 'Render failed'); } return $result; } $result = htmlToImage('
Failed to render
Rendering...
``` ### Nuxt server route ```typescript // server/api/render-invoice.post.ts export default defineEventHandler(async (event) => { const body = await readBody(event); const response = await $fetch('https://app.html2img.com/api/v1/templates/invoice-image', { method: 'POST', headers: { 'X-API-Key': process.env.HTML2IMG_API_KEY!, 'Content-Type': 'application/json' }, body, }); return { url: response.url }; }); ``` --- ## Named templates (JSON in, PNG out) Templates skip the markup step entirely. POST a JSON payload to `/api/v1/templates/{slug}` and receive a styled PNG. The full catalog is at [/templates](https://html2img.com/templates). Example, invoice template: ```bash curl -X POST https://app.html2img.com/api/v1/templates/invoice-image \ -H 'X-API-Key: YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{ "invoice_number": "INV-2026-0042", "business_name": "Coastline Coffee Co", "client_name": "Riverside Bakery", "items": [ {"description": "Wholesale beans", "quantity": "50", "unit_price": "$15.00", "amount": "$750.00"} ], "total": "$750.00" }' ``` Template categories: - **Social**: open-graph-image, twitter-post, instagram-square, instagram-story, linkedin-post, facebook-post, pinterest-pin, youtube-thumbnail, tweet-mockup-card. - **Business**: invoice-image, receipt-image, event-ticket, certificate-of-completion, product-card, business-card, coupon-voucher. - **Developer**: code-screenshot, github-repo-card, github-social-preview, project-showcase. - **Real estate**: real-estate-listing. - **Content**: quote-card, blog-hero, podcast-cover, podcast-episode-card, email-header. Each template has its own JSON schema documented at `/templates/{slug}`. --- ## Worked examples The site publishes worked examples for common image shapes. Each links to a full code walkthrough. - [Twitter/X embed to image](https://html2img.com/docs/examples/twitter-embed): capture a tweet permalink with cookie banners stripped. - [Facebook post to image](https://html2img.com/docs/examples/facebook-post): handle Facebook SDK timing with `ms_delay`. - [Instagram post to image](https://html2img.com/docs/examples/instagram-post): size an Instagram embed for capture. - [Invoice or receipt to image](https://html2img.com/docs/examples/invoice-receipt): render a styled invoice as an A4 PNG. - [GitHub repo card](https://html2img.com/docs/examples/github-repo-card): social preview for a repository. - [Chart screenshot](https://html2img.com/docs/examples/chart-screenshot): turn Chart.js into a static PNG. - [Product card](https://html2img.com/docs/examples/product-card): e-commerce social share image. - [Testimonial card](https://html2img.com/docs/examples/testimonial-card): quote, avatar, rating. - [Price comparison](https://html2img.com/docs/examples/price-comparison): pricing table as a marketing PNG. - [Calendar event](https://html2img.com/docs/examples/calendar-event): date badge, location, attendee list. - [Weather widget](https://html2img.com/docs/examples/weather-widget): current conditions and forecast. - [QR code](https://html2img.com/docs/examples/qr-code): branded QR with logo and label. --- ## Free in-browser tools No-signup tools at [/tools](https://html2img.com/tools) for generating Open Graph cards, Twitter cards, code screenshots, YouTube thumbnails, certificates, invoices and Pinterest pins directly in the browser. Built on the same API. --- ## Comparisons Honest comparisons against the most common alternatives: - [vs HTML/CSS to Image (htmlcsstoimage.com)](https://html2img.com/compare/htmlcsstoimage) - [vs Urlbox](https://html2img.com/compare/urlbox) - [vs APIFlash](https://html2img.com/compare/apiflash) - [vs Bannerbear](https://html2img.com/compare/bannerbear) Each covers pricing, features and migration effort. --- ## Reference URLs - Site: https://html2img.com - API base: https://app.html2img.com - CDN: https://i.html2img.com - Sign up: https://app.html2img.com/register - Dashboard: https://app.html2img.com/dashboard - Docs home: https://html2img.com/docs/getting-started - Parameters: https://html2img.com/docs/parameters - Integrations: https://html2img.com/integrations - Worked examples: https://html2img.com/docs/examples - Templates catalog: https://html2img.com/templates - Free tools: https://html2img.com/tools - Pricing: https://html2img.com/pricing - Features: https://html2img.com/features - Articles: https://html2img.com/articles - Contact: https://html2img.com/contact - Sitemap: https://html2img.com/sitemap.xml - Image sitemap: https://html2img.com/image-sitemap.xml