CSS Fragmentation Module Level 3

W3C Candidate Recommendation,

This version:
http://www.w3.org/TR/2016/CR-css-break-3-20160114/
Latest version:
http://www.w3.org/TR/css-break-3/
Editor's Draft:
http://dev.w3.org/csswg/css-break/
Previous Versions:
http://www.w3.org/TR/2015/WD-css3-break-20150129/
Feedback:
www-style@w3.org with subject line “[css-break] … message topic …” (archives)
Test Suite:
http://test.csswg.org/suites/css-break-3_dev/nightly-unstable/
Editors:
(Microsoft)
Elika J. Etemad / fantasai (Invited Expert)

Abstract

This module describes the fragmentation model that partitions a flow into pages, columns, or regions. It builds on the Page model module and introduces and defines the fragmentation model. It adds functionality for pagination, breaking variable fragment size and orientation, widows and orphans.

CSS is a language for describing the rendering of structured documents (such as HTML and XML) on screen, on paper, in speech, etc.

Status of this document

This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.

This document was produced by the CSS Working Group (part of the Style Activity) as a Candidate Recommendation. This document is intended to become a W3C Recommendation. This document will remain a Candidate Recommendation at least until in order to ensure the opportunity for wide review.

The (archived) public mailing list www-style@w3.org (see instructions) is preferred for discussion of this specification. When sending e-mail, please put the text “css-break” in the subject, preferably like this: “[css-break] …summary of comment…

Publication as a Candidate Recommendation does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.

This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.

This document is governed by the 1 September 2015 W3C Process Document.

For changes since the last draft, see the Changes section.

The following features are at-risk, and may be dropped during the CR period:

“At-risk” is a W3C Process term-of-art, and does not necessarily imply that the feature is in danger of being dropped or delayed. It means that the WG believes the feature may have difficulting being interoperably implemented in a timely manner, and marking it as such allows the WG to drop the feature if necessary when transitioning to the Proposed Rec stage, without having to publish a new Candidate Rec without the feature first.

Table of Contents

Breaking the Web, one fragment at a time

1. Introduction

This section is not normative.

In paged media (e.g., paper, transparencies, photo album pages, pages displayed on computer screens as printed output simulations), as opposed to continuous media, the content of the document is split into one or more discrete display surfaces. In order to avoid awkward breaks (such as halfway through a line of text), the layout engine must be able to shift around content that would fall across the page break. This process is called pagination.

In CSS, in addition to paged media, certain layout features such as regions [CSS3-REGIONS] and multi-column layout [CSS3COL] create a similarly fragmented environment. The generic term for breaking content across containers is fragmentation. This module explains how content breaks across fragmentation containers (fragmentainers) such as pages and columns and how such breaks can be controlled by the author.

1.1. Module Interactions

This module replaces and extends the pagination controls defined in [CSS21] section 13.3 and in [CSS3PAGE].

1.2. Values

This specification follows the CSS property definition conventions from [CSS21]. Value types not defined in this specification are defined in CSS Level 2 Revision 1 [CSS21]. Other CSS modules may expand the definitions of these value types: for example [CSS3VAL], when combined with this module, adds the initial value to the properties defined here.

In addition to the property-specific values listed in their definitions, all properties defined in this specification also accept the inherit keyword as their property value. For readability it has not been repeated explicitly.

2. Fragmentation Model and Terminology

fragmentation container (fragmentainer)
A box—such as a page box, column box, or region—that contains a portion (or all) of a fragmented flow. Fragmentainers can be pre-defined, or generated as needed. When breakable content would overflow a fragmentainer in the block dimension, it breaks into the next container in its fragmentation context instead.
fragmentation context
An ordered series of fragmentainers, such as created by a multi-column element, a chain of CSS regions, or a paged media display. A given fragmentation context can only have one block flow direction across all its fragmentainers. (Descendants of the fragmentation root may have other block flow directions, but fragmentation proceeds according to the block flow direction applied to the fragmentation root.)
fragmented flow
Content that is being laid out in a fragmentation context. The fragmented flow consists of the content of a (possibly anonymous) box called the fragmentation root.
fragmentation direction
The block flow direction of the fragmentation context, i.e. the direction in which content is fragmented. (In this level of CSS, content only fragments in one dimension.)
fragmentation
The process of splitting a content flow across the fragmentainers that form a fragmentation context.
box fragment or fragment
The portion of a box that belongs to exactly one fragmentainer. A box in continuous flow always consists of only one fragment. A box in a fragmented flow consists of one or more fragments. Each fragment has its own share of the box’s border, padding, and margin, and therefore has its own padding area, border area, and margin area. (See box-decoration-break, which controls how these are affected by fragmentation.)
remaining fragmentainer extent
The remaining block-axis space in the fragmentainer available to a given element, i.e. between the end of preceding content in fragmentainer and the edge of the fragmentainer.

