Search code examples
cssprintingpaginationjquery-pagination

Paginate code for print


Okay I'm wondering whether there is a way to tell the printer when to create a page-break when printing a HTML page? There must be something, cross-browser compatible, that allows me to do this.

An example would be to create a page break before every element with a class of 'mainHeading'.

Can anybody shed some light on this?

Thanks


Solution

  • You can specify where to put page breaks by using CSS page-break-before and page-break-after.

    The values you'll use for this are auto, which is default and always. Auto means that the page will break before or after the element (depending on which method you used) if necessary. Always will always force a page break before or after the element.

    A note, there are other values available, however I believe these are the only ones which work cross-browser.