Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To convert HTML to an image, render it in a browser engine and capture the rendered page or an element as a screenshot. The browser applies the page’s CSS and renders browser-supported content; the capture API then saves image bytes to a file or returns them for further processing. For an existing page, navigate to its URL. For your own markup, load it as a page or use a library that accepts an HTML string.

What HTML-to-image conversion actually does

HTML describes document structure; it is not itself a set of pixels. A typical conversion therefore has two stages: a browser engine lays out and renders the document, then a screenshot API captures the result. The browser, its version, installed fonts, viewport, device scale, and loaded resources can all affect the output. A capture is not guaranteed to look identical across browsers or environments.

This approach is useful when the image needs to reflect CSS layout and browser-rendered content. It also means that a page must load and render successfully before capture. For best results, choose the input type, capture region, output format, and pixel scale deliberately.

Choose the input and capture scope

Need Approach Consideration
Capture an existing website Navigate a browser page to its URL, then take a screenshot. The page must be reachable from the environment running the browser.
Render markup held by your application Load the HTML into a browser page or use a wrapper that accepts an HTML string. Relative asset URLs need a valid base or absolute paths; external resources must load for them to appear.
Convert a local HTML document Load the file in the browser or use a wrapper with file-path input. Check file permissions and how local asset paths resolve in your runtime.
Capture only what is visible Take a viewport screenshot. Content outside the viewport is omitted.
Capture a long page Use a full-page screenshot option. Long captures can consume more memory and may expose lazy-loaded content or layout timing issues.
Capture one component Locate the element and take an element screenshot. The selector must match an element that has rendered and is visible.

Use Playwright for configurable screenshots

Playwright supports saving screenshots to a path or returning image data as a buffer. Its screenshot API documents PNG, JPEG, and WebP output, full-page capture, element screenshots, and a scale setting. The examples below show the API pattern; check the documentation for the options and syntax supported by your installed Playwright version.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • 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.

Install Playwright

For a Node.js project, install Playwright and its browser runtime using the installation steps for your chosen package and environment. For example, the package can be added with:

npm install playwright

Follow the current Playwright installation instructions to install the browser binaries your environment needs. In a container or CI job, make sure the runtime includes those browser dependencies as well.

Capture a URL and save a PNG

const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch();
  try {
    const page = await browser.newPage({ viewport: { width: 1440, height: 900 } });
    await page.goto('https://example.com', { waitUntil: 'networkidle' });
    await page.screenshot({ path: 'page.png' });
  } finally {
    await browser.close();
  }
})();

Replace the example URL with the page to capture. The finally block closes the browser even if navigation or capture fails. The selected viewport controls the visible area and the page’s responsive layout. The navigation wait condition is a practical choice, not a guarantee that every application has finished rendering; for dynamic pages, wait for a meaningful selector or application-specific ready state before capturing.

Capture the full scrollable page

await page.screenshot({ path: 'full-page.png', fullPage: true });

fullPage: true asks Playwright to capture the full page rather than only the current viewport. This is useful for documents and landing pages, but very long pages can produce large images. If a page loads images or sections only as they approach the viewport, allow them to load before capture; otherwise some content may not appear in the result.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 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.

Capture a specific element

const card = page.locator('.product-card').first();
await card.screenshot({ path: 'product-card.png' });

Use a selector that identifies the intended element. If it can match several items, choose one explicitly or refine the selector. Make sure the element is present and visible before calling the screenshot method; an element that has not rendered cannot be captured reliably.

Return bytes for processing

const imageBuffer = await page.screenshot({ type: 'png' });
// Pass imageBuffer to an image-processing library or upload it.

Without a path, the screenshot call returns image data as a buffer. This avoids an intermediate output file when the next step is uploading, storing, or processing the image. Keep the buffer in memory only as long as needed, especially when capturing large pages or handling many jobs at once.

Choose format and scale

  • PNG: a lossless choice; a quality setting does not apply to PNG.
  • JPEG: supports a quality setting where documented by the API. It is often useful when a smaller photographic image is preferable to lossless output.
  • WebP: also supports a quality setting in the documented Playwright screenshot API.
  • CSS-pixel scale: captures at CSS-pixel dimensions, which can keep high-DPI output smaller.
  • Device-pixel scale: captures at device-pixel ratio and can produce larger output with more pixels.

For example, to request a JPEG with a quality value and CSS-pixel scale, use the corresponding documented options:

await page.screenshot({
  path: 'page.jpg',
  type: 'jpeg',
  quality: 80,
  scale: 'css'
});

Quality values and supported option combinations are API-specific. Consult the Playwright Page API for the installed version rather than assuming every setting is interchangeable across formats.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • 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.

Use Puppeteer for browser-driven capture

Puppeteer offers a similar workflow: launch a browser, create a page, navigate to a URL, take a screenshot, and close the browser. Its screenshots guide also documents taking a screenshot of a particular element with an element handle. As with Playwright, the output reflects the rendered browser page rather than an abstract conversion of HTML source.

Capture a page with Puppeteer

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  try {
    const page = await browser.newPage();
    await page.goto('https://example.com', { waitUntil: 'networkidle2' });
    await page.screenshot({ path: 'page.png' });
  } finally {
    await browser.close();
  }
})();