Each fragmentation break (hereafter, break) ends layout of the fragmented box in the current fragmentainer and causes the remaining content to be laid out in the next fragmentainer, in some cases causing a new fragmentainer to be generated to hold the deferred content.

Breaking inline content into lines is another form of fragmentation, and similarly creates box fragments when it breaks inline boxes across line boxes. However, inline breaking is not covered here; see [CSS21]/[CSS3TEXT].

2.1. Parallel Fragmentation Flows

When multiple formatting contexts are laid out parallel to each other, fragmentation is performed independently in each formatting context. For example, if an element is floated, then a forced break inside the float will not affect the content outside the float (except insofar as it may increase the height of the float). UAs may (but are not required to) adjust the placement of unforced breaks in parallel formatting contexts to visually balance such side-by-side content, but must not do so to match a forced break.

The following are examples of parallel flows whose contents will fragment independently:

Content overflowing the content edge of a fixed-size box is considered parallel to the content after the fixed-size box and follows the normal fragmentation rules. Although overflowing content doesn’t affect the size of the fragmentation root box, it does increase the length of the fragmented flow, spilling into or generating additional fragmentainers as necessary.

2.2. Nested Fragmentation Flows

Breaking a fragmentainer F effectively splits the fragmentainer into two fragmentainers (F1 and F2). The only difference is that, with regards to the content of fragmentainer F, the type of break between the two pieces F1 and F2 is the type of break created by the fragmentation context that split F, not the type of break normally created by F’s own fragmentation context.

For example, if a region box is broken at a page boundary, then the content of the region will be affected by a page break at that point (but not by a region break).
Note that when a multi-column element breaks across pages, it generates a new row of columns on the next page for the rest of its content, so that a page break within a multi-column element is always both a page break and a column break.

3. Controlling Breaks

The following sections explain how breaks are controlled in a fragmented flow. A page/column/region break opportunity between two boxes is under the influence of the containing block’s break-inside property, the break-after property of the preceding element, and the break-before property of the following element. A page/column/region break opportunity between line boxes is under the influence of the containing block’s break-inside, widows, and orphans properties. A fragmentation break can be allowed, forced, or discouraged depending on the values of these properties. A forced break overrides any break restrictions acting at that break point. In the case of forced page breaks, the author can also specify on which page (left or right) the subsequent content should resume.

See the section on rules for breaking for the exact rules on how these properties affect fragmentation.

3.1. Breaks Between Boxes: the break-before and break-after properties

Name: break-before, break-after
Value: auto | avoid | avoid-page | page | left | right | recto | verso | avoid-column | column | avoid-region | region
Initial: auto
Applies to: block-level elements, table row groups, table rows (but see prose)
Inherited: no
Percentages: N/A
Media: visual
Computed value: specified value

These properties specify page/column/region break behavior before/after the generated box. The forced break values left, right, recto, verso, page, column and region create a forced break in the flow while the avoid break values avoid, avoid-page, avoid-column and avoid-region indicate that content should be kept together.

Since breaks are only allowed between siblings, not between a box and its container (see Possible Break Points), a break-before value on a first-child box is propagated to its container. Likewise a break-after value on a last-child box is propagated to its container. (Conflicting values combine as defined below.) This propagation stops before it breaks through the nearest matching fragmentation context.

Values for break-before and break-after are defined in the sub-sections below. User Agents must apply these properties to boxes in the normal flow of the fragmentation root. User agents should also apply these properties to floated boxes whose containing block is in the normal flow of the root fragmented element. User agents may also apply these properties to other boxes.

Generic Break Values

These values have an effect regardless of the type of fragmented context containing the flow.

auto
Neither force nor forbid a break before/after the principal box.
avoid
Avoid a break before/after the principal box.

Page Break Values

These values only have an effect in paginated contexts; if the flow is not paginated, they have no effect.

avoid-page
Avoid a page break before/after the principal box.
page
Always force a page break before/after the principal box.
left
Force one or two page breaks before/after the principal box so that the next page is formatted as a left page.
right
Force one or two page breaks before/after the principal box so that the next page is formatted as a right page.
recto
Force one or two page breaks before/after the principal box so that the next page is formatted as either a left page or a right page, whichever is second (according to the page progression) in a page spread.
verso
Force one or two page breaks before/after the principal box so that the next page is formatted as either a left page or a right page, whichever is first (according to the page progression) in a page spread.

Column Break Values

These values only have an effect in multi-column contexts; if the flow is not within a multi-column context, they have no effect.

avoid-column
Avoid a column break before/after the principal box.
column
Always force a column break before/after the principal box.

Region Break Values

These values only have an effect in multi-region contexts; if the flow is not linked across multiple regions, these values have no effect.

avoid-region
Avoid a region break before/after the principal box.
region
Always force a region break before/after the principal box.

3.2. Breaks Within Boxes: the break-inside property

