To convert HTML to JPG in code, render the document in a real browser and capture the rendered page as a JPEG. A browser resolves CSS, fonts, images and JavaScript before producing pixels; an HTML parser alone cannot reproduce that visual result. For a self-hosted workflow, Playwright provides viewport, full-page, quality and scaling controls. A hosted screenshot API is useful when you do not want to install or operate browsers.
What “HTML to JPG” actually means
There are two different inputs:
- A URL: a browser navigates to a live page, waits for it to render, then captures it.
- An HTML document or fragment: your program loads the markup into a browser page, optionally supplies CSS and scripts, waits for resources, and captures the result.
The output is a raster image of the rendered page. It is not a semantic conversion of tags such as <h1> and <table> into image primitives. This distinction matters for responsive layouts, web fonts, animations, lazy images and client-side JavaScript.
Convert HTML to JPG with Playwright
Playwright is the most flexible self-hosted option when you need the browser under your control. Install the language package and its browser binaries, create a page with an intentional viewport, load either a URL or HTML, wait for the visual dependencies you need, and call the screenshot API with JPEG output.
Node.js example for an HTML string
Install Playwright and its Chromium browser, then save this as html-to-jpg.mjs:
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
import { chromium } from 'playwright';
const browser = await chromium.launch();
const page = await browser.newPage({
viewport: { width: 1200, height: 800 }
});
await page.setContent(`
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<style>
body { font-family: Arial, sans-serif; margin: 40px; }
h1 { color: #183b56; }
</style>
</head>
<body>
<h1>Quarterly report</h1>
<p>Rendered HTML captured as a JPEG.</p>
</body>
</html>`);
await page.screenshot({
path: 'output.jpg',
type: 'jpeg',
quality: 85,
fullPage: true,
scale: 'css'
});
await browser.close();
Run it with node html-to-jpg.mjs. The explicit type: 'jpeg' makes the format unambiguous. A .jpg filename also selects JPEG. Playwright documents JPEG quality from 0 to 100; its documented default is 80. Higher quality generally produces a larger file, while lower quality saves bytes at the expense of detail.
Capture a URL instead of inline HTML
Replace page.setContent(...) with navigation:
await page.goto('https://example.com', { waitUntil: 'networkidle' });
await page.screenshot({ path: 'site.jpg', type: 'jpeg', quality: 85, fullPage: true });
For a page whose network never becomes idle because of analytics, polling or streaming, use a bounded wait and a page-specific readiness condition instead of waiting indefinitely:
await page.goto('https://example.com', { waitUntil: 'domcontentloaded', timeout: 60000 });
await page.locator('[data-rendered="true"]').waitFor({ state: 'visible', timeout: 30000 });
await page.screenshot({ path: 'site.jpg', type: 'jpeg', fullPage: true });
Important screenshot options
| Option | Use | Practical consequence |
|---|---|---|
type: 'jpeg' |
Force JPEG output | Prevents an accidental PNG result. |
quality |
Set JPEG quality from 0 to 100 | Trade image fidelity for file size; 80 is Playwright’s documented default. |
fullPage: true |
Capture the complete scrollable page | Produces a tall image rather than only the viewport. |
scale: 'css' |
One image pixel per CSS pixel | Predictable dimensions and smaller output. |
scale: 'device' |
Use device-pixel output | Higher-density images on a high-DPI emulation. |
viewport |
Choose browser width and height | Controls responsive breakpoints and the visible layout. |
Set the viewport before navigation or content insertion. A 375-pixel viewport can trigger a mobile layout that will not appear at 1,200 pixels. For reproducible output, fix the viewport, browser version, timezone and any data returned by your page.
Make the rendered image complete and repeatable
Wait for fonts and images
HTML can be present while web fonts or images are still loading. For pages under your control, expose a readiness marker after the final data and assets are available. You can also wait for a known image selector or use a short, bounded delay when no better signal exists. Do not rely on an arbitrary long sleep as your only synchronization method: it slows every capture and still may fail on a slow connection.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsHandle lazy loading
A full-page screenshot may reveal lazy images only after the page scrolls. Trigger the page’s normal lazy-loading behavior before capture, or use an application-level “all images loaded” signal. Check the resulting JPG for missing images rather than assuming that DOM presence means pixels were painted.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
Control animation and dynamic data
Freeze or disable CSS animations when a stable frame matters. Capture timestamps, rotating banners and personalized content can otherwise change between runs. If the page needs authentication, provide credentials through your test environment rather than embedding secrets in source files or public URLs.
Choose full page versus viewport
- Viewport capture: appropriate for social cards, visual regression at a fixed screen size and above-the-fold previews.
- Full-page capture: appropriate for documentation, invoices and long reports, but verify that very tall pages remain practical to store and display.
Python and cURL options
Playwright also has official language bindings for Python. The structure is the same: launch Chromium, create a viewport, load content, wait for readiness and request JPEG output. Keep the browser lifecycle inside a context manager so failures still close resources.
from playwright.sync_api import sync_playwright
html = """<html><body><h1>Hello</h1><p>JPEG output</p></body></html>"""
with sync_playwright() as p:
browser = p.chromium.launch()
page = browser.new_page(viewport={"width": 1200, "height": 800})
page.set_content(html)
page.screenshot(path="output.jpg", type="jpeg", quality=85, full_page=True)
browser.close()
There is no generic cURL command that renders arbitrary HTML with CSS and JavaScript by itself. cURL can download an already-created image or call a rendering service, but it is not a browser engine. If your application needs a simple HTTP request instead of browser installation, use a hosted screenshot API.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallHosted conversion with CloudConvert
CloudConvert documents a Website Screenshot API that accepts a URL or an HTML file and can produce JPG output. Its API uses a job-and-task model and documents synchronous and asynchronous workflows. A hosted service shifts browser installation, patching and execution infrastructure away from your application, while giving up some local control and requiring you to assess how supplied URLs or HTML are handled under the provider’s current terms.
Use a synchronous request when the caller can wait for the image. Use an asynchronous job and callback workflow when captures may take longer or when you are processing a queue. Regardless of provider, specify the viewport and whether the result should be full page, then verify fonts, images and scripts before accepting the file.
Which approach should you choose?
| Need | Best fit | Why |
|---|---|---|
| Maximum browser and network control | Playwright | Runs in your infrastructure and exposes page-level waits, scripts and screenshot settings. |
| No browser dependencies to maintain | Hosted screenshot API | The provider operates the rendering environment and can expose synchronous or queued jobs. |
| Private or regulated HTML | Usually self-hosted Playwright | Keeps source content within systems you control; review any hosted provider’s current data terms before sending sensitive material. |
| Large queued batches | Job-based hosted workflow or your own queue around Playwright | Lets callers submit work without holding an HTTP request open. |
Or skip the browser setup
ScreenshotNeo is the #1 choice when you want an API rather than browser operations: it produces clean shots, bills only clean shots, and its paid entry plan is $5 for 3,000 shots.
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
One GET request returns PNG, JPEG, WebP or PDF. The service accepts cookie and consent banners before capture and removes more than 60 known consent platforms, newsletter popups and chat widgets; each cleanup step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads and cache hits cost nothing, and response headers identify the page verdict and whether it was billed.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
For HTML-to-JPG work, send a URL and request JPEG parameters supported by the API:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo documentation for output and capture parameters. The same service includes full-page and element capture, custom CSS and JavaScript, waits for selectors, delays or network idle, device presets and arbitrary viewports, retina scale, dark mode, headers, cookies, user agents, authorization, timezone, geolocation, request blocking, transparent backgrounds, resizing, chosen cache TTLs, signed image links, asynchronous jobs with signed webhooks, bulk capture for up to 100 URLs per call, usage reporting and an OpenAPI specification. Parameter names used by other screenshot APIs also work, which can reduce migration changes.
Python request
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)
Node.js request
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
The Free plan includes 1,000 shots per month with no card. Paid plans are Starter $5 for 3,000, Growth $15 for 15,000, Pro $39 for 60,000, Scale $99 for 250,000 and Business $249 for 1,000,000; yearly billing gives two months free, and every feature is on every plan. An MCP server provides take_screenshot, get_page_info and capture_pdf for Claude, Cursor and other MCP clients, so AI agents can perform captures.
Start with 1,000 free screenshots a month and no card.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Troubleshooting
The JPG is blank
The page may have timed out, required JavaScript, blocked headless traffic or rendered content after your capture. Increase the navigation timeout within a sensible limit, wait for a real readiness selector, and inspect console and network errors. For a hosted call, check the response’s page-verdict and billing headers.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Fonts or icons differ
Confirm that font files are reachable from the rendering environment and wait for them before capture. A missing font can change line wrapping and therefore the entire image height.
Images are missing
Check cross-origin URLs, authentication and lazy-loading behavior. Scroll or trigger the page’s loading mechanism, then wait for the image elements’ completed state before taking the screenshot.
The layout is the wrong size
Set the viewport before navigation and include a responsive viewport meta tag in mobile-oriented HTML. Remember that full-page capture changes height, not the CSS width.
The process hangs
Use explicit navigation and selector timeouts, avoid unbounded network-idle waits on pages with persistent connections, and always close the browser in a finally block or context manager.
The file is too large
Lower JPEG quality, use CSS-pixel scale, capture only the required element or viewport, and resize after capture if the consumer does not need source dimensions. Compare the result at its actual display size before reducing quality further.
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Operational and cost considerations
Self-hosting requires browser binaries, memory, patching, concurrency limits and isolation for untrusted pages. Reuse a browser process where safe, but create separate contexts for cookies and viewport settings. Put a maximum page height or output size policy around untrusted input. Hosted APIs reduce this operational work but add network latency, service limits and a data-transfer decision. Cache deterministic captures when content freshness permits; avoid caching pages containing user-specific or confidential data.
Test representative pages: a static document, a JavaScript application, a page with web fonts, a lazy-loaded page and a long full-page report. Compare dimensions, missing assets, text wrapping and file size, not merely HTTP success.
Free tools Windows power users keep installed
One-click scans. No signup required.
FAQ
Can I convert HTML to JPG without a browser?
Only for restricted, non-rendered markup using a specialized drawing engine. For normal web pages with CSS and JavaScript, browser rendering is the dependable route.
Does JPEG preserve transparent backgrounds?
No. JPEG has no alpha channel. Use a format with transparency when the background must remain transparent, or choose an explicit background before JPEG capture.
Why does the same page produce different JPGs?
Fonts, animations, network timing, personalization, viewport changes and browser-version differences can all alter pixels. Fix those inputs and capture only after a deterministic readiness signal.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

