Guides

CSS page breaks in HTML to PDF (tested in Chrome)

When you turn HTML into a PDF with headless Chrome (Puppeteer, Playwright or PDFLoom), page breaks come from CSS fragmentation rules. Most of what you read online was written for older browsers. We rendered every example below with Chrome 155 to A4 and checked which page each piece of text landed on. Here's what actually works today.

Force a new page

.page-break { break-before: page; }   /* modern */
.page-break { page-break-before: always; }   /* legacy alias, still works */

Put it on the element that should start the new page, for example each invoice in a batch or each chapter. break-after: page works too. In our tests a break-after: page on the last element did not add a blank trailing page in current Chrome.

It works on normal blocks, and also inside flex and grid containers, floats and absolutely positioned boxes. It does not work on inline or inline-block elements: a <span style="display:inline-block; break-before:page"> stayed on page 1. Make the element display: block.

Keep a box on one page

.card, .signature, .totals { break-inside: avoid; }

Without it, a bordered box that starts near the bottom of a page is cut in half. With it, Chrome moves the whole box to the next page. This also worked for flex items, both in column and row layouts.

One catch: if the box is taller than a page, Chrome still moves it to a new page first, then splits it anyway. You get a mostly empty page followed by a split box. Only use break-inside: avoid on things that fit on one page: cards, totals blocks, signature areas, images with captions. Don't use it on whole sections.

Don't split table rows

tr { break-inside: avoid; }

Chrome splits tall table rows across pages by default. A row with a dozen lines of text was cut between pages 1 and 2. With the rule above, it moved to page 2 intact. Short single-line rows weren't split in our tests either way, but the rule costs nothing, so add it to every invoice or report template.

Repeat the table header (and footer) on every page

Use real <thead> and <tfoot> elements. Chrome repeats both on every page a long table spans, with no extra CSS. In a 120-row table across 3 pages, both the header and footer cells appeared on all 3 pages.

<table>
  <thead><tr><th>Item</th><th>Qty</th><th>Amount</th></tr></thead>
  <tfoot><tr><td colspan="3">Continued on next page</td></tr></tfoot>
  <tbody>...</tbody>
</table>

A repeated <tfoot> also shows on the last page, so put your grand total in a separate block after the table, not in the tfoot.

If the header doesn't repeat, check that it really is a <thead> (not a styled first row) and that the table isn't set to display: flex or grid. With display: flex the header printed only on page 1. display: block on the table still repeated it in our test.

Keep headings with the following text

h1, h2, h3 { break-after: avoid; }

Without this, a heading can be the last line on a page, with its paragraph on the next. In our test the heading stayed on page 1 alone. With break-after: avoid, Chrome moved it to page 2 with its paragraph.

Page size and margins

Define the paper in CSS so the template controls its own layout:

@page { size: A4; margin: 16mm; }

With Puppeteer, pass preferCSSPageSize: true to page.pdf(), or the format option wins. With the PDFLoom API, send the same flag:

curl https://pdfloom.dev/v1/pdf \
  -H "Authorization: Bearer $PDFLOOM_KEY" \
  -H "Content-Type: application/json" \
  -d '{"html": "<style>@page{size:A4;margin:16mm} tr{break-inside:avoid}</style>...", "preferCSSPageSize": true}' \
  -o out.pdf

A print stylesheet to start from

@page { size: A4; margin: 16mm; }
h1, h2, h3 { break-after: avoid; }
tr, img, figure, .card, .totals, .signature { break-inside: avoid; }
.page-break { break-before: page; }
thead { display: table-header-group; }   /* the default; only needed if something reset it */

For a running header, footer or "Page X of Y", see page numbers, headers and footers. For a template that already uses these rules, see the free HTML invoice template.

Tested 20 November 2026 with Chrome 155 (Puppeteer), A4, 15 mm top and bottom margins. We found which page each element landed on by extracting each page's text with pdftotext.


More guides