Name: break-inside
Value: auto | avoid | avoid-page | avoid-column | avoid-region
Initial: auto
Applies to: elements in the normal flow that establish formatting contexts, or that are block containers, table row groups, or table rows
Inherited: no
Percentages: N/A
Media: visual
Computed value: specified value

This property specifies page/column/region break behavior within the element’s principal box. Values have the following meanings:

auto
Impose no additional breaking constraints within the box.
avoid
Avoid breaks within the box.
avoid-page
Avoid a page break within the box.
avoid-column
Avoid a column break within the box.
avoid-region
Avoid a region break within the box.

3.3. Breaks Between Lines: orphans, widows

Name: orphans, widows
Value: <integer>
Initial: 2
Applies to: block containers
Inherited: yes
Percentages: N/A
Media: visual
Computed value: specified value

The orphans property specifies the minimum number of line boxes in a block container that must be left in a fragment before a fragmentation break. The widows property specifies the minimum number of line boxes of a block container that must be left in a fragment after a break. Examples of how they are used to control fragmentation breaks are given below.

Only positive integers are allowed as values of orphans and widows. Negative values and zero are invalid and must cause the declaration to be ignored.

If a block contains fewer lines than the value of widows or orphans, the rule simply becomes that all lines in the block must be kept together.

3.4. Page Break Aliases: the page-break-before, page-break-after, and page-break-inside properties

For compatibility with CSS Level 2, UAs that conform to [CSS21] must alias the page-break-before, page-break-after, and page-break-inside properties to break-before, break-after, and break-inside by treating the page-break-* properties as shorthands for the break-* properties with the following value mappings:

Shorthand (page-break-*) Values Longhand (break-*) Values
auto | left | right | avoid auto | left | right | avoid
always page

4. Rules for Breaking

A fragmented flow may be broken across fragmentainers at a number of possible break points. In the case of forced breaks, the UA is required to break the flow at that point. In the case of unforced breaks, the UA has to choose among the possible breaks that are allowed.

To guarantee progress, fragmentainers are assumed to have a minimum block size of 1px regardless of their used size.

4.1. Possible Break Points

Fragmentation splits boxes in the block flow dimension. In block-and-inline flow, breaks may occur at the following places:

Class A
Between sibling boxes of the following types:
Block-parallel Fragmentation
When the block flow direction of the siblings' containing block is parallel to that of the fragmentation context: in-flow block-level boxes, a float and an immediately-adjacent in-flow or floated box, table row group boxes, table row boxes, multi-column column row boxes.
Block-perpendicular Fragmentation
When the block flow direction of the siblings' containing block is perpendicular to that of the fragmentation context: table column group boxes, table column boxes, multi-column column boxes.
Class B
Between line boxes inside a block container box.
Class C
Between the content edge of a block container box and the outer edges of its child content (margin edges of block-level children or line box edges for inline-level children) if there is a (non-zero) gap between them.

There is no inherent prioritization among these classes of break points. However, individual break points may be prioritized or de-prioritized by using the breaking controls.

Other layout models may add breakpoints to the above classes. For example, [CSS3-FLEXBOX] adds certain points within a flex formatting context to classes A and C.

Some content is not fragmentable, for example many types of replaced elements [CSS21] (such as images or video), scrollable elements, or a single line of text content. Such content is considered monolithic: it contains no possible break points. Any forced breaks within such boxes therefore cannot split the box, and must therefore also be ignored by the box’s own fragmentation context.

In addition to any content which is not generally fragmentable, UAs may consider as monolithic any elements with overflow set to auto or scroll and any elements with overflow: hidden and a non-auto logical height (and no specified maximum logical height).

Since line boxes contain no possible break points, inline-block and inline-table boxes (and other inline-level display types that establish a new formatting context) may also be considered monolithic.

4.2. Types of Breaks

There are different types of breaks in CSS, defined based on the type of fragmentainers they span:

page break
A break between two page boxes. [CSS3PAGE]
spread break
A break between two page boxes that are not associated with facing pages. A spread break is always also a page break. [CSS3PAGE]
column break
A break between two column boxes. Note that if the column boxes are on different pages, then the break is also a page break. Similarly, if the column boxes are in different regions, then the break is also a region break. [CSS3COL]
region break
A break between two regions. Note that if the region boxes are on different pages, then the break is also a page break. [CSS3-REGIONS]

A fifth type of break is the line break, which is a break between two line boxes. These are not covered in this specification; see [CSS21] [CSS3TEXT].

4.3. Forced Breaks

A forced break is one explicitly indicated by the style sheet author. A forced break occurs at a class A break point if, among the break-after properties specified on or propagated to the earlier sibling box and the break-before properties specified on or propagated to the later sibling box there is at least one with a forced break value. (Thus a forced break value effectively overrides any avoid break value that also applies at that break point.)

When multiple