Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk5 min

HTML to PDF Conversion: CSS Page-Break Rules Explained

Use CSS fragmentation rules to control HTML-to-PDF page breaks, keep components together where possible, and set page dimensions separately with @page.

Free tools Windows power users keep installed

One-click scans. No signup required.

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

To control pagination in an HTML-to-PDF conversion, use CSS fragmentation rules: break-before or break-after to request a page boundary, and break-inside to discourage a break within a component. Use @page separately to set paper size and margins. These rules guide a PDF renderer; they cannot keep oversized content on one page or guarantee identical output across renderers.

How HTML pagination works

When a browser or other renderer turns HTML into pages, it lays content into page boxes. The content flows through the page area and may be fragmented at page boundaries. CSS Paged Media describes the page box and page setup; CSS Fragmentation describes how content may break across pages and other fragmentation contexts. See the W3C CSS Paged Media Module Level 3 and the W3C CSS Fragmentation Module Level 3.

This distinction matters: @page sets up the sheet, while break-* rules influence where content is divided. The same styles can paginate differently in different PDF engines or versions, so verify the generated file with the renderer and assets used in production.

Set the page size and margins

Use @page for paper dimensions, orientation, and margins. For example, this sets A4 portrait pages with 18 mm margins:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
@page {
  size: A4;
  margin: 18mm;
}

The document content flows in the page area inside those margins. Some implementations also support content in page-margin areas; do not assume that every renderer supports every paged-media feature.

Force a page break before or after a section

Use break-before: page when a block should start on a new page, or break-after: page when the next block should start on one. Apply the rule to the element at the boundary you want to control:

@media print {
  .chapter {
    break-before: page;
  }

  .appendix {
    break-after: page;
  }
}

For older renderers that rely on the legacy properties, add their compatibility aliases:

@media print {
  .chapter {
    break-before: page;
    page-break-before: always;
  }

  .appendix {
    break-after: page;
    page-break-after: always;
  }
}

The legacy value always maps to the modern page value. These declarations express the same intent; confirm their behavior in the actual renderer you support. The specifications also define forced values such as left and right, with recto and verso in applicable contexts. Use those only when the output needs page-side control and the target renderer supports it.

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

Keep a component together where possible

Use break-inside: avoid-page when the constraint is specifically about page breaks, or break-inside: avoid for a general fragmentation constraint. The legacy page-break-inside: avoid is an alias for break-inside: avoid.

@media print {
  .card,
  figure {
    break-inside: avoid-page;
    page-break-inside: avoid;
  }
}

An avoidance rule influences the renderer’s choice among possible break points; it is not an absolute fit guarantee. If a box is taller than the available page area, it cannot stay intact on that page. Depending on the implementation and surrounding layout, the result may be a split, overflow, or awkward pagination. Avoid applying the rule indiscriminately to large containers.

Prevent stranded lines with widows and orphans

The widows and orphans properties set minimum line-box counts on either side of a page break. They can help avoid leaving a single line at the bottom or top of a page:

@media print {
  p {
    orphans: 3;
    widows: 3;
  }
}

These constraints participate in break selection along with rules on neighboring boxes and ancestors. They do not determine the entire pagination by themselves.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

A practical print stylesheet

This combines page setup, a new page before each chapter, keep-together hints for figures and cards, and line-count constraints for paragraphs:

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

@media print {
  .chapter {
    break-before: page;
    page-break-before: always;
  }

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

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

Treat this as a starting point, not a cross-renderer guarantee. Inspect the PDF at its final page size with production fonts, images, and other assets; changing any of these can change line wrapping and pagination.

Why avoid does not always prevent a split

A potential break is not controlled by one declaration in isolation. The properties on boxes meeting at the boundary and constraints on their enclosing context can all affect whether a break is allowed. Forced break values take precedence over avoidance in the CSS 2.2 rules. If the usual permitted break points are not enough to prevent overflow, the specifications describe relaxing constraints and allowing additional break points.

CSS defines constraints and permitted choices, but does not prescribe one uniquely correct break in every layout. This is why a rule that works in one document or renderer may not produce the same page boundary in another. See W3C CSS 2.2, Paged Media for the legacy rules and fallback behavior.

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

Choose and verify the right rules

  • To start a section on a new page, use break-before: page; for a boundary after it, use break-after: page.
  • To discourage splitting a manageable component across pages, use break-inside: avoid-page or the broader avoid value.
  • To reduce isolated paragraph lines, set appropriate widows and orphans values.
  • To set sheet dimensions and margins, use @page, not a break declaration.
  • For compatibility, consider legacy page-break-* aliases, then check the result in the exact PDF engine and version deployed.

MDN’s CSS fragmentation guide provides an accessible overview of how fragmentation applies to pagination.

Troubleshooting common pagination problems

A section does not start on a new page

  • Check that the rule applies to the element that actually generates the block at the intended boundary.
  • Confirm the stylesheet is active for print or PDF output; rules inside @media print will not affect a renderer that does not use print media.
  • Test the modern declaration and, if older engines are in scope, its legacy alias in the target renderer.

A card or figure still splits

  • Check whether its height exceeds the available page area; no avoidance rule can make oversized content fit intact.
  • Check ancestor and neighboring break constraints, which also participate in selecting a break.
  • Inspect the actual rendered PDF rather than assuming support or identical behavior across engines.

Pagination changes after a content or design update

Text wrapping depends on dimensions, fonts, and assets. Recheck page boundaries after changing production content, font loading, image sizes, or page margins. A small layout change can move later content to another page.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If your goal is a screenshot or PDF capture of a web page rather than controlling a custom HTML document’s print stylesheet, ScreenshotNeo offers a one-request website screenshot API and an MCP server for AI agents. The CSS rules above remain the right approach when you need to author pagination in your own HTML.

cURL example (replace the URL with the page to capture):

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options. Before capture, it accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan to try 1,000 screenshots a month with no card.

Frequently Asked Questions

What is the difference between break-before: page and page-break-before: always?

The modern declaration uses the fragmentation vocabulary; the legacy property is a compatibility alias, with always mapping to page. Support should be checked in the PDF renderer you use.

Should I use avoid or avoid-page?

Use avoid-page when the intended constraint is specifically page fragmentation; use avoid for a broader fragmentation constraint.

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.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.