CSS Properties
CSS break-after Property
Photo Credit to CodeToFun
🙋 Introduction
The break-after
property in CSS is used to control the behavior of page, column, or region breaks after an element. It is particularly useful in paged media, multi-column layouts, and other situations where content needs to be broken up across multiple pages, columns, or regions.
This property helps in managing the flow of content in a more controlled and predictable manner.
💡 Syntax
The syntax for the break-after
property is simple. You apply it to an element and specify the type of break you want to occur after that element.
element {
break-after: value;
}
🎛️ Default Value
The default value of the break-after
property is auto, meaning that no explicit break is applied, and the break behavior is determined by the browser's default settings.
🏠 Property Values
Value | Description |
---|---|
auto | Default value. Automatic page/column/region break behavior. |
always | Always force a page/column/region break after the element. |
avoid | Avoid a page/column/region break after the element. |
left | Force a page/column/region break after the element, so that the next page/column/region is formatted as a left page. |
right | Force a page/column/region break after the element, so that the next page/column/region is formatted as a right page. |
page | Force a page break after the element. |
column | Force a column break after the element. |
region | Force a region break after the element. |
📄 Example
In this example, we'll apply the break-after
property to a div element to ensure a page break after the element in a paged media context.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS break-after Example</title>
<style>
.page-break {
break-after: page;
}
</style>
</head>
<body>
<h1>Content Before Page Break</h1>
<div class="page-break">
This content will be followed by a page break.
</div>
<h1>Content After Page Break</h1>
<p>This content will appear on a new page.</p>
</body>
</html>
🖥️ Browser Compatibility
The break-after
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-after
property is a valuable tool for managing content flow in complex layouts, especially when dealing with paged media, multi-column layouts, or regions. By using this property, you can create more controlled and predictable layouts, ensuring that content breaks occur exactly where you want them. Experiment with different values to see how this property can enhance the readability and presentation of your web projects.
👨💻 Join our Community:
Author
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
If you have any doubts regarding this article (CSS break-after Property), please comment here. I will help you immediately.