Open In App

HTML DOM | Style pageBreakAfter Property

The Style pageBreakAfter property is used for setting or returning the page-break behavior after an element in printing or print preview. The Style pageBreakAfter property does not affect the absolutely positioned elements. 

Syntax : To get the property:



object.style.pageBreakAfter

To set the property:

object.style.pageBreakAfter = "auto|always|avoid|emptystring|left|
right|initial|inherit"

Return Values: It returns a string that represents the page-break behavior after an element when printing



Property Values:

Below program illustrates the Style pageBreakAfter property: 

Example 1: Setting a page break after the <p> element with id=”footer” 




<!DOCTYPE html>
<html>
<head>
  <title>Style pageBreakAfter Property in HTML</title>
  <style>
    h1 {
      color: green;
    }
    h2 {
      font-family: Impact;
    }
    body {
      text-align: center;
    }
  </style>
</head>
<body>
  <h1>GeeksforGeeks</h1>
  <h2>Style pageBreakAfter Property</h2>
  <br>
  <p id="myfooter">Geeksforgeeks is a portal for geeks.</p>
 
   
<p>For setting page break after footer paragraph,
    double click the "Set Page Break" button: </p>
 
  <br>
  <button ondblclick="pagebreak()">Set Page Break</button>
  <script>
    function pagebreak() {
      document.getElementById("myfooter")
        .style.pageBreakAfter = "always";
    }
  </script>
</body>
</html>

Output:

 

Note: In order to see the output, please save the code in HTML file and run it on your browser. The output will be seen when you will see the PRINT PREVIEW of that file. 

Supported Browsers: The browser supported by HTML DOM | Style pageBreakAfter Property are listed below:


Article Tags :