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

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

To turn HTML into a screenshot, render it in a real browser and capture the rendered page with Playwright or Puppeteer. For raw HTML, inject the markup with page.setContent(), set a viewport, wait for any assets or scripts your page needs, then save a viewport, full-page, element, or clipped screenshot. Below are runnable examples and the choices that affect the result.

What you need to know before capturing HTML

An image renderer must interpret the HTML and CSS, load fonts and images, and run any JavaScript that changes the page. A browser automation library such as Playwright or Puppeteer does that work and exposes a screenshot method. This is different from converting the source text directly: the capture shows the browser’s rendered result, not the markup itself.

Use a fixed viewport when you want repeatable dimensions. Decide whether you need only the visible window, the entire scrollable page, or a specific element or rectangle. Then wait until the content you care about is ready. A screenshot taken before a web font, image, or application update finishes can be valid but visually incomplete.

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

Create a screenshot with Playwright

Install Playwright and its browser from your project directory:

#1 Best Overall
Sale
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents
npm install playwright
npx playwright install chromium

Save this as screenshot.mjs and run it with node screenshot.mjs:

import { chromium } from 'playwright';

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

  await page.setContent(`<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <style>
      body { font: 16px sans-serif; margin: 2rem; }
      h1 { color: #174ea6; }
    </style>
  </head>
  <body>
    <h1>Hello</h1>
    <p>Rendered from HTML.</p>
  </body>
</html>`);

  await page.screenshot({ path: 'page.png' });
} finally {
  await browser.close();
}

Playwright writes the image to page.png when you pass path. If you omit path, the screenshot API returns image bytes, which is useful for passing the result to an image-processing or pixel-diff step. Its screenshot API also includes controls for image type, quality, transparency, clipping, and scale. See the official Playwright Screenshots guide and Page API.

Capture a full page, element, or rectangle

Use the following variants after the page is ready:

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.
// Visible viewport only
await page.screenshot({ path: 'viewport.png' });

// Full scrollable document, including content below the fold
await page.screenshot({ path: 'full.png', fullPage: true });

// One element selected by CSS
await page.locator('.header').screenshot({ path: 'header.png' });

// A rectangle in page coordinates
await page.screenshot({
  path: 'region.png',
  clip: { x: 40, y: 60, width: 640, height: 360 }
});

A full-page capture is convenient for a document or report, but can result in a very tall image. If the reader only needs a component or a defined area, capture that element or clip instead. Playwright describes a full-page screenshot as a capture of the full scrollable page. Consult the official examples for current API details.

Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors

Choose format, scale, and animation behavior

PNG is a sensible default when you want lossless output. For JPEG or WebP, select the type and a quality value supported by the API to trade image size against compression. Playwright also offers a screenshot scale choice: CSS-pixel scale produces one image pixel per CSS pixel, while device-pixel scale produces a higher-resolution image at high-DPI settings. The current API documentation lists screenshot options, including controls for animations and transparency; use those when they fit your capture and output requirements rather than assuming a page will settle identically on its own.

Create a screenshot with Puppeteer

Install Puppeteer, which downloads a compatible browser as part of its standard installation, then save this example as screenshot.mjs:

npm install puppeteer
import puppeteer from 'puppeteer';

const browser = await puppeteer.launch();
try {
  const page = await browser.newPage();
  await page.setViewport({ width: 1280, height: 800 });

  await page.setContent(`<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <style>body { font: 16px sans-serif; margin: 2rem; }</style>
  </head>
  <body>
    <h1>Hello</h1>
    <p>Rendered from HTML.</p>
  </body>
</html>`);

  await page.screenshot({ path: 'page.png', fullPage: true });
} finally {
  await browser.close();
}

Puppeteer’s Page.setContent() sets the page content to the supplied markup; Page.screenshot() can save by path or return image data, and accepts fullPage. For an element capture, locate the element and use its handle’s screenshot() method. Puppeteer also supports base64 output and clipping. See the official Puppeteer Screenshots guide, Page.screenshot() API, and Page API.

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

Make the capture reflect the intended rendered state

Setting HTML content is only the first part of readiness. A simple static document may be ready immediately after setContent(); a document with external resources or application logic may not be. Wait for the specific thing you need, rather than choosing a delay without knowing what it waits for.

