← Back to Guides

Why Your HTML-to-Image Render Is Blank (CORS & Font Fixes)

By Sachin Jagtap · Builder of HTMLtoImage.online · Updated October 2026

You wrote some HTML, ran it through an image converter or a library like html2canvas, and got back a blank rectangle, a black box, or a render with the images and fonts mysteriously missing. It is one of the most common frustrations when turning HTML into an image — and it almost always comes down to a handful of fixable causes. Here is what actually goes wrong, and how to fix each one.

1. Cross-origin images (the CORS problem)

This is the number-one cause. When a converter draws an image hosted on another domain onto a <canvas>, the browser marks the canvas as tainted for security. A tainted canvas throws a SecurityError the moment you try to export it, resulting in a failed or blank output.

Newer libraries such as modern-screenshot fail differently: they fetch each image and embed it, so a host that blocks cross-origin requests doesn't throw an error at all. The image simply goes missing from the output, which is harder to spot. (Our converter counts these and shows a warning when it happens.)

Fix it one of three ways:

  • Host the image with CORS enabled with an Access-Control-Allow-Origin: * header.
  • Convert the image to a base64 data URI and embed it inline. This is the most reliable fix because data URIs are same-origin by definition:
    <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUg..." alt="Icon">
  • Proxy the image through your own domain so it counts as same-origin.

2. Web fonts that never loaded

Image capture is synchronous — it paints whatever is ready at that exact millisecond. If custom fonts haven't finished downloading over the network, text renders in a system fallback or invisibly.

Fix it by awaiting fonts in JavaScript:

// Wait for all @font-face rules to resolve
await document.fonts.ready

// Allow the browser layout engine one frame to paint
await new Promise(r => setTimeout(r, 200))

const dataUrl = await domToPng(node, { scale: 2 })

3. A black background instead of transparent

JPG files have no alpha transparency channel, so transparent pixels have to become some color, and many encoders pick black. The fix is to give the image a white background before encoding — but be careful how you do it.

The obvious approach is modern-screenshot's backgroundColor: '#ffffff' option. The catch: it doesn't just fill behind your content — it also forces the captured element's own background-color to white. A dark card or a colored banner comes out white. The safer pattern is to render with a transparent background and flatten onto white yourself:

import { domToCanvas } from 'modern-screenshot'

const rendered = await domToCanvas(node, { scale: 2 })  // transparent background

const flat = document.createElement('canvas')
flat.width = rendered.width
flat.height = rendered.height
const ctx = flat.getContext('2d')
ctx.fillStyle = '#ffffff'
ctx.fillRect(0, 0, flat.width, flat.height)
ctx.drawImage(rendered, 0, 0)

const jpg = flat.toDataURL('image/jpeg', 0.8)

If you don't need a JPG specifically, export a transparent PNG or WebP instead.

4. Modern CSS the renderer can't draw

html2canvas doesn't use the browser's rendering engine — it re-implements CSS painting itself, and version 1.4.1 has no support for effects like filter, mask, clip-path, backdrop-filter, or modern color functions such as oklch(). Layout (Flexbox, Grid, positioning) is fine, because it reads positions from the browser.

modern-screenshot takes a different route: it serializes your element into an SVG <foreignObject> and lets the browser paint it. In our tests with modern-screenshot 4.7 in Chrome (October 2026), that fixed most of the gaps — but not all of them:

  • ✅ oklch() colors render correctly
  • ✅ clip-path shapes are clipped correctly
  • ✅ filter (e.g. grayscale(), blur()) is applied
  • ✅ mask-image gradients mask correctly
  • ❌ backdrop-filter is still ignored — the content behind is drawn unfiltered

backdrop-filter fails because a browser doesn't apply it inside an SVG image, which is how foreignObject rendering works. For "frosted glass" designs, fake the effect for the export: put filter: blur() on a copy of the background layer behind the panel, or replace the glass with a semi-transparent solid color such as rgba(255, 255, 255, 0.85).

Frequently Asked Questions

Why is my HTML-to-image render blank or missing external images?
Usually a cross-origin image. With html2canvas it taints the canvas and toDataURL() throws a SecurityError; with modern-screenshot the image is silently left out. Embed images as base64 data URIs or enable CORS on the image host.
Why did my render come out completely black?
The JPG format doesn't support transparency, so transparent areas can turn black. Render with a transparent background, then draw it onto a white-filled canvas before encoding the JPG — or switch to PNG/WebP.
Why is my backdrop-filter or frosted-glass effect missing?
html2canvas doesn't support backdrop-filter, and foreignObject-based renderers like modern-screenshot can't draw it either, because browsers don't apply it inside an SVG image. Fake the effect for export with filter: blur() on a copy of the background, or use a semi-transparent solid color.
How do I guarantee custom web fonts render properly?
Wait for document.fonts.ready in JavaScript before capturing the element, and ensure font files are served with CORS-friendly headers.

About the author — Sachin Jagtap is a builder and the creator of HTMLtoImage.online, a free, privacy-first tool for converting HTML, CSS, and SVG code into PNG, JPG, and WebP images.