Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS break-before Property

Posted in CSS Tutorial
Updated on Oct 02, 2024
By Mari Selvan
👁️ 14 - Views
⏳ 4 mins
💬 1 Comment
CSS break-before Property

Photo Credit to CodeToFun

🙋 Introduction

The break-before property in CSS is used to control the page, column, or region break behavior before a specified element.

This property is particularly useful in paged media (such as printed documents) or multi-column layouts, allowing developers to dictate how content should flow across pages or columns.

💡 Syntax

The syntax for the break-before property is straightforward and accepts several keyword values that dictate the break behavior.

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

🎛️ Default Value

The default value of the break-before property is auto, which means no break is forced before the element, and the content flows naturally.

🏠 Property Values

ValueDescription
autoDefault value. Neither force nor forbid a break before the element.
alwaysAlways force a page break before the element.
avoidAvoid a page break before the element.
leftForce one or two page breaks before the element so that the next page is formatted as a left page.
rightForce one or two page breaks before the element so that the next page is formatted as a right page.
pageForce a page break before the element.
columnForce a column break before the element in a multi-column layout.
regionForce a region break before the element.

📄 Example

In this example, we'll force a page break before a heading element in a printed document.

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 break-before Example</title>
  <style>
    @media print {
      h2 {
        break-before: page;
      }
    }
  </style>
</head>
<body>
  <h1>Chapter 1</h1>
  <p>Content of the first chapter...</p>
  <h2>Chapter 2</h2>
  <p>Content of the second chapter...</p>
</body>
</html>

In this example, when the document is printed, a page break will be forced before the second heading (<h2>), ensuring that Chapter 2 starts on a new page.

🖥️ Browser Compatibility

The break-before property is supported in most modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. However, it is always a good practice to test your website across different browsers to ensure compatibility.

🎉 Conclusion

The break-before property is a useful tool for web developers working with paged media or multi-column layouts. It allows for fine-grained control over content flow, ensuring that elements appear in the desired locations across pages or columns.

By understanding and using this property, you can create more professional and well-organized documents and layouts.

👨‍💻 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