<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Wajid Ali</title>
    <description>The latest articles on DEV Community by Wajid Ali (@member_902de54c).</description>
    <link>https://dev.to/member_902de54c</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4262786%2Fc401da8d-3740-483d-b246-3789eb2e54ff.png</url>
      <title>DEV Community: Wajid Ali</title>
      <link>https://dev.to/member_902de54c</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/member_902de54c"/>
    <language>en</language>
    <item>
      <title>Building print-accurate test pages with CSS (and the things browsers quietly get wrong)</title>
      <dc:creator>Wajid Ali</dc:creator>
      <pubDate>Tue, 24 Nov 2026 14:17:28 +0000</pubDate>
      <link>https://dev.to/member_902de54c/building-print-accurate-test-pages-with-css-and-the-things-browsers-quietly-get-wrong-21h3</link>
      <guid>https://dev.to/member_902de54c/building-print-accurate-test-pages-with-css-and-the-things-browsers-quietly-get-wrong-21h3</guid>
      <description>&lt;p&gt;I run a small site with printer test pages: color sheets, nozzle check patterns, alignment grids. It sounded like the easiest project I'd ever ship. It's a page you print, so how hard can that be?&lt;/p&gt;

&lt;p&gt;Pretty hard, it turns out. Getting a webpage to come out of a printer looking exactly the way you designed it means fighting the browser at almost every step. Here's what I ran into and what actually worked.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Browsers strip your backgrounds by default
&lt;/h2&gt;

&lt;p&gt;This was the first surprise. You design a nice CMYK block, hit print, and get a blank page with a few labels on it. Chrome, Firefox and Safari all drop background colors and images when printing to save ink, unless the user ticks "Background graphics" in the print dialog.&lt;/p&gt;

&lt;p&gt;You can ask the browser to keep them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.swatch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;-webkit-print-color-adjust&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;exact&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;print-color-adjust&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;exact&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It works in current Chromium, Firefox and Safari, but treat it as a request rather than a guarantee. For anything that &lt;em&gt;has&lt;/em&gt; to print, like the actual color patches, I stopped relying on &lt;code&gt;background-color&lt;/code&gt; and drew them as inline SVG &lt;code&gt;&amp;lt;rect&amp;gt;&lt;/code&gt; elements with a &lt;code&gt;fill&lt;/code&gt;. The browser treats SVG fills as content, not background, so they print even when background graphics are off.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. &lt;code&gt;@page&lt;/code&gt; is your friend, but only half of it is supported
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@page&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;A4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10mm&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;size&lt;/code&gt; and &lt;code&gt;margin&lt;/code&gt; are reliable in Chromium. Firefox has supported &lt;code&gt;size&lt;/code&gt; only since fairly recently, so test your target versions. The margin boxes from the spec, like &lt;code&gt;@top-center&lt;/code&gt; for running headers, are still patchy, so I don't use them for anything important.&lt;/p&gt;

&lt;p&gt;The bigger issue is that users pick their own paper size. Someone in the US prints your A4 layout on Letter and the bottom 18mm gets clipped. I ended up shipping separate A4 and Letter versions instead of one "responsive" print layout, because a test page that changes scale isn't really a test page anymore.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Use physical units for anything that gets measured
&lt;/h2&gt;

&lt;p&gt;On screen, &lt;code&gt;px&lt;/code&gt; is fine. On paper, an alignment grid needs real millimetres, because people put a ruler on it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.grid-line&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.25mm&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.calibration-box&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100mm&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100mm&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;CSS defines &lt;code&gt;1in = 96px&lt;/code&gt;, and print engines respect that, so &lt;code&gt;mm&lt;/code&gt; and &lt;code&gt;in&lt;/code&gt; come out accurate as long as the user prints at 100%. That's the catch: "Fit to page" or "Shrink to fit" in the print dialog silently scales everything. I added a 100mm reference box with a visible label so people can check the scale with a ruler before trusting the rest of the page.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Hairlines disappear, and thick lines lie
&lt;/h2&gt;

&lt;p&gt;A 1px border looks crisp on a retina screen and then either vanishes or prints as a fuzzy grey line, depending on the printer's resolution and driver. For nozzle check patterns that's a real problem, because the whole point is spotting a missing line.&lt;/p&gt;

&lt;p&gt;What worked for me:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Line weights of at least 0.25mm for diagonal and step patterns&lt;/li&gt;
&lt;li&gt;Solid fills rather than borders for the bars&lt;/li&gt;
&lt;li&gt;Pure process colors (&lt;code&gt;#00FFFF&lt;/code&gt;, &lt;code&gt;#FF00FF&lt;/code&gt;, &lt;code&gt;#FFFF00&lt;/code&gt;, &lt;code&gt;#000000&lt;/code&gt;) so each bar maps to one cartridge as closely as the driver allows&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One thing worth knowing: the browser sends RGB, and the printer driver converts it to CMYK. You don't control that conversion, so "pure cyan" on screen isn't guaranteed to be cyan-ink-only on paper. Treat the page as a practical diagnostic, not a lab-grade calibration target.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Kill the page breaks you didn't ask for
&lt;/h2&gt;

&lt;p&gt;One-page test sheets have to stay on one page. A few properties did most of the work:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="nt"&gt;print&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;header&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;nav&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;footer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;.ads&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;.no-print&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;none&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;important&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nc"&gt;.sheet&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;break-inside&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;avoid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;page-break-inside&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;avoid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="n"&gt;html&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;overflow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;visible&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That &lt;code&gt;overflow: visible&lt;/code&gt; line fixed a weird bug where a scrolling container on screen caused only the visible part to print in some browsers.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Ship a PDF too
&lt;/h2&gt;

&lt;p&gt;Even after all of this, browser printing is a moving target: different defaults, different dialogs, extensions that inject stuff. So every sheet also has a PDF version built from the same layout. A PDF fixes the page size, keeps the fills, and sidesteps the background-graphics setting completely. It's also what most people actually want: download, print, done.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd tell myself at the start
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Test on a real printer early. Print preview lies.&lt;/li&gt;
&lt;li&gt;Draw anything critical in SVG, not CSS backgrounds.&lt;/li&gt;
&lt;li&gt;Pick fixed paper sizes and ship one version for each.&lt;/li&gt;
&lt;li&gt;Give users a way to check the scale.&lt;/li&gt;
&lt;li&gt;Offer a PDF and stop worrying about the browser print dialog.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you want to see the finished sheets, they're free at &lt;a href="https://printerprinttest.com/" rel="noopener noreferrer"&gt;printerprinttest.com&lt;/a&gt;. I'd genuinely like to hear how other people have handled print CSS, especially the Firefox &lt;code&gt;@page&lt;/code&gt; quirks.&lt;/p&gt;

</description>
      <category>css</category>
      <category>webdev</category>
      <category>html</category>
      <category>frontend</category>
    </item>
  </channel>
</rss>