Rank #3
Sale
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.
  1. Set a viewport. Specify width and height before capture so text wrapping and layout have known dimensions.
  2. Load or inject the document. Use setContent() for raw markup. For a live page, navigate to its URL instead.
  3. Wait for relevant content. For a selector-driven page, wait for the selector. For a document that depends on remote resources, choose a suitable navigation readiness condition and then check fonts, images, custom elements, or application data that matter to your image.
  4. Handle animation. If a repeatable frame matters, account for animations with the available screenshot controls or your page’s own styling.
  5. Capture the right scope. Pick the viewport, full document, element, or clip based on what must appear in the result.
  6. Close the browser. Put shutdown in a finally block so the browser process exits even if capture fails.

Puppeteer’s official screenshot example uses waitUntil: 'networkidle2' during navigation. That can be a useful signal for some pages, but raw HTML and applications with persistent network activity can require a more specific readiness check. Neither a timeout nor a network-idle condition proves that every visual dependency has completed.

Pick an output that suits its destination

Need Capture choice Practical consideration
Quick preview of the current layout Viewport screenshot Content outside the viewport is excluded.
Documentation of a long document Full-page screenshot The image may be very tall; consider whether a focused section is more useful.
Reusable component image Element screenshot Choose a stable CSS selector for the intended component.
Specific portion of the page Clip rectangle Use coordinates and dimensions that match the rendered layout.
Lossless image or further pixel processing PNG or returned bytes Playwright can return a buffer without a path; Puppeteer supports binary output.
Smaller lossy image JPEG or WebP with quality control Compression can reduce file size but may introduce visual artifacts.

For automation and visual comparison, returning bytes can avoid an intermediate file. For a straightforward manual workflow, a path makes the output easy to locate. Choose CSS-pixel or device-pixel scale deliberately: the former corresponds directly to CSS layout dimensions, while the latter produces more pixels for a high-DPI capture.

Troubleshoot common screenshot problems

The file is blank or the page looks unfinished

Check that the markup is valid and that the expected content is in the document before capturing. If JavaScript populates the page asynchronously, wait for a page-specific selector or state. If styles or images are external, confirm that the browser can access those resources and that the capture occurs after they load.

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

Fonts, images, or custom elements are missing

These assets may not have finished loading when the screenshot ran, or their URLs may be inaccessible from the browser process. Wait for the relevant font or image readiness, verify resource paths and network access, and ensure custom elements have upgraded before capture. A successful screenshot call only means an image was captured; it does not guarantee the page has all desired assets.

Rank #4
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient

The screenshot cuts off content

A default screenshot captures the current viewport. Set fullPage: true for the full scrollable document, or capture a particular element or clip when a whole-page image is not appropriate. If the full image is unexpectedly short, verify that content has rendered before the capture.

The output differs between runs

Fix the viewport, wait for the same page state, and control animation where the API or page allows it. Check whether content changes with time, remote data, or font availability. Avoid comparing captures made with different device-pixel settings or image formats.

The browser process does not exit

Ensure browser.close() runs after success and failure. The examples use try/finally so an exception during page setup or capture does not leave the launched browser running.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If you need screenshots without managing a local browser runtime, ScreenshotNeo is a website screenshot API and MCP server. For raw HTML and CSS, its API supports HTML/CSS-to-image capture; one GET request can return an image or PDF. The simple URL form is:

Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.
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 authentication and request options. Cookie banners are accepted and removed, along with 60+ known consent platforms, newsletter popups, and chat widgets, before the shot; each cleanup step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and each response identifies the page verdict and billing status in headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf for AI agents. The Free plan includes 1,000 screenshots a month without a card; paid plans start at $5 for 3,000 shots. Create an account at ScreenshotNeo’s free sign-up page.

Which method should you use?

Use Playwright or Puppeteer when you need local control over a browser-rendered page, want to integrate capture into an existing JavaScript workflow, or need to inspect and manipulate the page before saving. Inject raw HTML with setContent(), define a viewport, wait for the page state you need, and choose the narrowest capture scope that answers your task. A hosted API is an alternative when running and maintaining the browser locally is the part you want to avoid.

Frequently Asked Questions

Can I screenshot HTML without saving it to a file first?

Yes. Both Playwright and Puppeteer can return image data from their screenshot APIs when you do not provide a file path.

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

Does a full-page screenshot include content below the fold?

Yes. Set fullPage: true to capture the full scrollable document.

Can I capture only one HTML element?

Yes. Use Playwright’s locator screenshot or Puppeteer’s element-handle screenshot method.

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.