Menu

CSS page breaks for HTML-to-PDF: tables, headers, margins and backgrounds
📰

CSS page breaks for HTML-to-PDF: tables, headers, margins and backgrounds

DEV Community: css·SlipKiln·15 days ago
#AmR0GGpP
#devtocss#devto#dev#break#slipkiln
Long article (560 words) — no AI summary yet.
Reading 0:00
15s threshold

These rules work in Chromium-based renderers: Chrome's Print to PDF, Puppeteer, Playwright and APIs built on them, including SlipKiln. Older engines like wkhtmltopdf support less of this.

Tables split across pages

Long tables get rows cut in half at the page edge, and the header row appears only on page one. Two rules fix both:

/* Keep each row whole and repeat the header row on every page */ tr { break-inside : avoid ; } thead { display : table-header-group ; } tfoot { display : table-footer-group ; }

Enter fullscreen mode

Exit fullscreen mode

Chromium repeats a <thead> on every printed page, so make sure your header row is actually in a <thead> , not the first <tr> of the body.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.