break-inside CSS property
Baseline
Widely available
*
This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2019.
* Some parts of this feature may have varying levels of support.
The break-inside CSS property sets how page, column, or region breaks should behave inside a generated box. If there is no generated box, the property is ignored.
Try it
break-inside: auto;
break-inside: avoid;
<div>
<p>
The effect of this property can be noticed when the document is being
printed or a preview of a print is displayed.
</p>
<button id="print-btn">Show Print Preview</button>
<div class="box-container">
<div class="box">Content before the property</div>
<div class="box" id="example-element">Content with 'break-inside'</div>
<div class="box">Content after the property</div>
</div>
</div>
.box {
border: solid #5b6dcd 5px;
background-color: #5b6dcd;
margin: 10px 0;
padding: 5px;
}
#example-element {
border: solid 5px #ffc129;
background-color: #ffc129;
color: black;
}
@media print {
#example-element {
height: 25cm;
}
}
const btn = document.getElementById("print-btn");
btn.addEventListener("click", () => {
window.print();
});
Syntax
/* Keyword values */
break-inside: auto;
break-inside: avoid;
break-inside: avoid-page;
break-inside: avoid-column;
break-inside: avoid-region;
/* Global values */
break-inside: inherit;
break-inside: initial;
break-inside: revert;
break-inside: revert-layer;
break-inside: unset;
Each possible break point (in other words, each element boundary) is affected by three properties: the break-after value of the previous element, the break-before value of the next element, and the break-inside value of the containing element.
To determine if a break must be done, the following rules are applied:
- If any of the three concerned values is a forced break value (
always,left,right,page,column, orregion), it has precedence. If more than one of them are such a break, the value of the element that appears the latest in the flow is used. Thus, thebreak-beforevalue has precedence over thebreak-aftervalue, which in turn has precedence over thebreak-insidevalue. - If any of the three concerned values is an avoid break value (
avoid,avoid-page,avoid-region, oravoid-column), no such break will be applied at that point.
Once forced breaks have been applied, soft breaks may be added if needed, but not on element boundaries that resolve in a corresponding avoid value.
Values
auto-
Allows, but does not force, any break (page, column, or region) to be inserted within the principal box.
avoid-
Avoids any break (page, column, or region) from being inserted within the principal box.
avoid-page-
Avoids any page break within the principal box.
avoid-column-
Avoids any column break within the principal box.
avoid-region-
Avoids any region break within the principal box.
Page break aliases
For compatibility reasons, the legacy page-break-inside property should be treated by browsers as an alias of break-inside. This ensures that sites using page-break-inside continue to work as designed. A subset of values should be aliased as follows:
| page-break-inside | break-inside |
|---|---|
auto |
auto |
avoid |
avoid |