Hi,

I print a HTML table with background colour but, it doesn't print it with colours. Why?

Thanks

Dani AI

Generated

— this is a browser/printing preference issue, as and noted. To expand: modern browsers will often suppress background colors to save ink, but you can increase the chance that backgrounds print by adding a print-specific CSS hint and giving critical areas explicit colors.

A minimal, practical print stylesheet example:

@media print {
  .print-bg {
    background-color: #f2f2f2 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}

Add that to your print CSS (or inside a @media print block) for table rows or cells that must show shading. Note that this is only a request to the browser/engine; user print settings, OS print dialogs, and printer drivers can still override it. If backgrounds remain absent, test with the browser Print Preview or "Save as PDF" to isolate browser behavior from the physical printer. For content that must remain visible even when backgrounds are stripped, use strong borders, alternating text styles, or small inline images as fallbacks.

Authoritative notes: user agents may ignore backgrounds when printing (W3C CSS). The print-color-adjust property and its WebKit prefix are the practical, supported way to ask browsers to preserve colors when printing (W3C CSS2.1 colors, MDN: print-color-adjust).

Recommended Answers

All 2 Replies

Hi Veledrom,

This is quite a common problem and the answer is simple, there isnt anything wrong with your coding, its simply the users choice and the preferences s/he has the browser set to.

Now... don't get me wrong, one browser does it by default and that is Apple Safari, not sure about others

By the way, should search your questions first, this topic has already been discussed:
http://www.daniweb.com/forums/thread53080.html

This is a setting on most browsers, although some don't print the background at all.

On Firefox, the setting is in the Page Setup dialog box.

In addition, the printer and the printer driver mist be capable of doing this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.