CSS
🎯 CSS page-break-after Property
The page-break-after property determines whether a new page should be forced or prevented immediately after a specific HTML element when printing a web document.
This property is highly essential for crafting print stylesheets (`@media print`). It allows developers to dictate exactly where a printed page ends, ensuring subsequent content seamlessly transitions to the top of the next page.
🔧 page-break-after Values and Their Meanings
This property manages page layouts for printing using the following primary values:
1️⃣ auto
This is the default value. The browser automatically manages the layout based on the natural flow of the page, initiating a page break only when the content reaches the physical printing boundary of the paper.
.paragraph {
page-break-after: auto;
}
2️⃣ always
Forces a new page break immediately after the selected HTML element. This guarantees that whatever element comes next in the HTML markup will be pushed directly to the top of a fresh printed page.
.end-of-chapter {
page-break-after: always;
}
3️⃣ initial
Resets the property back to its initial, standard CSS value, causing it to function identically to auto.
.box {
page-break-after: initial;
}
🧪 Practical Example: Multi-page Reports and Booklets
When structuring document endpoints, you can force the next container to start fresh on a new paper sheet once the current section wraps up:
@media print {
/* Ensure a clean separation after summary reports or specific sections */
.report-summary,
.cover-page {
page-break-after: always;
}
}
🚀 Common Use Cases & Real-World Benefits
Implementing smart page breaks elevates the readability and aesthetics of physical documents:
- Ideal for finalizing cover pages, making sure the actual content starts on page two.
- Perfect for ending discrete chapters, analytical data groups, or tables within large document sheets.
- Prevents subsequent headers from dangling awkwardly at the absolute bottom of a page.
-
💡 Modern CSS Integration
- Just like its sibling properties, page-break-after is legacy syntax now legacy-mapped into the broader break-after property. Declaring both in your print styles yields excellent cross-browser backwards compatibility.
-
🧠 Quick Summary
- auto: Browser decides page break points automatically as space requires (Default).
- always: Forces the page to cut immediately after this element, sending following content to the next page.
- initial: Reverts back to standard automatic document rendering (auto).
