Your HTML looks correct in the browser: colored table rows, a shaded header, a background image behind the logo. Then you run it through an HTML-to-PDF converter and all of that styling is gone. The text and layout survive, but the backgrounds render as plain white. The HTML is not broken, and the converter is not ignoring your CSS. This is expected print behavior.
Why backgrounds get dropped
PDF generation runs through the same code path as printing. By default, browsers and print engines drop background colors and background images to save ink and keep printed pages readable. Most HTML-to-PDF tools that use a headless browser, such as Puppeteer, Playwright, or wkhtmltopdf, inherit this same default. So a CSS rule like background-color or background-image is parsed correctly, but the rendering layer chooses not to paint it in print mode.
The fix: print-color-adjust
The CSS property print-color-adjust controls this. Setting it to exact tells the engine your colors are intentional and should be preserved. Chromium-based engines also need the -webkit-print-color-adjust prefix. Apply both to the elements that have backgrounds, or to html and body to cover the whole document:
@media print {
html,
body,
.has-background {
-webkit-print-color-adjust: exact;
print-color-adjust: exact;
}
}A few things to check if backgrounds still do not appear. First, the property is inherited, so applying it to html or body cascades to the elements inside, but confirm the rule actually reaches the element painting the background and is not overridden lower down. Second, make sure the style is not trapped behind a media query that the converter does not match; placing it inside @media print is the safest option because PDF rendering counts as print. Third, verify the converter loads your stylesheet at all, especially when the CSS is external and the engine renders before the file finishes loading.
Once print-color-adjust: exact is in place and the rule reaches the right element, your colored rows, shaded headers, and background images will carry through to the generated PDF.
Back to All Questions