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.
| Setup | Background in the PDF? |
|---|---|
| Defaults | No (white) |
printBackground: true | Yes |
CSS print-color-adjust: exact, no option | Yes |
printBackground: true plus a print stylesheet that clears backgrounds | No |
| Same, but rendered with screen media | Yes |
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:
- Remove or override the rule for the elements you need, inside your own
@media printblock with higher specificity. - Render with screen styles instead of print styles. Then
@media printrules are ignored, and the PDF looks like the page on screen:
// 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?
- Background image never loaded. If the image is on a server, the PDF can be generated before it arrives. Wait for the network to go idle (
waitUntil: 'networkidle0'in Puppeteer, or"waitUntil": "networkidle0"in the PDFLoom API), use an absolute URL, or inline small images as data URIs. - Relative URLs with
setContent. HTML passed as a string has no base URL, sourl(/img/bg.png)can't resolve. Use absolute URLs or add a<base href="https://your-site/">tag. - Dark mode. If your CSS uses
prefers-color-scheme, the headless renderer uses the light scheme unless you emulate dark mode, so the PDF may not match what you see on screen.
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
- How to convert HTML to PDF in Node.js (2026 guide)
- wkhtmltopdf alternatives in 2026: what to use now that it is archived
- Add page numbers, headers and footers to an HTML-generated PDF
- CSS page breaks in HTML to PDF (tested in Chrome)
- Fonts missing or wrong in HTML to PDF? 5 causes
- PDFLoom vs DocRaptor: HTML to PDF API comparison
- PDFLoom vs PDFShift: HTML to PDF API comparison
- PDFLoom vs Api2Pdf: pay-per-use vs flat pricing