Install Puppeteer and its browser according to the current project guidance and your deployment environment. Navigation wait modes can behave differently depending on a site’s network activity; if the page continues making requests, wait for a specific element or condition instead of relying only on network idleness. See the Puppeteer screenshots guide for the documented capture workflow and element screenshots.

Use Browsershot from PHP

Spatie Browsershot provides a PHP-facing interface for HTML-to-image and PDF workflows using Puppeteer running headless Chrome. Its project documentation shows URL input and HTML-string input, and documents file-path HTML input. This is a fit when your application is in PHP but you want a browser-rendering workflow. Installation, compatibility, and runtime requirements can change, so verify them in the project’s current documentation.

Capture a URL

use SpatieBrowsershotBrowsershot;

Browsershot::url('https://example.com')
    ->save('page.png');

Render an HTML string

use SpatieBrowsershotBrowsershot;

$html = '<html><body><h1>Hello</h1></body></html>';

Browsershot::html($html)
    ->save('hello.png');

When providing a string, ensure any stylesheets, fonts, and images it references can be resolved by the browser process. For a local HTML file, use the file-path input documented by Browsershot and confirm that the path is accessible to the process that launches Chrome.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • 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

Choose a browser library or a hosted API

If you already operate a browser runtime, Playwright or Puppeteer gives you direct control over navigation and capture in application code. A wrapper such as Browsershot can expose the same general browser-rendering approach from PHP. A hosted screenshot API can reduce the browser setup you manage yourself; choose it when its input, output, and operational behavior fit your application.

ScreenshotNeo is a website screenshot API and MCP server for developers. For a URL-based capture, it accepts a GET request and returns an image or PDF. Its response indicates the page verdict and billing status in headers, so a caller can distinguish outcomes such as a cache hit or failed load. Its capture options include full-page and element screenshots, image format and viewport controls, custom CSS and JavaScript, wait conditions, and request blocking. Check the current ScreenshotNeo documentation for parameters and response handling.

cURL

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Python

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)

Node.js

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

These examples save or retrieve the response body as image data; production code should also inspect the response status and the documented page-verdict and billing headers before treating a body as a successful image. The API supports PNG, JPEG, WebP, or PDF output. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, or other MCP clients.

Or skip the browser setup

ScreenshotNeo removes cookie banners, popups, and chat widgets before the shot. Bot checks, blank pages, and failed loads are never billed; MCP tools let AI agents take screenshots. The free plan includes 1,000 shots a month with no card, and paid plans start at $5 for 3,000. Send one request:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Sign up for ScreenshotNeo’s free plan.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Operational considerations

Rendering time and concurrency

A screenshot job includes browser startup or reuse, navigation, page rendering, and image encoding. Heavy pages and full-page captures generally take more resources than a small viewport capture. If capturing many pages, control concurrency so browser processes and image buffers do not exhaust memory or CPU. Reuse browser processes where appropriate for your framework, while isolating page state between jobs.

Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 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.

Deterministic output

For repeatable captures, keep the browser version, viewport, scale, fonts, locale, and relevant page state consistent. Wait for the specific content you need, and consider disabling animations or supplying stable test data where your workflow permits. External images, ads, and other third-party resources can change or fail independently of your own HTML.

Security and deployment

Browser automation processes web content, so treat input URLs and HTML as untrusted if users can supply them. Restrict access to internal network destinations where appropriate, avoid exposing secrets in page content or logs, and follow your platform’s browser sandbox and process-isolation guidance. Confirm that headless browser binaries and required system libraries are available in the production environment.

Troubleshooting common capture problems

  • The image is blank or incomplete: navigation may have finished before client-side rendering or asset loading. Wait for a known selector or application-ready condition, then capture.
  • Images are missing: check that URLs resolve from the browser environment, that authentication is present if required, and that lazy-loaded images had an opportunity to load.
  • The layout is different from the browser you expect: set the viewport explicitly and check the browser engine, device scale, fonts, and responsive breakpoints.
  • A full-page image is too large: capture a specific element or viewport, reduce the page content, or choose CSS-pixel scale where available.
  • An element screenshot fails: verify the selector matches, wait for the element to appear, and ensure it is visible and not detached during capture.
  • Navigation hangs or times out: some pages keep network connections open. Use a suitable navigation condition or wait for a page-specific element rather than requiring all network activity to stop.
  • The browser fails to launch in CI or a container: verify browser installation and OS-level dependencies for the installed library version and deployment image.
  • PHP cannot find Chrome or Puppeteer: confirm the Browsershot installation and runtime configuration in its documentation, including that the web or worker process can access the configured binaries.
  • The output format or quality option is rejected: confirm the format name and options supported by the installed API version; quality is not a PNG setting in Playwright’s documented API.

Frequently Asked Questions

Can I convert HTML to an image without a browser?

For a faithful rendering of HTML and CSS, use a browser engine or a tool built on one; the approaches here capture browser-rendered pixels.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Which approach should I use for PHP?

Browsershot is the PHP-oriented option covered here; confirm its current requirements and compatibility in the project documentation.

Can Playwright return an image without writing a file?

Yes. Calling the screenshot API without a path returns image data as a buffer.

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.