Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use print CSS to keep related content together and guide where pages break: apply break-inside: avoid to figures, cards and callouts; keep headings with what follows using break-after: avoid; and reserve forced page breaks for real section boundaries. Include the older page-break-* aliases for compatibility, then verify the result in the HTML-to-PDF renderer that will produce your files.

How page-break rules work

HTML-to-PDF pagination divides content into page boxes. A page break ends layout in one page box and continues it in another; the W3C describes this as ending layout in the current page box and laying out remaining document content in a new one. See the CSS 2.2 paged media specification.

Use the modern fragmentation properties break-before, break-after and break-inside. Their older counterparts—page-break-before, page-break-after and page-break-inside—remain useful aliases for older engines. In either form, always requests a forced break and avoid requests that the formatter not break at the specified point or within the selected box. Avoid is a request, not a guarantee: the renderer may need to split an oversized block to make progress.

Start with a print stylesheet

Give content that belongs together a semantic container, then use print rules to control its pagination. Set the page size and margins explicitly so the formatter has a defined page box.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
PDF Extra 2024| Complete PDF Reader and Editor | Create, Edit, Convert, Combine, Comment, Fill & Sign PDFs | Lifetime License | 1 Windows PC | 1 User [PC Online code]
  • EDIT text, images & designs in PDF documents. ORGANIZE PDFs. Convert PDFs to Word, Excel & ePub.
  • READ and Comment PDFs – Intuitive reading modes & document commenting and mark up.
  • CREATE, COMBINE, SCAN and COMPRESS PDFs
  • FILL forms & Digitally Sign PDFs. PROTECT and Encrypt PDFs
  • LIFETIME License for 1 Windows PC or Laptop. 5GB MobiDrive Cloud Storage Included.
@page {
  size: A4;
  margin: 18mm 16mm 20mm;
}

