Tillitsdone
down Scroll to discover
CSS page-break-after Mastering Page Breaks
CSS page-break-after controls page breaks after elements for printed web pages.

Learn about its use cases, available options like auto, always, avoid, left, and right, and how to optimize your printed layout.
thumbnail

Introduction

The page-break-after property in CSS helps control where pages break when printing a web page. It’s essential for web design, ensuring content is well-organized and easy to read. While page-break-after is older, understanding it helps maintain compatibility with older sites and browsers.

Specification

The page-break-after property is part of the CSS Paged Media Module, which defines formatting for printed documents. It allows developers to control page breaks after specific elements, improving the appearance and readability of printed content.

The page-break-after property is defined in the following specifications:

  1. CSS Logical Properties and Values Level 1: Describes logical properties that adapt to the writing mode and script of the document.
  2. CSS Paged Media Module Level 3: Specifically addresses the formatting of content in paged media, providing detailed control over page breaks.

Syntax

The page-break-after property is used to control page breaks after elements when printing. The syntax is straightforward:

page-break-after: value;

Keyword Values

  • auto: Default value, allowing automatic page breaks.
  • always: Forces a page break after the element.
  • avoid: Prevents a page break after the element, if possible.
  • left: Forces a page break so the next page is a left page.
  • right: Forces a page break so the next page is a right page.
  • recto: Acts like right for left-to-right pages, and like left for right-to-left pages.
  • verso: Acts like left for left-to-right pages, and like right for right-to-left pages.

Global Values

  • inherit: Inherits the value from its parent.
  • initial: Sets the property to its default value (auto).
  • revert: Resets the property to the user agent’s default value.
  • revert-layer: Resets the property to the value established by the originating layer.
  • unset: Acts as either initial or inherit.

Example Syntax

/* Force a page break after a footer element */
footer {
page-break-after: always;
}

This property applies to block-level elements that generate a box.

Values

The page-break-after property can take several values to define how page breaks should be handled after an element:

auto

page-break-after: auto;

always

page-break-after: always;

avoid

page-break-after: avoid;

left

page-break-after: left;

right

page-break-after: right;

recto

page-break-after: recto;

verso

page-break-after: verso;

Global Values

  • inherit
    page-break-after: inherit;
  • initial
    page-break-after: initial;
  • revert
    page-break-after: revert;
  • revert-layer
    page-break-after: revert-layer;
  • unset
    page-break-after: unset;

Page Break Aliases

The page-break-after property is considered a legacy property and has been largely replaced by the break-after property in modern CSS. For compatibility reasons, page-break-after is often treated as an alias of break-after.

Alias Mapping

page-break-after Valuebreak-after Value
autoauto
leftleft
rightright
avoidavoid
alwayspage

Example of Aliasing

/* Using page-break-after */
div {
page-break-after: always;
}
/* Equivalent using break-after */
div {
break-after: page;
}

Best Practices

  • Check Compatibility: Always check browser compatibility tables.
  • Use Both Properties: For maximum compatibility, use both properties:
    div {
    page-break-after: always;
    break-after: page;
    }
  • Plan for Transition: If maintaining an older codebase, plan to transition to break-after gradually.

Formal Definition

The page-break-after property controls page breaks after specific elements when printing.

Initial Value

  • auto: Allows automatic page breaks.

Applies To

  • Block-level elements: Applies to block-level elements in the normal flow.

Inherited

  • No: This property is not inherited from parent elements.

Computed Value

  • As specified: The computed value is the same as the specified value.

Animation Type

  • Discrete: Changes abruptly from one value to another.

Formal Syntax

page-break-after =
auto |
always |
avoid |
left |
right |
recto |
verso |
inherit

Examples

Setting a Page Break After Footnotes

/* Move to a new page after footnotes */
div.footnotes {
page-break-after: always;
}

Avoiding Page Breaks After Headings

/* Avoid a page break after headings */
h1, h2, h3 {
page-break-after: avoid;
}

Ensuring Left-Page Formatting After Sections

/* Force the next page to be a left page after sections */
section {
page-break-after: left;
}

Ensuring Right-Page Formatting After Paragraphs

/* Force the next page to be a right page after paragraphs */
p {
page-break-after: right;
}

Using recto and verso for Directional Page Breaks

/* Adapt to page progression direction */
div.chapter {
page-break-after: recto;
}
div.section {
page-break-after: verso;
}

Example HTML and CSS

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Page Break Example</title>
<style>
footer {
page-break-after: always;
}
h1, h2, h3 {
page-break-after: avoid;
}
section {
page-break-after: left;
}
p {
page-break-after: right;
}
div.chapter {
page-break-after: recto;
}
div.section {
page-break-after: verso;
}
</style>
</head>
<body>
<h1>Introduction</h1>
<p>This is an example of how to use the page-break-after property in CSS.</p>
<section>
<h2>Section 1</h2>
<p>This section will force the next page to be a left page.</p>
</section>
<div class="chapter">
<h2>Chapter 1</h2>
<p>This chapter will adapt to the page progression direction.</p>
</div>
<footer>
<p>This footer will force a page break after it.</p>
</footer>
</body>
</html>

