CSS page-break-inside Property

You are Here:

CSS page-break-inside Property

CSS page-break-inside property sets whether a page-break should be avoided inside a specified element.

Example

HTML Online Editor
<!DOCTYPE html> <html lang="en-US"> <head> <title>CSS page-break-inside property</title> <style> @media print { p{ line-height: 2; page-break-inside: avoid; } } </style> </head> <body> <h1>Example CSS page-break-inside property</h1> <p> This page will not break inside the paragraph. ... This page will not break inside the paragraph. </p> <button onclick="window.print()">Print</button> </body> </html>

Syntax

Using CSS

element{ page-break-inside: avoid; }

Using Javascript

object.style.pageBreakInside="avoid";

Animatable

No, page-break-inside property is not animatable. CSS Animatable Properties Reference.

Default Value

Default value for CSS page-break-inside property is auto.

Property Value

The following table provides a list of values for CSS page-break-inside property.

ValueExplanation
autoAutomatic page breaks.
avoidAvoid page breaks inside the element.

Using JavaScript

In the following example, we will demonstrate how to set the CSS page-break-inside property of an element using JavaScript.

Example

HTML Online Editor
<!DOCTYPE html> <html lang="en-US"> <head> <style> p{ line-height: 2; } </style> </head> <body> <h1>CSS page-break-inside property</h1> <p> This page will not break inside the paragraph. ... This page will not break inside the paragraph. </p> <button onclick="window.print()">Print</button> <button onclick="myFunction()">Print with page-break-inside: avoid at p tag.</button> <script> function myFunction(){ var styles = 'p{page-break-inside: avoid;}'; var styleSheet = document.createElement("style") styleSheet.type = "text/css" styleSheet.media = "print" styleSheet.innerText = styles document.head.appendChild(styleSheet); window.print(); } window.onafterprint = function(){ location.reload(); } </script> </body> </html>

Reminder

Hi Developers, we almost covered 98.7% of CSS Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in CSS.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author