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

To convert pasted HTML into a PNG that matches a real browser’s rendering, load the HTML string into a Playwright page and save a screenshot. Use page.setContent(html) to render the markup, then page.screenshot({ path: 'output.png', type: 'png' }). For an element already visible in a browser page, the JavaScript library html2canvas is a lighter in-page option, but it recreates the image from DOM and CSS information rather than taking a true browser screenshot.

Choose the right way to turn HTML into a PNG

The best method depends on where your pasted HTML is and how closely the PNG needs to match what a browser displays:

  • Use Playwright when you have an HTML string and want to render it in a browser, especially for complex CSS, server-side automation, or repeatable captures.
  • Use html2canvas when the element is already rendered in a browser page and its styles are within the library’s supported feature set.

Playwright takes a screenshot of the browser-rendered page. html2canvas instead traverses the DOM and reconstructs an image from the styles and information it can access; it may differ from the browser’s actual pixels. See the Playwright Page API and the html2canvas documentation.

Convert a pasted HTML string with Playwright

This Node.js example puts a complete HTML document into a Chromium page and writes a full-page PNG named output.png. Install Playwright in your project first with npm install playwright. Playwright also needs its browser binaries installed; use the installation command for the browser you intend to run as described in its setup documentation.

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.
const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch();
  const page = await browser.newPage({
    viewport: { width: 1200, height: 800 }
  });

  const html = `
    <!doctype html>
    <html>
      <head>
        <meta charset="utf-8">
        <style>
          body { font: 16px sans-serif; margin: 24px; }
          h1 { color: #174ea6; }
        </style>
      </head>
      <body>
        <h1>Hello, PNG</h1>
        <p>Rendered from pasted HTML.</p>
      </body>
    </html>
  `;

  try {
    await page.setContent(html);
    await page.screenshot({
      path: 'output.png',
      type: 'png',
      fullPage: true
    });
  } finally {
    await browser.close();
  }
})();

Save the code in a file such as convert.js and run node convert.js. The output is written in the current working directory. The example uses a fixed 1200-by-800 CSS-pixel viewport; fullPage: true makes the screenshot include the document beyond the visible viewport. For a viewport-only image, omit fullPage or set it to false.

Control output size and sharpness

Playwright’s screenshot API supports PNG, full-page capture, and scale options. With CSS scale, an output pixel corresponds to a CSS pixel. Device scale follows the page’s device-pixel ratio and can produce a larger image with more pixels. Larger output can also consume more memory. Pick a viewport that matches the intended layout, then choose scale based on whether you value smaller files or additional pixel detail. Consult the Page API reference for the current screenshot options.

For example, a narrow viewport can cause responsive HTML to wrap differently from a desktop layout. A full-page capture includes the page’s vertical content, but it does not mean that an oversized image is unlimited: very tall or wide output can hit browser or platform limits.

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.

Wait for external resources and dynamic content

Inline CSS in the pasted string is available immediately, but linked stylesheets, web fonts, images, and scripts may load separately. If you capture before those resources are ready, the PNG can show fallback fonts, empty image areas, or an incomplete layout. Use a readiness condition that reflects the page: wait for a specific selector, image, font, or application signal when appropriate. A fixed delay may work for a known, stable case, but it is not a reliable universal wait strategy.

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

For remote images and other external resources, confirm that the browser can reach the URL and that the server permits the request. Playwright uses a real browser, but it does not bypass browser security rules or make blocked resources available.

Capture an element already on a page with html2canvas

If your pasted markup is already displayed in a browser page and you only need one element, html2canvas can render that element to a canvas and export it as PNG. Load the library in your page, then select the element you want to capture:

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.
const element = document.querySelector('#capture');
if (!element) {
  throw new Error('Could not find #capture');
}

const canvas = await html2canvas(element);
const link = document.createElement('a');
link.download = 'output.png';
link.href = canvas.toDataURL('image/png');
link.click();

Replace #capture with the selector for your target element. The project’s examples also demonstrate cropping with x, y, width, and height, and increasing pixel density with scale.

Choose html2canvas for convenience, not pixel-perfect fidelity. It implements selected CSS features and builds an image from the DOM; unsupported or differently implemented styles may render unexpectedly. Its documentation explicitly cautions that the result may not be completely accurate to the real browser representation.

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

Playwright vs. html2canvas

Decision Playwright html2canvas
What it captures Rendered pixels from a browser page. [Playwright Page API] A reconstructed canvas image based on accessible DOM and style information. [html2canvas documentation]
Best fit An HTML string, automated or server-side rendering, or cases where browser fidelity matters. An element already present in a page when client-side capture is convenient. [html2canvas examples]
CSS fidelity Uses a browser’s rendering engine; results still depend on browser version, fonts, resources, viewport, and page state. Limited to the CSS properties the library implements; visual differences are possible.
Cross-origin content Subject to browser security and resource-loading conditions. Cannot bypass browser content policies; cross-origin images may be skipped or taint the canvas, and cross-origin iframe contents are inaccessible. [html2canvas FAQ]
Runtime Requires a browser automation setup. Runs in a browser; its FAQ says it is not suitable for Node.js alone because Node does not provide the required browser APIs. [html2canvas FAQ]

Or skip the browser setup

If you need screenshots of web pages regularly rather than rendering a local pasted string, ScreenshotNeo is a website screenshot API and MCP server for developers. For pasted markup, use the browser workflow above unless you have made the HTML available to the service: the one-call URL example below captures a web page, not an arbitrary local string.

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
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 API documentation for request details. ScreenshotNeo removes cookie or consent banners, newsletter popups, and chat widgets before capture; those steps can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and responses identify the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and MCP clients. The free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots. 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

Troubleshoot common conversion problems

The PNG is unstyled

Include the needed CSS in the pasted HTML or check that linked stylesheets can load. If styles are external, capture only after the relevant stylesheet or page-ready condition is satisfied.

Images or fonts are missing

Check that the resource URLs are valid and reachable from the browser environment. For html2canvas, cross-origin images require suitable CORS support or a proxy configured to provide the image; the library cannot override browser content policy. Cross-origin iframe content is not accessible to html2canvas. See the html2canvas FAQ.

Free tools Windows power users keep installed

One-click scans. No signup required.

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

The result is clipped

With Playwright, decide whether you want the visible viewport or the entire scrollable document and set fullPage accordingly. With html2canvas, check the target element’s dimensions and the capture options. The FAQ notes that setting windowWidth and windowHeight to the element’s scroll dimensions can help when output is clipped.

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.

The PNG is blank or partly drawn

Very large canvases may exceed size limits that vary by browser and platform. Reduce the capture dimensions or split a tall page into sections. There is no single safe maximum that applies to every device.

The output looks blurry

Check the chosen viewport and capture scale. A higher device-pixel scale can add detail, but it also increases image dimensions and memory use. If the image will be displayed at a particular size, avoid enlarging a low-resolution capture afterward.

Practical reliability and cost considerations

For occasional conversions, running Playwright locally avoids relying on an external screenshot service, but you must install and maintain the browser runtime and make required page resources available. For repeated captures, automate a stable HTML input, viewport, browser version, and readiness condition so layout changes are easier to diagnose. A browser update or changed font/resource can alter the pixels even when the HTML string stays the same.

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

html2canvas is suitable when its supported CSS and client-side browser environment meet the need; it avoids a separate browser automation process but is not a substitute for a browser screenshot when fidelity is essential. Large captures carry a memory and image-size trade-off with either approach. If captures are of published web pages rather than a pasted local string, a hosted API can reduce browser setup, but check its request model and billing behavior against your workload.

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.