Add or Avoid Page Breaks in HTML PDFs

IronPDF supports page breaks within PDF documents. One major difference between PDF documents and HTML is that HTML documents tend to scroll whereas PDFs are multi-paged and can be printed.

Ensure proper HTML page breaks in your PDF in one line!

new IronPdf.ChromePdfRenderer().RenderHtmlAsPdf("<div>Page1 content</div><div style='page-break-after: always;'></div><div>Page2 content</div>").SaveAs("page-breaks.pdf");
Install with NuGet
green arrow pointer

PM >  Install-Package IronPdf

Get started with IronPDF

Start using IronPDF in your project today with a free trial.

First Step:
green arrow pointer



Add a Page Break

To create a page-break in HTML you can use this in your HTML code:

<div style="page-break-after: always;"></div>
<div style="page-break-after: always;"></div>
HTML

Demonstration of Creating a Page Break

In this example, I have the following table and image in my HTML, and I want them to be on two separate pages by adding a page break after the table.

Table

<table style="border: 1px solid #000000">
  <tr>
    <th>Company</th>
    <th>Product</th>
  </tr>
  <tr>
    <td>Iron Software</td>
    <td>IronPDF</td>
  </tr>
  <tr>
    <td>Iron Software</td>
    <td>IronOCR</td>
  </tr>
</table>
<table style="border: 1px solid #000000">
  <tr>
    <th>Company</th>
    <th>Product</th>
  </tr>
  <tr>
    <td>Iron Software</td>
    <td>IronPDF</td>
  </tr>
  <tr>
    <td>Iron Software</td>
    <td>IronOCR</td>
  </tr>
</table>
HTML

Image

<img src="/static-assets/pdf/how-to/html-to-pdf-page-breaks/ironpdf-logo-text-dotnet.svg" style="border:5px solid #000000; padding:3px; margin:5px" />
<img src="/static-assets/pdf/how-to/html-to-pdf-page-breaks/ironpdf-logo-text-dotnet.svg" style="border:5px solid #000000; padding:3px; margin:5px" />
HTML
:path=/static-assets/pdf/content-code-examples/how-to/html-to-pdf-page-breaks-page-break.cs
using IronPdf;

const string html = @"
  <table style='border: 1px solid #000000'>
    <tr>
      <th>Company</th>
      <th>Product</th>
    </tr>
    <tr>
      <td>Iron Software</td>
      <td>IronPDF</td>
    </tr>
    <tr>
      <td>Iron Software</td>
      <td>IronOCR</td>
    </tr>
  </table>

  <div style='page-break-after: always;'> </div>

  <img src='https://ironpdf.com/img/products/ironpdf-logo-text-dotnet.svg'>";

var renderer = new ChromePdfRenderer();

var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("Page_Break.pdf");
Imports IronPdf

Private Const html As String = "
  <table style='border: 1px solid #000000'>
    <tr>
      <th>Company</th>
      <th>Product</th>
    </tr>
    <tr>
      <td>Iron Software</td>
      <td>IronPDF</td>
    </tr>
    <tr>
      <td>Iron Software</td>
      <td>IronOCR</td>
    </tr>
  </table>

  <div style='page-break-after: always;'> </div>

  <img src='https://ironpdf.com/img/products/ironpdf-logo-text-dotnet.svg'>"

Private renderer = New ChromePdfRenderer()

Private pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("Page_Break.pdf")
$vbLabelText   $csharpLabel

And the code above will generate the PDF below, which has 2 pages: the Table on the First page and the Image on the second:

Avoiding Page Breaks in Images

To avoid a page-break within an image or table, you may use the CSS page-break-inside attribute applied to a wrapping DIV element.

<div style="page-break-inside: avoid">
    <img src="no-break-me.png" />
</div>
<div style="page-break-inside: avoid">
    <img src="no-break-me.png" />
</div>
HTML

Avoiding Page Breaks in Tables

As shown above, page breaks within tables can be avoided by using the CSS page-break-inside: avoid. This is better applied to a wrapping DIV than to the table itself to ensure the style is applied to a block-level HTML node.

To duplicate table headers and footers across every page of a large HTML table spanning multiple PDF pages, you may use a <thead> group within the table:

<thead>
    <tr>
        <th>C Sharp</th><th>VB</th>
    </tr>
</thead>
<thead>
    <tr>
        <th>C Sharp</th><th>VB</th>
    </tr>
</thead>
HTML

Advanced CSS3 Settings

To give greater control, you may wish to use CSS3 in addition to your thead group:

<style type="text/css">
    table { page-break-inside:auto }
    tr { page-break-inside:avoid; page-break-after:auto }
    thead { display:table-header-group }
    tfoot { display:table-footer-group }
</style>
<style type="text/css">
    table { page-break-inside:auto }
    tr { page-break-inside:avoid; page-break-after:auto }
    thead { display:table-header-group }
    tfoot { display:table-footer-group }
</style>
HTML

Frequently Asked Questions

How can I add a page break in an HTML document?

To add a page break in an HTML document, you can use the CSS style 'page-break-after: always;' within a

element in your HTML code using IronPDF.

How to avoid page breaks in images when converting HTML to PDF?

To avoid page breaks in images, apply the CSS attribute 'page-break-inside: avoid' to a wrapping

element around the image using IronPDF.

Can I prevent page breaks within tables?

Yes, you can prevent page breaks within tables by using the CSS 'page-break-inside: avoid' on a wrapping

element. This ensures that the table is treated as a block-level element in IronPDF.

How can I ensure table headers are repeated on each page in a PDF?

To ensure table headers repeat on each page, use a group in your HTML table structure. This allows headers to be duplicated across multiple pages when using IronPDF.

What are some advanced CSS settings for controlling page breaks in PDFs?

Advanced CSS settings include using 'page-break-inside: auto' for tables, 'page-break-inside: avoid; page-break-after: auto' for rows, and setting 'display: table-header-group' for and 'display: table-footer-group' for in IronPDF.

What is the main difference between HTML documents and PDFs regarding page layout?

The main difference is that HTML documents tend to scroll continuously, while PDFs are multi-paged and can be printed, requiring proper pagination. This is managed using IronPDF.

Is there a C# library available for adding page breaks in PDFs?

Yes, the IronPDF C# library can be used to manage page breaks when converting HTML to PDF. It supports various settings for handling page breaks effectively.

Chaknith Bin
Software Engineer
Chaknith works on IronXL and IronBarcode. He has deep expertise in C# and .NET, helping improve the software and support customers. His insights from user interactions contribute to better products, documentation, and overall experience.