@media print {
  h1, h2, h3 {
    break-after: avoid;
    page-break-after: avoid;
  }

  section.chapter {
    break-before: page;
    page-break-before: always;
  }

  figure, .card, .callout, .table-group {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  p, li {
    orphans: 3;
    widows: 3;
  }
}

The values in this example are a starting point, not universal requirements. Choose the page size and margins that match the intended document. The modern and legacy declarations express the same intent; test the actual renderer and output rather than assuming every engine treats all layouts identically.

Keep headings and related content together

Headings with the next paragraph

A heading stranded at the bottom of a page leaves its section label separated from its content. Applying break-after: avoid to headings asks the formatter to keep the next content with them. Use it for the heading levels that appear in your generated document; the example applies it to h1, h2 and h3.

Figures, cards and callouts

Wrap a figure and its caption in one <figure> element, and use a block container for a card or callout. Apply break-inside: avoid to that container. This communicates that the unit should travel together instead of being divided between pages.

Tables and grouped rows

For a meaningful table fragment or a group of related rows, a wrapper such as .table-group lets you express the intended unit. Avoid treating an entire long table as atomic: if it cannot fit on one page, the renderer may have to split it or override the avoidance request. Test multi-page tables with representative data, and use the renderer’s documented table behavior rather than assuming a wrapper can make a long table indivisible.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
MobiPDF Lifetime - Professional PDF Editor for Windows | Edit, Sign & Convert PDFs | Best Adobe Acrobat Pro Alternative | Lifetime License
  • Edit PDFs with Ease. Modify text, images, and layouts directly within your PDF documents.
  • Convert & Organize. Export PDFs to Word, Excel, or ePub, and organize files with ease.
  • Read & Annotate. Enjoy intuitive reading modes and powerful tools to comment, highlight, and mark up PDFs.
  • Create & Manage PDFs. Create new PDFs, combine multiple files, scan documents, and compress for easy sharing.
  • Fill & Sign Forms. Complete forms and digitally sign documents with secure e-signature tools.

Long text and page edges

widows and orphans specify the minimum number of lines of a paragraph to leave at the top or bottom of a page. They help reduce awkward single-line fragments, but they do not make an entire long paragraph unbreakable. Tune the values for the document’s type size and available page area.

Use forced breaks sparingly

Use break-before: page when a new page is part of the document’s design, such as at the start of a major chapter. Its older alias is page-break-before: always. Do not apply a forced break to every section by default: doing so can leave large blank areas when the preceding section ends early.

Break decisions are affected by the previous element’s break-after, the next element’s break-before, and the containing box’s break-inside. The interaction matters when a rule appears to be ignored or when several rules meet at the same page boundary. See MDN’s explanation of break decisions.

Test the difficult cases

A stylesheet that looks right with a short example may fail on real documents. Check the cases most likely to challenge the page layout:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Adobe Acrobat Pro | PDF Software | Convert, Edit, E-Sign, Protect | PC/Mac Online Code | Activation Required
  • Create and edit PDFs. Collaborate with ease. E-sign documents and collect signatures. Get everything done in one app, wherever you go.
  • Edit text and images without jumping to another app.
  • E-sign documents or request e-signatures on any device. Recipients don’t need to log in to e-sign.
  • Convert PDFs to editable Microsoft Word, Excel, or PowerPoint documents.
  • Share PDFs for collaboration. Commenting features make it easy for reviewers to comment, mark up, and annotate.
  • Long paragraphs and lists that cross a page boundary.
  • Figures with captions, including images close to the available page height.
  • Nested cards and callouts.
  • Tables that span several pages.
  • Blocks taller than one page, which cannot remain intact.
  • Documents with forced chapter breaks and sections of very different lengths.

When a block is taller than the printable page area, avoidance cannot make it fit. The formatter must split it, move it, or otherwise adjust layout to continue. The W3C CSS Print Profile notes that when a printer cannot buffer a whole long element, page-break-inside: avoid can result in a break before the element; it also recommends specifying page size through the CSS size property. See the CSS Print Profile.

Check your PDF renderer

Puppeteer and Chromium

Puppeteer’s page.pdf() generates a PDF using the print CSS media type. Put pagination rules in @media print so they apply during PDF generation. If the page is deliberately designed for screen media and you specifically want that styling in the output, Puppeteer documents page.emulateMediaType('screen') as the way to select screen media instead. Its PDF documentation also notes that colors are modified for printing by default; use -webkit-print-color-adjust when exact colors are required. See Puppeteer’s PDF API and its PDF generation guide.

WeasyPrint

WeasyPrint’s API reference lists break-before, break-after and break-inside for pages, along with the page-break-* aliases and orphans/widows. It distinguishes page support from column and region fragmentation, so a design that depends on multi-column breaking needs separate verification. See the WeasyPrint API reference.

Choose based on the layout you need

Puppeteer uses browser-based Chromium print behavior; WeasyPrint is a dedicated HTML/CSS-to-PDF engine with documented pagination support. For a project, compare the renderer’s print-media handling, modern and legacy break-property support, behavior for tables and flex, grid or column layouts, header and footer capabilities, font and image fidelity, JavaScript requirements, and operational cost. Do not assume that a CSS rule behaving in one engine will produce identical pagination in another.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
PDF Extra Lifetime - Professional PDF Editor - Best Adobe Acrobat Pro Alternative - Lifetime License for Windows PC
  • Perfect Adobe Acrobat Pro alternative – lifetime license for Windows 10 and 11.
  • EDIT text, images, pages, hyperlinks, designs in PDF documents. ORGANIZE PDFs.
  • READ and Comment on PDFs – Intuitive reading modes & document commenting and mark up tools!
  • CREATE, COMBINE, SCAN and COMPRESS PDFs.
  • FILL forms & Digitally Sign PDFs. Work with Digital certificates
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common pagination problems

A heading still appears alone at the bottom of the page

Confirm that the PDF renderer is using print media and that the heading’s print rule includes break-after: avoid (and the legacy alias if required). Inspect the heading’s following content and containing layout: break decisions involve the preceding and following elements as well as the containing box. If the next block is too large to fit, the renderer may move more content or override an avoidance request.

A card or figure splits despite break-inside: avoid

Check that the rule is applied to the outer container that encloses all related content, not only to a child. Then check whether the box is taller than the available page area. Avoidance cannot preserve a unit that physically cannot fit in the remaining or a full page area; shorten it, allow it to split, or redesign its layout.

Print styles seem to have no effect

Verify which media type the PDF generation path selects. Puppeteer’s page.pdf() uses print media; an explicit call to emulate screen media changes that choice. Also confirm that the stylesheet loads and that the relevant selectors match the generated HTML.

Colors differ from the browser view

In Puppeteer, PDF printing modifies colors by default. If exact colors are required, use -webkit-print-color-adjust and verify the resulting PDF in the target workflow.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
PDF Pro 3 - PDF editor to create, edit, convert and merge PDFs - 100% Compatible with Adobe Acrobat - for Windows 11, 10, 8.1, 7
  • ALL-IN-ONE SOLUTION – read, edit, convert, merge and protect your PDF files
  • MAXIMUM FUNCIONALITY – create interactive forms, compare PDFs, bates numbering, find and replace text or colors, convert documents, OCR engine, comment, highlight, fill out and print forms, document protection and others
  • EASY TO INSTALL AND USE – well-structured user-interface, in-program instructions, free tech support whenever you need it
  • GREAT VALUE FOR MONEY - why spend a fortune if you can have maximum functionality at a reasonable price - this also fits the requirements of companies very well

Columns or complex layouts break unexpectedly

Pagination support for pages does not establish identical behavior for columns or other fragmentation contexts. Verify the exact layout in the chosen engine; WeasyPrint’s reference distinguishes page support from column and region fragmentation.

Or skip the browser setup

If your job is to create a screenshot or PDF of a live web page, ScreenshotNeo offers a one-call API rather than requiring you to configure a browser capture process. For PDF output and its options, see the ScreenshotNeo documentation. This is a hosted capture service, not a replacement for authoring and testing print CSS in your own HTML-to-PDF renderer.

cURL:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.pdf

Python:

import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
    timeout=90,
)
open("shot.pdf", "wb").write(r.content)

Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

