Guides

Background colors missing in HTML to PDF? 3 fixes

Your page looks right in the browser, but the PDF has white table headers, no coloured badges and no background images. That's Chrome's print engine saving ink: by default it drops background colours and images when printing. This affects Puppeteer, Playwright and any other tool that uses Chrome's page.pdf(). We tested each fix below with Chrome 155 by rendering a red box to PDF and checking the pixel colour.

SetupBackground in the PDF?
DefaultsNo (white)
printBackground: trueYes
CSS print-color-adjust: exact, no optionYes
printBackground: true plus a print stylesheet that clears backgroundsNo
Same, but rendered with screen mediaYes

Background images behave the same way as colours. A tiled background image was dropped by default and printed with printBackground: true.

Fix 1: turn on printBackground

// Puppeteer
await page.pdf({ path: 'out.pdf', format: 'A4', printBackground: true });

// Playwright
await page.pdf({ path: 'out.pdf', format: 'A4', printBackground: true });

This is the same as ticking "Background graphics" in Chrome's print dialog. In the PDFLoom API printBackground is already true by default, so backgrounds print unless you turn it off.

Fix 2: print-color-adjust in your CSS

If you can't change the PDF options (for example, users print the page themselves, or a library calls page.pdf() for you), put the fix in the stylesheet:

body {
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

In our test this printed the background even with printBackground off. Setting it on body was enough, because the property is inherited. Keep the -webkit- prefixed line for older Chromium and Safari.

Fix 3: a print stylesheet is removing them

If backgrounds are still missing with printBackground: true, something in your CSS is clearing them for print. Many CSS frameworks and boilerplates include a print reset like this:

@media print {
  *, *::before, *::after { background: transparent !important; box-shadow: none !important; }
}

With that rule present, our red box came out white even with printBackground: true. You have two options:

// Puppeteer
await page.emulateMediaType('screen');
await page.pdf({ printBackground: true });

// PDFLoom API
{ "html": "...", "emulateMedia": "screen" }

Screen media also ignores print-only rules you might want, such as hiding navigation. Check the result, and use @media screen rules to hide those elements.

Still missing?

Related: CSS page breaks in HTML to PDF, fonts missing or wrong in the PDF and page numbers, headers and footers. To try it without code, paste your HTML into the free HTML to PDF converter (backgrounds on).

Tested 25 November 2026 with Chrome 155 via Puppeteer: a 400 px red box rendered to A4 PDF, rasterised with pdftoppm, and the pixel colour checked.


More guides