Guide
Controlling Page Breaks in Markdown to PDF Exports
Updated July 10, 2026
When converting Markdown documents into PDFs, one of the most common visual issues is poor page division. A heading might appear at the very bottom of a page, separated from its corresponding paragraph, or a multi-row table might split awkwardly across sheets.
To create professional documents, you must learn to control page breaks markdown to pdf converters respect. Depending on your toolchain, this can be done using HTML/CSS, LaTeX commands, or Pandoc configurations.
The Challenge of Page Segmentation
Markdown is designed for continuous reading on the web. It has no native concept of “pages.” When rendering a Markdown file to PDF, the rendering engine must decide where to split content. Without manual guidance, these split decisions can result in:
- Orphan headings: Headings placed at the bottom of a page with their content on the next page.
- Split tables or images: Tables divided halfway, or images cut into top and bottom halves.
- Imbalanced sections: New chapters starting mid-page instead of on a fresh sheet.
Method 1: Using HTML and CSS (Web-to-PDF Engines)
If your converter utilizes an HTML-based rendering engine (such as Weasyprint, Puppeteer, or PrinceXML), you can control page layout using CSS and raw HTML.
The CSS Page-Break Properties
Modern CSS provides three major properties to dictate page breaks:
break-before: Specifies whether a page break should occur before an element.break-after: Specifies whether a page break should occur after an element.break-inside: Avoids or forces page breaks inside an element (crucial for tables and images).
You can define these in a custom stylesheet:
/* Force a page break before every major header */
h2 {
break-before: page;
}
/* Prevent images and tables from breaking across pages */
img, table, pre {
break-inside: avoid;
}
Creating a Reusable Page Break Helper
If you only want to force a page break at a specific point in your Markdown file, insert a raw HTML div styled with a break-before:
Here is the end of the introduction.
<div style="break-before: page;"></div>
Here is the start of the next section on a fresh page.
Method 2: LaTeX Page Breaks (Pandoc Engines)
If you are using Pandoc with a LaTeX engine (like pdflatex or xelatex) to generate your PDFs, HTML and CSS page breaks will be ignored. Instead, you must use LaTeX commands.
Direct LaTeX Injection
LaTeX commands can be embedded directly into Markdown. The compiler will interpret them during export:
This is the end of chapter one.
\newpage
This is the start of chapter two.
Or you can use \clearpage, which behaves similarly but forces all pending figures and tables to render before the break.
Pandoc Header Templates
If you want to automate page breaks before every H1 or H2 header without manually inserting commands, you can specify this in your Pandoc template, or pass a filter that automatically injects page breaks prior to specific headers.
Method 3: Using CSS Paged Media for Dynamic Rules
For web-based compilers, using Paged Media rules helps keep documents tidy:
@media print {
h1, h2, h3 {
break-after: avoid; /* Prevent orphan headings */
}
blockquote {
break-inside: avoid;
}
}
Applying break-after: avoid to header elements ensures that headers will always stay attached to the paragraphs that follow them, pushing the header to the next page if space is insufficient.
Achieve Perfect Page Alignment
Controlling where your content splits is essential for creating high-quality, readable documents. If you want a quick and visual way to check how your custom styling and page breaks render, use our Markdown to PDF Editor for instant feedback and page break preview adjustments.
Written by Markdown to PDF Editorial Team
Our team specializes in document design, web standards, and developer utilities. This guide was researched and vetted against current browser printing standards and Paged.js specifications. Learn more on our About page.
Try it yourself — free, no signup
Convert your Markdown to a polished PDF right in your browser.
Open the editor