CSS page-break Property

Actually, there is no page-break property in the CSS specification. It is a set of three properties: page-break-inside, page-break-before, and page-break-after. These properties define the behavior of the document when printed.

Page-break-after

The page-break-after property defines page break after the element.

This property cannot be used on an empty <div> or on absolutely positioned elements.

The page-break-after property is replaced by break-after property.

Example

@media print {
footer {page-break-after: left;}
}

Page-break-before

The page-break-before property defines page break before the element.

This property cannot be used on an empty <div> or on absolutely positioned elements.

The page-break-before property is replaced by break-before property.

Example

@media print {
h2 { 
page-break-before: right; 
}

Page-break-inside

The page-break-inside property defines the page break inside the element.

This property cannot be used on an empty <div> or on absolutely positioned elements.

The page-break-inside property is replaced by break-inside property.

Example

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      .example{
      background-color: #8ebf42;
      height: 90px;
      width: 200px;
      columns: 1;
      column-width: 80px;
      }
      .list, ol, ul, p {
      break-inside: avoid;
      }
      p {
      background-color: #8ebf42;
      }
      ol, ul, .list {
      margin: 0.5em 0;
      display: block;
      background-color: #1c87c9;
      }
      p:first-child {
      margin-top: 1;
      }
    </style>
  </head>
  <body>
    <h2>Page-break property example</h2>
    <div class="example">
      <p>The first paragraph.</p>
      <section class="list">
        <span>A list</span>
        <ol>
          <li>one</li>
        </ol>
      </section>
      <ul>
        <li>one</li>
      </ul>
      <p>The second paragraph.</p>
      <p>The third paragraph, it contains more text.</p>
      <p>The fourth paragraph. It has a little bit more text than the third one.</p>
    </div>
  </body>
</html>

Practice Your Knowledge

page-break is a set of three properties:




Related articles