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

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

To keep a card, notice, or other block together in a react-to-pdf export, put both break-inside: avoid and page-break-inside: avoid on the block’s outer wrapper, and make sure the block is shorter than the usable PDF page. Those CSS rules can help, but react-to-pdf captures the DOM with html2canvas and writes the image to a PDF with jsPDF; it is not browser print pagination. If avoidance still fails, group content into page-sized sections and control the boundaries yourself.

Why react-to-pdf splits elements across pages

react-to-pdf uses html2canvas to capture the target DOM and jsPDF to create the PDF. The capture is a canvas image, which is then divided among PDF pages. That differs from a browser’s print engine laying out text and blocks directly across pages.

html2canvas documents that CSS properties must be implemented manually, so a CSS rule that works in browser printing is not guaranteed to affect how a captured canvas is divided. In particular, page-break-inside: avoid may appear to do nothing when a tall canvas is sliced into pages. See the html2canvas FAQ and react-to-pdf package documentation.

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

The practical distinction is important: avoidance rules may help the capture or pagination setup respect a block boundary, but they cannot make an oversized block fit on a page. If one logical unit is taller than the available page area, it must be shrunk, split, redesigned, or given a page of its own.

Keep a card or other logical block together

Apply both the modern and legacy avoidance properties to the outer block that represents one indivisible unit. Applying the rule only to a paragraph inside a card does not tell the pagination logic to keep the whole card intact.

.pdf-unit {
  break-inside: avoid;
  page-break-inside: avoid;
}

Use that class on each repeated unit inside the element you pass to react-to-pdf:

import { useRef } from 'react';
import { usePDF } from 'react-to-pdf';

export function Report({ items }) {
  const targetRef = useRef(null);
  const { toPDF } = usePDF({ filename: 'report.pdf' });

  return (
    <>
      <button type="button" onClick={() => toPDF()}>
        Download PDF
      </button>
      <div ref={targetRef} className="pdf-root">
        {items.map(item => (
          <section className="pdf-unit" key={item.id}>
            <h2>{item.title}</h2>
            <p>{item.body}</p>
          </section>
        ))}
      </div>
    </>
  );
}

Use the hook, target ref, and invocation style documented by the version of react-to-pdf installed in your project; package APIs can differ by version. The key layout idea is independent of the button: the ref should identify the intended PDF root, and .pdf-unit should wrap every block you want to keep intact.

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

Make sure the unit can fit

Estimate the usable page height after margins and any reserved header or footer space, then keep each unbreakable unit below that height. A long table row, oversized image, or card with unconstrained content can exceed the page even when both CSS properties are present. Consider reducing content, adjusting dimensions, or intentionally making the item its own page.

Remove layout constraints that obstruct flow

Fixed heights and overflow rules can clip content or produce unexpected dimensions in the captured DOM. Remove or adapt them on blocks that need to flow into the PDF. Keep the PDF’s styles separate from interactive screen styles where possible, so a screen-only scroll container does not become the capture root.

Use explicit page sections when a split is unacceptable

When automatic avoidance remains unreliable, divide the content into groups that fit within the intended page area and render those groups as page-sized sections. A deliberate page boundary gives you more control than asking a canvas slicing step to infer where a complex card or group belongs.

<div ref={targetRef} className="pdf-root">
  <section className="pdf-page">
    {firstPageItems.map(renderItem)}
  </section>
  <div className="html2pdf__page-break" aria-hidden="true" />
  <section className="pdf-page">
    {secondPageItems.map(renderItem)}
  </section>
</div>

The html2pdf__page-break class is documented by html2pdf.js, which also describes selector-based break positions. Do not assume that this class automatically works in react-to-pdf: its documented configuration focuses on page, canvas, and jsPDF options, and it uses a different pipeline. If you use a marker, verify that your installed version actually passes through behavior that recognizes it. The safer general approach is to make page-sized groups explicit in the content you capture.

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

Choose the boundary deliberately

Split groups between logical units, not through a card or table row. If the data is dynamic, assign items to pages before rendering, based on your layout constraints, rather than inserting a boundary at an arbitrary item index. A page section that exceeds the usable height can still spill or be clipped, so validate the rendered dimensions as content changes.

