I spent a week chasing a bug that turned out not to be a bug in my code.
A packing slip generated in the browser looked correct in the print preview on my machine. A seller printed the same slip on a 4×6 thermal printer and got text that was readable but slightly small, with the bottom row of items clipped. Same HTML, same CSS, different result.
The cause was not the CSS. It was the chain of four places where "4×6" gets decided, and only one of them is under my control.
The four places a page size is set
- CSS —
@page { size: 4in 6in; margin: 0; } - The browser print dialog — paper size dropdown and scale (
Fit to pagevs100%) - The printer driver — the paper size the driver believes is loaded
- The physical roll — 4×6 in, with a non-printable dead zone at the edges
If any of the four disagrees, the browser silently scales the content to fit whatever it thinks the paper is. Nothing errors. The slip just comes out at 92% and the last line gets pushed onto a second page.
What CSS can actually do
@page size is supported in Chromium and Firefox for the print media type. In Chromium it sets the initial paper size in the print preview. It does not force the physical printer to that size — if the driver has 4×6 loaded but the dialog says Letter, you get Letter layout scaled onto a 4×6 roll.
@page { size: 4in 6in; margin: 0; } html, body { margin: 0; padding: 0; } .slip { width: 4in; min-height: 5.9in; /* 0.1in safety, not 6in */ padding: 0.12in; /* inner padding instead of page margin */ box-sizing: border-box; break-inside: avoid; page-break-after: always; } .slip:last-child { page-break-after: auto; /* otherwise you get one blank page at the end */ } Two details in there are load-bearing:
-
min-height: 5.9ininstead of6in. Rounding in the layout engine plus any 1px border is enough to make a 6.0in box exceed the page by a fraction, and that fraction becomes a blank second page. The 0.1in is a rounding budget, not a design choice. -
page-break-after: alwayson every slip except the last. This is the single most common cause of "my batch print produced 12 pages for 6 orders."
Safari is the exception, and you have to design around it
Safari's print path uses the system print dialog's paper size and does not honour @page size the same way Chromium does. On macOS the practical result is that the user must pick the 4×6 paper in the dialog; CSS alone will not do it. I have not tested Safari on iOS against a thermal printer, so I am not going to claim a behaviour there.
If you are building a tool for other people, this means: do not hide the paper-size choice. Put a line of text above the print button that says which paper the layout is built for and what to select in the dialog. It is unglamorous and it removes most support questions.
Thermal printers make two CSS habits worse
Thermal printers are 1-bit devices. There is no gray.
- Light gray text becomes dithered noise.
color: #999on a 203 dpi head comes out as a spray of dots. Use pure black, and use size or weight for hierarchy instead of value. - Background fills bleed. A
background: #f5f5f5table header is either invisible or, at higher density settings, a solid block that bleeds into the row below. Use a 1px black border instead of a fill.
Also: do not scale barcode images with CSS transforms. A barcode rendered at 300px and displayed at 240px gets resampled, and the quiet zone stops being quiet. Render at the final pixel size.
The scale setting is where most batches die
In the Chromium print dialog, the default scale is Default, which is not 100%. On a 4×6 page with margin: 0, the visible symptom of a wrong scale is not a shifted layout — it is a slip that looks fine until you check a ruler against the 4in width.
The check I now do before printing a batch:
- Print one slip.
- Measure the printed width. It should be 4in ± 1/32in.
- If it is short, the dialog scale is not 100%.
- If it is right but the bottom is clipped, the driver's paper size is not 4×6.
That is the whole diagnostic. Three minutes, one sheet of paper, and it separates the four causes above.
What I changed in the tool
The generator I maintain (orderquill.com/shipping-label-printer) now does three things differently because of this:
- The layout has explicit A4 and 4×6 modes instead of one layout that "fits both." Switching the paper in the print dialog without switching the layout is how you get 8pt text on a 4×6 roll.
- Long item tables paginate by slip, not by row. A 15-item order stays on one slip or moves entirely to a second one; it never splits mid-row.
- The troubleshooting sheet linked from the page lists the settings per browser, and marks the printer combinations I have actually tested as tested, and the rest as untested.
The sample CSVs and the print-check spec I use for testing are in this repo — fictional orders, no customer data, MIT licensed. If you are building something similar, the four-place model above is the part worth copying.
The short version
@page size sets intent, not reality. Reality is the print dialog scale, the driver's paper setting, and the roll in the machine. Check the printed width with a ruler before you print a batch of forty, and put the paper-size instruction where the person clicking Print will see it.