break-before

Avatar of Sunkanmi Fafowora
Sunkanmi Fafowora on (Updated on )

The CSS break-before property is neat in that it allows, forces, or prevents breaks in paged media, multi-column layouts, and regions. When applying the property to an element, what we’re doing is providing an instruction for whether to break or prevent breaks between pages, columns, and regions.

Note: break-before is an alias for the deprecated page-break-before property.

Syntax

break-before: auto | avoid | always | all | avoid-page | page | left | right | recto | verso | avoid-column | column | avoid-region | region
  • Initial: auto
  • Applies to: block-level boxes, grid items, flex items, table row groups, table rows
  • Inherited: no
  • Computed value: as specified
  • Animation type: discrete

Values

At the time of this writing, the following values are defined in the CSS Fragmentation Module Level 4 specification, which is in Editor Draft status. So, some of the following values are experimental and could change at some point. In fact, the generic all and always values below were not included in the Level 3 specifications.

The big thing to know about break-before is that it is designed to work with paged media, multi-column layouts, and regions. That means we have three sets of possible values that can be used depending on the context.

Generic break values

These values are generic in the sense that they can be used in all three contexts:

  • auto: Neither forces nor forbids a break (page, column, or region) before the element.
  • avoid: Avoids a break (page, column, or region) before the element.
  • all: (Experimental) Forces a page break after the element, breaking all possible fragmentation contexts. So, a break inside a multi-column container that’s inside a page container would force both a column and page break.
  • always: (Experimental) Forces a break after the element. This value is in the context of the immediately-containing fragmentation. For example, if we are inside a multi-column container — like using the column property on the parent container — then it would force a column break; inside paged media, it would force a page break.

Paged Media values

  • avoid-page: Avoids any page break before the element.
  • page: Forces a page break before the element.
  • left: Forces one or two page breaks before the element, so anything that makes it to the next page will be formatted to the left; that is, it starts from the left page.
  • right: Forces one or two page breaks before the element, so anything that makes it to the next page will be formatted to the right, that is it starts from the right page.
  • recto: (Experimental) Forces one or two page breaks before the element, so that the next page is formatted as a recto page (i.e. a right page moving from left-to-right or a left page moving right-to-left).
  • verso: (Experimental) Forces one or two page breaks before the element so that the next page is formatted as a verso page (i.e a left page moving from left-to-right or a right page moving from right-to-left)

Multi-column Layout values

  • avoid-column: (Experimental) Avoid a column break before the element.
  • column: (Experimental) Always forces a column break before the element.

Regions values

  • avoid-region: Avoids a region break before the element.
  • region: Always forces a region break before the element.

break-before replaces page-break-before

If break-before looks somewhat familiar, that’s because it takes the place of page-break-before, one of three page-break-related properties.

What’s the difference? Well, page-break-before was only for paged media. break-before is a lot more robust as far as where and how it can be used since, in addition to serving as an alias for page-break-before, it is also contained in the CSS Fragmentation, Multi-column Layout and Regions specifications.

Here’s a table of the break-before values that correspond with the legacy page-break-before property values if you’re using it as an alias:

break-beforepage-break-before
autoauto
avoidavoid
rightright
leftleft
pagealways

Even though break-before replaces page-break-before, it’s still a good idea to set page-break-before as a fallback for browsers that might lack support for break-before:

.element {
  page-break-before: always; /* fallback */
  break-before: page;
}

But as far as going on and changing page-break-before to break-before throughout your code, no worries. page-break-before is now listed as a legacy shorthand for break-before and will conform to the table values above.

Demos

Let’s take a look at a couple of demos to better understand how break-before works.

Multi-column layout

In this demo, we have a set of boxes that we want to display as in a multi-column layout. Specifically, we want each box to be a column. This is the HTML:

<main>

  <section>
    <h2>Heading</h2>
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit.
      Aliquid a corporis nostrum velit repudiandae fuga commodi aut delectus numquam.
      Debitis quod repellendus reprehenderit obcaecati asperiores?</p>
  </section>

  <section>
    <h2>Heading</h2>
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit.
      Aliquid a corporis nostrum velit repudiandae fuga commodi aut delectus numquam.
      Debitis quod repellendus reprehenderit obcaecati asperiores?</p>
  </section>

  <section>
    <h2>Heading</h2>
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit.
      Aliquid a corporis nostrum velit repudiandae fuga commodi aut delectus numquam.
      Debitis quod repellendus reprehenderit obcaecati asperiores?</p>
  </section>

  <!-- and so on... -->

</main>

If we were to simply define columns and stop there, there’s no guarantee that the boxes will line up nicely with one another.

That’s where break-before comes in. If we set it with a value of column (we are working with a multi-column layout afterall) on the <section> element like this:

section {
  break-after: column;
}

…then the columns will break right before each <section> which tidies things up nicely:

Paged Media alias

In this example, the avoid value is used to prevent any page, column, or region breaks in the layout so that when printing the page — yes, with a real printer that uses paper — there are no breaks between the columns. Instead, what we get is a nice single-column layout that’s better suited for printing:

Browser support

Browser support for break-before varies depending on the context it’s used.

Paged Media

Multi-column Layout

CSS Regions

More information