Matt Wilson Matt Wilson - 1 month ago 10
HTML Question

Specifying phyiscal size in CSS (e.g. 2 inches) when printing a web page

Is there a reliable way to specify physical dimensions in CSS such that when the page is printed, my elements are at a specific size and position on the printed page?

I see that CSS has units for in and cm, but (not surprisingly) neither Firefox nor Chrome actually printed the box at 2x2 inches when I did the following:

.test {
width: 2in;
height: 2in;
border: solid 1px #aaa;
}


Am I being too optimistic hoping that there is some way of specifying the size and having the browser adjust it's printing size based on the resolution of the printer etc?

Thanks.

Answer

Try adding margin: 0; padding: 0 to avoid any extra spacing.