These examples use the stated API call with the output filename or requested format adapted for PDF. ScreenshotNeo accepts cookie or consent banners as a visitor and removes more than 60 known consent platforms, newsletter popups and chat widgets before capture; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads and cache hits cost nothing, and response headers report the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info and capture_pdf for AI agents. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Sign up for 1,000 free screenshots a month with no card.

Frequently Asked Questions

Does break-inside: avoid guarantee that a block will stay on one PDF page?

No. It asks the formatter to avoid splitting the box. A box taller than the available page area may still need to split or be moved.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why include both break-* and page-break-* declarations?

The break-* properties are the modern fragmentation properties; the older page-break-* names are aliases useful for older engines.

Quick Recap

Bestseller No. 1
PDF Extra 2024| Complete PDF Reader and Editor | Create, Edit, Convert, Combine, Comment, Fill & Sign PDFs | Lifetime License | 1 Windows PC | 1 User [PC Online code]
PDF Extra 2024| Complete PDF Reader and Editor | Create, Edit, Convert, Combine, Comment, Fill & Sign PDFs | Lifetime License | 1 Windows PC | 1 User [PC Online code]
READ and Comment PDFs – Intuitive reading modes & document commenting and mark up.; CREATE, COMBINE, SCAN and COMPRESS PDFs
$99.99
Bestseller No. 2
MobiPDF Lifetime - Professional PDF Editor for Windows | Edit, Sign & Convert PDFs | Best Adobe Acrobat Pro Alternative | Lifetime License
MobiPDF Lifetime - Professional PDF Editor for Windows | Edit, Sign & Convert PDFs | Best Adobe Acrobat Pro Alternative | Lifetime License
Edit PDFs with Ease. Modify text, images, and layouts directly within your PDF documents.; Convert & Organize. Export PDFs to Word, Excel, or ePub, and organize files with ease.
$99.99
Bestseller No. 3
Adobe Acrobat Pro | PDF Software | Convert, Edit, E-Sign, Protect | PC/Mac Online Code | Activation Required
Adobe Acrobat Pro | PDF Software | Convert, Edit, E-Sign, Protect | PC/Mac Online Code | Activation Required
Edit text and images without jumping to another app.; Convert PDFs to editable Microsoft Word, Excel, or PowerPoint documents.
$239.88
Bestseller No. 4
PDF Extra Lifetime - Professional PDF Editor - Best Adobe Acrobat Pro Alternative - Lifetime License for Windows PC
PDF Extra Lifetime - Professional PDF Editor - Best Adobe Acrobat Pro Alternative - Lifetime License for Windows PC
Perfect Adobe Acrobat Pro alternative – lifetime license for Windows 10 and 11.; EDIT text, images, pages, hyperlinks, designs in PDF documents. ORGANIZE PDFs.
$99.99
Bestseller No. 5
PDF Pro 3 - PDF editor to create, edit, convert and merge PDFs - 100% Compatible with Adobe Acrobat - for Windows 11, 10, 8.1, 7
PDF Pro 3 - PDF editor to create, edit, convert and merge PDFs - 100% Compatible with Adobe Acrobat - for Windows 11, 10, 8.1, 7
ALL-IN-ONE SOLUTION – read, edit, convert, merge and protect your PDF files
$29.99

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.