Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS page-break-before Property

Posted in CSS Tutorial
Updated on Jul 21, 2024
By Mari Selvan
👁️ 10 - Views
⏳ 4 mins
💬 1 Comment
CSS page-break-before Property

Photo Credit to CodeToFun

🙋 Introduction

The page-break-before property in CSS is used when printing a document. It specifies whether a page break should occur before a particular element.

This property is useful for creating documents with well-defined sections or chapters, ensuring that specific elements start on a new page when printed.

💡 Syntax

The syntax for the page-break-before property is straightforward. It can be applied to any block-level element.

Syntax
Copied
Copy To Clipboard
element {
  page-break-before: value;
}

🎛️ Default Value

The default value of the page-break-before property is auto, which means the page break behavior is determined by the browser.

🏠 Property Values

ValueDescription
autoDefault. Allows the browser to decide whether a page break is needed.
alwaysAlways inserts a page break before the element.
avoidAvoids inserting a page break before the element.
leftInserts one or two page breaks before the element so that the next page is a left-hand page.
rightInserts one or two page breaks before the element so that the next page is a right-hand page.
inheritInherits this property from its parent element.

📄 Example

In this example, we'll ensure that a heading starts on a new page when printed.

index.html
Copied
Copy To Clipboard
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS page-break-before Example</title>
  <style>
    h1 {
      page-break-before: always;
    }
  </style>
</head>
<body>
  <h1>Section 1</h1>
  <p>This is the first section of the document.</p>
  <h1>Section 2</h1>
  <p>This is the second section of the document, and it starts on a new page when printed.</p>
</body>
</html>

🖥️ Browser Compatibility

The page-break-before property is supported in all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. It is also supported in Internet Explorer. However, as with any CSS property, it is good practice to test your website across different browsers to ensure compatibility.

🎉 Conclusion

The page-break-before property is a valuable tool for controlling the layout of printed documents.

By using this property, you can ensure that certain elements start on a new page, improving the readability and organization of your printed content. Experiment with different values to see how they can enhance the presentation of your printed documents.

👨‍💻 Join our Community:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.

Buy me a coffee to make codetofun.com free for everyone.

Buy me a Coffee

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy