The HTML DOM Style pageBreakInside property returns and modify the page-break behavior for printing or print preview inside an HTML element in an HTML document.
Syntax
Following is the syntax −
1. Returning pageBreakInside
object.pageBreakInside
2. Modifying pageBreakInside
object.pageBreakInside = “value”
Here, value can be −
| Value | Explanation |
|---|---|
| initial | It sets this property value to its default value. |
| inherit | It inherits this property value from its parent element. |
| Auto | It inserts a page break inside the element in an HTML document if necessary. |
| avoid | It avoids a page break inside the element in an HTML document |
Let us see an example of HTML DOM Style pageBreakInside Property −
Example
<!DOCTYPE html>
<html>
<style>
body {
color: #000;
height: 100vh;
background-color: #8BC6EC;
background-image: linear-gradient(135deg, #8BC6EC 0%, #9599E2 100%);
}
.btn {
background: #db133a;
border: none;
height: 2rem;
border-radius: 2px;
width: 40%;
display: block;
color: #fff;
outline: none;
cursor: pointer;
margin: 1rem auto;
}
p {
text-align: center;
}
</style>
<body>
<h1 style="text-align:center">DOM Style pageBreakInside Property Demo</h1>
<p>
Hi! I'm a para element with some dummy text. Hi! I'm a para element with some dummy text.
</p>
<p class="page-break">
Hi! I'm second para element with some dummy text. Hi! I'm a second element with some dummy text.
</p>
<button onclick="set()" class="btn">Set Break Page Here</button>
<p>
Hi! I'm another para element with some dummy text. Hi! I'm another para element with some dummy text.
</p>
<script>
function set() {
document.querySelector(".page-break").style.pageBreakInside = "avoid";
}
</script>
</body>
</html>Output

Now open print preview and observe how our html page would be displayed. And then click on the red button to avoid page-break behaviour in the document −
