Skip to content
Related Articles

Related Articles

HTML DOM | Style pageBreakBefore Property
  • Last Updated : 29 Jan, 2019

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

Syntax :

object.style.pageBreakBefore

Property Values :

object.style.pageBreakBefore = “auto | always | avoid | emptystring | left | right | initial | inherit”

Values Description:



  • auto :It is used to insert a page break before the element if necessary.
  • always :It is used to insert a page break always before the element.
  • avoid : It is used to avoid a page break before an element.
  • emptystring : Page break is not inserted before the element.
  • left : It is used to insert one or two page breaks before the element, so the next page is considered a left page.
  • right : It is used to insert one or two page breaks before the element, so the next page is considered a right page.
  • initial : It is used to set this property to its default value.
  • inherit : It is used to inherit this property from its parent element.

Below program illustrates the Style pageBreakBefore property :

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




<!DOCTYPE html>
<html>
  
<head>
    <title>Style pageBreakBefore Property in HTML</title>
    <style>
        h1 {
            color: green;
        }
          
        h2 {
            font-family: Impact;
        }
          
        body {
            text-align: center;
        }
    </style>
</head>
  
<body>
  
    <h1>GeeksforGeeks</h1>
    <h2>Style pageBreakBefore Property</h2>
    <br>
  
    <p id="myfooter">Geeksforgeeks is a portal for geeks.</p>
  
    <p>For setting page break before 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.pageBreakBefore = "always";
        }
    </script>
  
</body>
  
</html>         

Output:

  • Before clicking Button:

  • After clicking the button

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.

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :