Javascript – Print html to multiple page

htmljavascriptprinting

Assuming we have multiple html paragraph

<p>Paragraph 1</p>
<p>Paragraph 2</p>

Is there a way to print both to different page to the printer ?

Paragraph 1 would be printed on the first page and Paragraph 2 would be printed on the second page.

Thank You

Best Answer

You can do this using CSS page-break-after property:

@media print {
    p { page-break-after: always; }
}

It will print each p element on new page.

window.print()
@media print {
    @page { margin: 0; }
    p { page-break-after: always; }
}
<p>Paragraph 1</p>
<p>Paragraph 2</p>

Related Topic