Tune the capture only when you have a specific reason

react-to-pdf documents an overrides object for values passed to its underlying jsPDF and html2canvas libraries. Use overrides for targeted needs such as capture behavior or image settings, not as a substitute for sensible page grouping. Its package documentation warns that overrides can break output; change one setting at a time and inspect the resulting PDF.

For example, html2canvas’s onclone callback can add a class to the cloned DOM used for capture without changing the live interface:

const options = {
  overrides: {
    canvas: {
      onclone: clonedDocument => {
        clonedDocument.querySelectorAll('.pdf-unit')
          .forEach(node => node.classList.add('capture-unit'));
      }
    }
  }
};

You could define capture-specific styling for .capture-unit in your stylesheet. Check the typings and documentation for the exact installed react-to-pdf and html2canvas versions before relying on an option: the names and supported settings must match the versions actually used by your project. See the html2canvas configuration documentation.

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

Troubleshoot a block that still splits

  • The CSS rule seems ignored: Confirm that both avoidance properties are on the outer logical block, not just an inner text node. Remember that this is canvas capture rather than full browser print pagination.
  • The block is taller than a page: Avoidance cannot fit an oversized unit into the available area. Shorten it, reduce its dimensions, split it intentionally, or render it on a page of its own.
  • Content is clipped or unexpectedly tall: Inspect fixed heights and overflow on the root and its children. Remove screen-oriented scroll constraints where the PDF needs natural document flow.
  • The first or last item is cut off: Make sure the ref points to the intended content root rather than a scrolling parent with unexpected height. Check that the root’s dimensions include the complete content you expect to export.
  • Pages change between runs: Wait until fonts and images have loaded before capturing. If assets arrive after layout measurement, element heights can change and move content across a boundary.
  • The export hangs or the browser crashes: High capture resolution increases image size. Try a lower resolution while debugging, especially for multi-page exports; the package documentation notes that high resolutions can cause browser crashes or hangs.
  • A page-break marker has no effect: The html2pdf__page-break behavior belongs to html2pdf.js documentation. Confirm that your react-to-pdf pipeline supports the same behavior instead of assuming the class is universal.
  • Overrides make output worse: Revert the last change and confirm the option against the installed package typings. Test one override at a time, since the package cautions that overrides can break output.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When a canvas-based PDF is the wrong fit

A screenshot-to-PDF workflow is convenient when visual appearance matters more than document semantics. It is a poor fit when the PDF must have selectable or searchable text, complex tables, repeating headers, or strict CSS pagination. Because html2canvas does not support every CSS property, requirements like these are a reason to evaluate a CSS-aware browser or server-side HTML-to-PDF renderer rather than adding more capture tweaks.

HTML2PDF.app is one example whose documentation exposes break-inside: avoid, page-break-inside: avoid, and explicit page sections. That documents a relevant capability, not a conclusion about service reliability, pricing, or suitability for your application; verify those independently before choosing a service.

Or skip the browser setup

If you only need a clean screenshot or PDF of a website, ScreenshotNeo offers a one-request screenshot API and an MCP server for AI agents. Its capture flow accepts cookie and consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup 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. Claude, Cursor, and other MCP clients can use its take_screenshot, get_page_info, and capture_pdf tools. All listed features are on every plan.

For example, request a screenshot with cURL (replace the URL with the page you want to capture):

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.
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. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots. Sign up for ScreenshotNeo’s free plan.

Frequently asked questions

Does page-break-inside: avoid guarantee that an element will stay together?

No. It is a useful rule to try on the wrapper, but react-to-pdf relies on canvas capture and does not provide the same CSS pagination behavior as a browser print engine.

Can one element be taller than the PDF page and remain unbroken?

Not without changing the layout or output constraints. It must be shortened, scaled, split, or given more page space.

Will the html2pdf.js page-break class work in react-to-pdf?

Not necessarily. It is documented for html2pdf.js; verify support in the specific react-to-pdf pipeline and version you use.

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.