By using the page-break-after property effectively, you can ensure that your printed documents are well-organized and easy to read.

Browser Compatibility

The page-break-after property is widely supported across modern web browsers, ensuring that your printed documents maintain their intended layout and formatting. Here’s a breakdown of the browser compatibility for the page-break-after property:

Browser Support

BrowserVersionRelease Date
Google Chrome1.0Dec 2008
Firefox1.0Nov 2004
Internet Explorer/Edge4.0Sep 1997
Opera7Jan 2003
Safari1.0Jun 2003

Compatibility Notes

  • Google Chrome: The page-break-after property has been supported since the first version of Google Chrome, released in December 2008.
  • Firefox: Firefox has supported this property since its initial release in November 2004.
  • Internet Explorer/Edge: Support for page-break-after began with Internet Explorer 4.0, released in September 1997. The Edge browser, which succeeded Internet Explorer, continues to support this property.
  • Opera: Opera has supported page-break-after since version 7, released in January 2003.
  • Safari: Safari has supported this property since its first version, released in June 2003.

Best Practices for Compatibility

While the page-break-after property is well-supported, it’s important to consider the following best practices to ensure compatibility across all browsers:

  1. Use Both Properties: For maximum compatibility, use both page-break-after and break-after in your CSS. This ensures that your printed layout is maintained across both older and newer browsers.
    div {
    page-break-after: always;
    break-after: page;
    }
  2. Check Browser Compatibility Tables: Regularly refer to browser compatibility tables to stay updated on the latest support for CSS properties.
  3. Test Across Browsers: Always test your printed documents across different browsers to ensure that the layout is consistent and as intended.
  4. Fallback Values: Use CSS fallback values to ensure that your content remains readable even if the page-break-after property is not supported.
    div {
    page-break-after: always;
    page-break-after: avoid; /* Fallback for unsupported browsers */
    }

Example of Browser-Specific CSS

Here’s an example of how you might use browser-specific CSS to ensure compatibility:

/* General rule */
footer {
page-break-after: always;
break-after: page;
}
/* Fallback for older browsers */
@media print {
footer {
page-break-after: avoid; /* Fallback if page-break-after is not supported */
}
}

By following these best practices and understanding the browser compatibility of the page-break-after property, you can ensure that your printed documents are well-formatted and readable across all major browsers. This enhances the user experience and professionalism of your web content.

See Also

To further enhance your web development and design skills, you might want to explore related CSS properties and resources. Here are some useful links and references that can help you better understand and utilize page break properties:

Related CSS Properties

  • break-before: This property controls page breaks before an element, providing similar functionality to page-break-before.
  • break-after: This property controls page breaks after an element, effectively replacing page-break-after.
  • break-inside: This property controls page breaks inside an element, helping to prevent breaks within specific content.
  • page-break-before: This property controls page breaks before an element, similar to break-before.
  • page-break-inside: This property controls page breaks inside an element, similar to break-inside.

Additional Resources

  • orphans: This property specifies the minimum number of lines that must be left at the bottom of a page.
  • widows: This property specifies the minimum number of lines that must be left at the top of a page.

Helpful Guides and References

Learning More

  • MDN Web Docs: The Mozilla Developer Network offers comprehensive documentation and examples for the page-break-after property.
  • W3C CSS Paged Media: The World Wide Web Consortium (W3C) provides official specifications and guidelines for CSS properties related to paged media.

By exploring these related properties and resources, you can gain a deeper understanding of how to control page breaks and enhance the printed layout of your web pages. This knowledge will help you create polished and professional documents that are well-formatted and easy to read.

Whether you’re a seasoned developer or just starting out, these resources will provide valuable insights and practical examples to help you master the use of page break properties in CSS.

Get in Touch
Thank you for your interest in Tillitsdone! Whether you have a question about our services, want to discuss a potential project, or simply want to say hello, we're here and ready to assist you.
We'll be right here with you every step of the way.
Contact Information
rick@tillitsdone.com+66824564755
Find All the Ways to Get in Touch with Tillitsdone - We're Just a Click, Call, or Message Away. We'll Be Right Here, Ready to Respond and Start a Conversation About Your Needs.
Address
9 Phahonyothin Rd, Khlong Nueng, Khlong Luang District, Pathum Thani, Bangkok Thailand
Visit Tillitsdone at Our Physical Location - We'd Love to Welcome You to Our Creative Space. We'll Be Right Here, Ready to Show You Around and Discuss Your Ideas in Person.
Social media
Connect with Tillitsdone on Various Social Platforms - Stay Updated and Engage with Our Latest Projects and Insights. We'll Be Right Here, Sharing Our Journey and Ready to Interact with You.
We anticipate your communication and look forward to discussing how we can contribute to your business's success.
We'll be here, prepared to commence this promising collaboration.
Frequently Asked Questions
Explore frequently asked questions about our products and services.
Whether you're curious about features, warranties, or shopping policies, we provide comprehensive answers to assist you.