CSS
🎯 CSS page-break-inside Property
The page-break-inside property determines whether a page break is allowed to occur within the boundaries of a specific HTML element when printing a web document.
In other words, this property controls whether a multi-line element, a box, or a table row can be split across two separate sheets of paper, or if it must stay completely intact on a single page.
🔧 page-break-inside Values and Their Meanings
This property lets you manage printed layout fracturing using the following core values:
1️⃣ auto
This is the default value. The browser automatically slices content wherever a physical page margin occurs. If an element falls directly on a page boundary, it will be fragmented and split onto the next page seamlessly.
.article-body {
page-break-inside: auto;
}
2️⃣ avoid
Instructs the printer to avoid breaking the specified element across two pages. If the element cannot fit entirely at the bottom of the current sheet, the browser will push the **entire element** to the top of the next page to keep it whole.
.pricing-card,
tr {
page-break-inside: avoid;
}
3️⃣ initial
Resets the property back to its default global CSS layout rule, behaving exactly like auto.
.box {
page-break-inside: initial;
}
🧪 Practical Example: Preventing Broken Tables or Cards
When a user prints data tables or pricing cards, half-empty tables look unprofessional. Use avoid to keep rows and content blocks together:
@media print {
/* Prevent table rows, images, and signature blocks from cutting in half */
tr,
img,
.signature-area,
.info-card {
page-break-inside: avoid;
}
}
🚀 Why Is It Crucial for Clean Printing Layouts?
Without configuring this property, dense data sets and creative assets can look poorly formatted when turned into physical documents or PDFs:
- **Table Integrity:** Prevents a single row of a table from being sliced horizontally across two sheets.
- **Component Binding:** Ensures that elements like testimonial blocks, cards, or product listings stay grouped together.
- **Polished Aesthetics:** Shifts overlapping components to a fresh page to enhance user readability.
-
💡 Modern Break Properties
- In modern web layouts, page-break-inside is safely consolidated into the modern break-inside spec. Including both declarations inside your `@media print` blocks maximizes modern multi-browser and legacy printer runtime rendering.
-
🧠 Quick Summary
- auto: Elements can be divided and split down the middle across separate pages if necessary (Default).
- avoid: Stops the browser from cutting the element, moving the whole element to the next page instead.
- initial: Reverts standard parameters back to normal document layout behavior (auto).
