Web Page Print Styles
When you print a HTML page from the browser, either to a paper printer or to PDF there can be formatting issues. Here I present a few CSS styles that can be used to better present details on the page.
# TL;DR
ISO A4 sized pages, with manual page breaks and avoidance of split elements.
|
|
# Setting the Paper Size
To set the page size and margin, use the @page
selector.
|
|
The size
rule accepts mm
(millimetres), cm
(centimetres), or in
(inches). For standard paper sizes refer to ISO Paper Sizes.
# Forcing Page Breaks
To force a page break, choose an HTML element that seems natural for a page break, generally I use <hr>
elements for this purpose.
|
|
Optionally you can hide the element as I have, if it will disrupt the presentation of the document.
# Avoid Splitting Elements
To avoid splitting elements like <p>
<code>
and <pre>
blocks, use the page-break-inside
rule. You can apply this to all elements on a page and a best attempt will be made to avoid splitting elements over two pages.
|
|