CSS Overflow Module Level 4

W3C Working Draft,

More details about this document
This version:
https://www.w3.org/TR/2023/WD-css-overflow-4-20230321/
Latest published version:
https://www.w3.org/TR/css-overflow-4/
Editor's Draft:
https://drafts.csswg.org/css-overflow-4/
History:
https://www.w3.org/standards/history/css-overflow-4
Feedback:
CSSWG Issues Repository
Inline In Spec
Editors:
L. David Baron (Mozilla)
Florian Rivoal (On behalf of Bloomberg)
Elika J. Etemad / fantasai (Invited Expert)
Suggest an Edit for this Spec:
GitHub Editor

Abstract

This module contains the features of CSS relating to scrollable overflow handling in visual media. It builds on the CSS Overflow Module Level 3, defining line-clamp, its longhands, and its legacy pre-standard syntax; adding a block-ellipsis property; and expanding overflow-clip-margin with longhands. An appendix also contains a more experimental exploration of redirecting overflow by fragmentation.

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

Status of this document

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

This document was published by the CSS Working Group as a Working Draft using the Recommendation track. Publication as a Working Draft does not imply endorsement by W3C and its Members.

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.

Please send feedback by filing issues in GitHub (preferred), including the spec code “css-overflow” in the title, like this: “[css-overflow] …summary of comment…”. All issues and comments are archived. Alternately, feedback can be sent to the (archived) public mailing list [email protected].

This document is governed by the 2 November 2021 W3C Process Document.

This document was produced by a group operating under the 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.

1. Introduction

This specification extends [CSS-OVERFLOW-3]. It contains several primary sections:

Overflow Scrolling and Clipping Controls

This section defines relatively simple extensions to the overflow-* properties in Level 3.

Automatic Ellipses.

This section defines some experimental extensions to the *-ellipsis properties in Level 3.

Redirection of Overflow

This section definse a highly experimental, exploratory new model for handling overflow by redirecting it into newly-generated fragmentation containers.

Note: At the time of writing, [CSS-OVERFLOW-3] is not completely finalized yet. To avoid accidental divergences and maintenance overhead, This specification is written as a delta specification over css-overflow Level 3. Once the level 3 specification is final, its content will be integrated into this specification, which will then replace it. Until then, this specification only contains additions and extensions to level 3.

1.1. Value Definitions

This specification follows the CSS property definition conventions from [CSS2] using the value definition syntax from [CSS-VALUES-3]. Value types not defined in this specification are defined in CSS Values & Units [CSS-VALUES-3]. Combination with other CSS modules may expand the definitions of these value types.

In addition to the property-specific values listed in their definitions, all properties defined in this specification also accept the CSS-wide keywords as their property value. For readability they have not been repeated explicitly.

1.2. Module Interactions

This module extends features defined in [CSS-OVERFLOW-3].

2. Overflow Concepts and Terminology

Copy Level 3 content when final.

3. Scrolling and Clipping Overflow

Copy Level 3 content when final.

3.1. Managing Overflow: the overflow-x, overflow-y, and overflow properties

This level extends the overflow-x and overflow-y properties (and overflow shorthand) to apply to replaced elements.

On replaced elements, the used values of all computed values other than visible is clip. Host languages should define UA style sheet rules that apply a default value of clip to such elements and set their overflow-clip-margin to content-box.

Note: Application of overflow to replaced elements was added to allow images to paint effects outside their effective layout box; the recommended UA style sheet rules are to effect their original behavior as a default. See discussion in Issue 7059 and Issue 7144. This is a change from CSS2.1 and is at-risk.

Application of overflow to replaced elements is still being worked out. [Issue #7144]

3.2. Expanding Clipping Bounds: the overflow-clip-margin-* properties

Name: overflow-clip-margin-top, overflow-clip-margin-right, overflow-clip-margin-bottom, overflow-clip-margin-left, overflow-clip-margin-block-start, overflow-clip-margin-inline-start, overflow-clip-margin-block-end, overflow-clip-margin-inline-end
Value: <visual-box> || <length [0,∞]>
Initial: 0px
Applies to: boxes to which overflow applies
Inherited: no
Percentages: see individual properties
Computed value: the computed <length> and a <visual-box> keyword
Animation type: per computed value if the <visual-box> values match; otherwise discrete
Canonical order: per grammar
Logical property group: overflow-clip-margin
Name: overflow-clip-margin, overflow-clip-margin-inline, overflow-clip-margin-block
Value: <visual-box> || <length [0,∞]>
Initial: 0px
Applies to: boxes to which overflow applies
Inherited: no
Percentages: see individual properties
Computed value: see individual properties
Animation type: see individual properties
Canonical order: per grammar

These properties and their shorthands define the overflow clip edge of the box, i.e. precisely how far outside its bounds the box’s content is allowed to paint before being clipped by effects (such as overflow: clip, above) that are defined to clip to the box’s overflow clip edge. The shorthand/longhand relationships are as for margin, but note that the shorthands have a restricted syntax.

Values are defined as follows:

<visual-box>

Specifies the box edge to use as the overflow clip edge origin, i.e. when the specified offset is zero.

If omitted, defaults to padding-box on non-replaced elements, or content-box on replaced elements.

Application of overflow-clip-margin to replaced elements is still being worked out. [Issue #7144]

<length [0,∞]>

The specified offset dictates how much the overflow clip edge is expanded from the specified box edge Negative values are invalid. Defaults to zero if omitted.

The overflow clip edge is shaped in the corners exactly the same way as an outer box-shadow with a spread radius of the same cumulative offset from the box’s border edge. See CSS Backgrounds 3 § 4.2 Corner Shaping and CSS Backgrounds 3 § 6.1.1 Shadow Shape, Spread, and Knockout, noting in particular the formula for outsets beyond the border edge.

Note: This property has no effect on boxes with overflow: hidden or overflow: scroll, which are not defined to use the overflow clip edge.

4. Automatic Ellipses

4.1. Inline Overflow Ellipsis: the text-overflow property

Name: text-overflow
Value: [ clip | ellipsis | <string> | fade | <fade()> ]{1,2}
Initial: clip
Applies to: block containers
Inherited: no
Percentages: refer to the width of the line box
Computed value: as specified, with lengths made absolute
Canonical order: per grammar
Animation type: by computed value type

This section might need to be re-synced against [CSS-OVERFLOW-3].

This property specifies rendering when inline content overflows its line box edge in the inline progression direction of its block container element ("the block") that has overflow other than visible.

Even though this property is not inherited, anonymous block container boxes generated to establish the line box’s inline formatting context (see block container) are ignored, and the value of the property that applies is the one on the non anonymous box. This can be seen in the “nested paragraph” part of example 7: even though the word “NESTED” is wrapped in an anonymous block container whose text-overflow property has the initial value, it is ellipsed.

Text can overflow for example when it is prevented from wrapping (e.g. due to white-space: nowrap or a single word is too long to fit). Values have the following meanings:

clip
Clip inline content that overflows its block container element. Characters may be only partially rendered.
ellipsis
Render an ellipsis character (U+2026) to represent clipped inline content. Implementations may substitute a more language, script, or writing-mode appropriate ellipsis character, or three dots "..." if the ellipsis character is unavailable.
<string>
Render the given string to represent clipped inline content. The given string is treated as an independent paragraph for bidi purposes.
fade( [ <length> | <percentage> ] )
Clip inline content that overflows its line box. Characters may be only partially rendered. In addition, the UA must apply a fade out effect near the edge of the line box, reaching complete transparency at the edge.

Do we need to define the way the fade out is calculated so that the fading is identical across browsers? It should probably be something like mask-image: linear-gradient(to right, rgba(0,0,0,1), rgba(0,0,0,0)), except applied to the relevant portion of the line only.

The argument determines the distance over which the fade effect is applied. The <percentage> is resolved against the width of the line box. Values lower than 0 are clipped to 0. Values greater than the width of the line box are clipped to the width of the line box.

If the line box is too short to display the fade effect at the desired length, should we drop the effect, or shrink the distance it is applied over until it fits, or clip the end of the fade?

How should we deal with things overflowing out of the line box, or overlapping onto it? Should fade apply to the logical content of the line, or to the physical area of the line box, or the intersection of both?

fade
Same as fade(), but the distance over which the fading effect is applied is determined by the UA. 1em is suggested as a reasonable value.

The term "character" is used in this property definition for better readability and means "grapheme cluster" [UAX29] for implementation purposes.

If there is one value, it applies only to the end line box edge. If there are two values, the first value applies to the line-left edge, and the second value applies to the line-right edge. The terms end, line-left and line-right are defined in [CSS-WRITING-MODES-3].

Note: the use of line-left and line-right rather than start and end when there are two values is intentional, to facilitate the use of directional characters such as arrows.

For the ellipsis and string values, implementations must hide characters and atomic inline-level elements at the applicable edge(s) of the line as necessary to fit the ellipsis/string, and place the ellipsis/string immediately adjacent to the applicable edge(s) of the remaining inline content. The first character or atomic inline-level element on a line must be clipped rather than ellipsed.

Bidi ellipsis examples

These examples demonstrate which characters get hidden to make room for the ellipsis in a bidi situation: those visually at the edge of the line.

Sample CSS:

div {
  font-family: monospace;
  white-space: pre;
  overflow: hidden;
  width: 9ch;
  text-overflow: ellipsis;
}

Sample HTML fragments, renderings, and your browser:

HTML Reference rendering Your Browser
<div>שלום 123456</div>
123456 ם…
שלום 123456
<div dir=rtl>שלום 123456</div>
…456 שלום
שלום 123456

ellipsing details

user interaction with ellipsis

text-overflow examples

These examples demonstrate setting the text-overflow of a block container element that has text which overflows its dimensions:

sample CSS for a div:

div {
  font-family: Helvetica, sans-serif;
  line-height: 1.1;
  width: 3.1em;
  border: solid .1em black;
  padding: 0.2em; margin:1em 0;
}

sample HTML fragments, renderings, and your browser:

HTML sample rendering your browser
<div>
CSS IS AWESOME, YES
</div>
First, a box with text drawing outside of it.
CSS IS AWESOME, YES
<div style="text-overflow:clip; overflow:hidden">
CSS IS AWESOME, YES
</div>
Second, a similar box with the text clipped outside the box.
CSS IS AWESOME, YES
<div style="text-overflow:ellipsis; overflow:hidden">
CSS IS AWESOME, YES
</div>
Third, a similar box with an ellipsis representing the clipped text.
CSS IS AWESOME, YES
<div style="text-overflow:ellipsis; overflow:hidden">
NESTED
 <p>PARAGRAPH</p>
WON’T ELLIPSE.
</div>
Fourth, a box with a nested paragraph demonstrating anonymous block boxes equivalency and non-inheritance into a nested element.
NESTED

PARAGRAPH

WON’T ELLIPSE.
<div style="text-overflow:fade; overflow:hidden">
CSS IS AWESOME, YES
</div>
a box with the text fading out on overflow.
CSS IS AWESOME, YES

Note: the side of the line that the ellipsis is placed depends on the direction of the block. E.g. an overflow hidden right-to-left (direction: rtl) block clips inline content on the left side, thus would place a text-overflow ellipsis on the left to represent that clipped content.

insert RTL example diagram here to illustrate note.

ellipsis interaction with scrolling interfaces

This section applies to elements with text-overflow other than text-overflow:clip (non-clip text-overflow) and overflow:scroll.

When an element with non-clip text-overflow has overflow of scroll in the inline progression dimension of the text, and the browser provides a mechanism for scrolling (e.g. a scrollbar on the element, or a touch interface to swipe-scroll, etc.), there are additional implementation details that provide a better user experience:

When an element is scrolled (e.g. by the user, DOM manipulation), more of the element’s content is shown. The value of text-overflow should not affect whether more of the element’s content is shown or not. If a non-clip text-overflow is set, then as more content is scrolled into view, implementations should show whatever additional content fits, only truncating content which would otherwise be clipped (or is necessary to make room for the ellipsis/string), until the element is scrolled far enough to display the edge of the content at which point that content should be displayed rather than an ellipsis/string.

This example uses text-overflow on an element with overflow scroll to demonstrate the above described behavior.

sample CSS:

div.crawlbar {
  text-overflow: ellipsis;
  height: 2em;
  overflow: scroll;
  white-space: nowrap;
  width: 15em;
  border:1em solid black;
}

sample HTML fragment:

<div class="crawlbar">
CSS is awesome, especially when you can scroll
to see extra text instead of just
having it overlap other text by default.
</div>

demonstration of sample CSS and HTML:

CSS is awesome, especially when you can scroll to see extra text instead of just having it overlap other text by default.

As some content is scrolled into view, it is likely that other content may scroll out of view on the other side. If that content’s block container element is the same that’s doing the scrolling, and the computed value of text-overflow has two values, with the value applying to the start edge being a non-clip value, then implementations must render an ellipsis/string in place of the clipped content, with the same details as described in the value definition above, except that the ellipsis/string is drawn in the start (rather than end) of the block’s direction (per the direction property).

While the content is being scrolled, implementations may adjust their rendering of ellipses/strings (e.g. align to the box edges rather than line edges).

Same as previous example except with text-overflow: ellipsis ellipsis, demonstrated:
CSS is awesome, especially when you can scroll to see extra text instead of just having it overlap other text by default.

If there is insufficient space for both start and end ellipses/strings, then only the end ellipsis/string should be rendered.

4.2. Indicating Block-Axis Overflow: the block-ellipsis property

Name: block-ellipsis
Value: none | auto | <string>
Initial: none
Applies to: block containers
Inherited: yes
Percentages: N/A
Computed value: specified value
Canonical order: per grammar
Animation type: discrete

This property allows inserting content into the last line box before a (forced or unforced) region break to indicate the continuity of truncated/interrupted content. It only affects line boxes contained directly by the block container itself, but as it inherits, will have an effect on descendants’ line boxes unless overridden. If the box contains no line box immediately preceding a region break, then this property has no effect.

Note: See Appendix A: Redirection of Overflow for a way to generate boxes with such a region break.

Should this apply to other types of fragmentation breaks (e.g. pages, columns)?

The inserted content is called the block overflow ellipsis. Values have the following meanings:

none
The rendering is unaffected.
auto
Render an ellipsis character (U+2026)—or a more typographically-appropriate equivalent—as the block overflow ellipsis at the end of the affected line box. UAs should use the conventions of the content language, writing system, and writing mode to determine the most appropriate ellipsis string.
<string>
Render the specified string as the block overflow ellipsis at the end of the affected line box. The UA may truncate this string if it is absurdly long.

When block-ellipsis is not none, the block overflow ellipsis string is wrapped in an anonymous inline and placed at the end of the line box as a direct child of the block container’s root inline box, reducing the space in the line box available to the other contents of the line. This inline is assigned unicode-bidi: plaintext and line-height: 0 and is placed in the line box after the last soft wrap opportunity (see [CSS-TEXT-3]) that would still allow the entire block overflow ellipsis to fit on the line. For this purpose, soft wrap opportunities added by overflow-wrap are ignored. If this results in the entire contents of the line box being displaced, the line box is considered to contain a strut, as defined in CSS 2.1 § 10.8.1 Leading and half-leading. Text alignment and justification occurs after placement, and measures the inserted block overflow ellipsis together with the rest of the line’s content.

Note: Setting the block overflow ellipsis's line-height to 0 makes sure that inserting it cannot cause the line’s height to grow, which could cause further relayouts and potentially cycles. This is almost equivalent to inserting the block overflow ellipsis as a paint-time operation, except that it still participates in alignment and justification. The downside is that unusually tall / deep glyphs in the block overflow ellipsis may overflow.

The block overflow ellipsis must not be included in either the ::first-letter nor the ::first-line pseudo-elements.

If there is a subsequent fragmentation container in the fragmentation context that would receive subsequent content, then the content displaced by the block overflow ellipsis must be pushed to that fragmentation container.

The UA must treat the block overflow ellipsis as an unbreakable string, If any part of the block overflow ellipsis overflows, it is treated as scrollable overflow, and its rendering is affected by the text-overflow property.

The block overflow ellipsis does not capture events: pointer events are dispatched to whatever is underneath it.

It also has no effect on the intrinsic size of the box: its min-content and max-content sizes are calculated exactly as if block-ellipsis were none.

Note: Future specifications may extend this feature, for example by providing an ::ellipsis pseudo-element to style the text, or by allowing the selection of a child element of the block to use as either an inline-level or block-level indicator (in which case, it can capture events).

5. Fragmenting Overflow

5.1. Limiting Visible Lines: the line-clamp shorthand property

Name: line-clamp
Value: none | <integer [1,∞]> <'block-ellipsis'>?
Initial: none
Applies to: see individual properties
Inherited: see individual properties
Percentages: N/A
Computed value: see individual properties
Animation type: see individual properties
Canonical order: per grammar

The line-clamp property is a shorthand for the max-lines, block-ellipsis, and continue properties.

For the time being, experimental implementations are encouraged to follow the full behavior defined by this shorthand and its longhands, but to only expose the shorthand to authors. This is in order to facilitate further tweaking, and in particular potential renaming, of the longhand properties and their values.

It allows limiting the contents of a block container to the specified number of lines; remaining content is fragmented away and neither rendered nor measured. Optionally, it also allows inserting content into the last line box to indicate the continuity of truncated/interrupted content.

The values have the following meaning:

none
Sets max-lines to none, continue to auto, and block-ellipsis to none.
<integer [1,∞]> <block-ellipsis>?
Sets max-lines to the specified <integer>, continue to discard, and the block-ellipsis property to second component of the value or to auto if omitted.

See the corresponding longhand properties for details about how this mechanism operates.

In this example, the lead paragraph of each article is listed in a shortened menu, truncated to fit within 5 lines that end with “… (continued on next page)”:
li {
  line-clamp: 5 "… (continued on next page)";
}
strong {
  display: block;
  text-transform: uppercase;
}
<li><a href="cheese-is-milk">
  <strong>Cheese is Actually Made of Milk!</strong>
  Investigative reporters at the World Wide Web Press Corps
  have discovered the secret of cheese.
  Tracing through byzantine layers of bureaucracy and shadow corporations,
  our crack team of journalists have traced the source of camembert.
</a></li>

Sample rendering:

+---------------------------------------+
| CHEESE IS ACTUALLY MADE OF MILK!      |
| Investigative reporters at the World  |
| Wide Web Press Corps have discovered  |
| the secret of cheese. Tracing through |
| byzantine…  (continued on next page)  |
+---------------------------------------+

5.1.1. Legacy compatibility

For compatibility with legacy content, UAs that support line-clamp must also support the -webkit-line-clamp property and the additional -webkit-discard value for the continue property.

Name: -webkit-line-clamp
Value: none | <integer [1,∞]>
Initial: none
Applies to: see individual properties
Inherited: see individual properties
Percentages: N/A
Computed value: see individual properties
Animation type: see individual properties
Canonical order: per grammar
Name: continue
New values: -webkit-discard

Like line-clamp, -webkit-line-clamp is a shorthand of max-lines, continue, and block-ellipsis, except that:

Additionally, for children (including anonymous children) of boxes whose display property computes to -webkit-box or -webkit-inline-box, the used values of the max-lines, continue, and block-ellipsis properties are taken from the computed values of the parent box; the computed values of these properties on the box itself are ignored.

The -webkit-discard value behaves identically to discard, except that it only takes effect if the computed value of the display property on the parent is -webkit-box or -webkit-inline-box and the computed value of the -webkit-box-orient property on the parent is vertical.

Note: Implementations of the legacy -webkit-line-clamp property have not behaved identically to what is specified here. The historical behavior is quirky and less robust, as documented for example in this blog post. The current design learns from the mistakes of that early experiment, and is intended to be sufficiently compatible with existing content that implementations can eventually be changed to follow to the specified behavior. If further adjustments are found to be necessary, they will be incorporated to this specification. In the meanwhile, authors should be aware that there may be discrepancies.

5.2. Forcing a Break After a Set Number of Lines: the max-lines property

Name: max-lines
Value: none | <integer [1,∞]>
Initial: none
Applies to: block containers which are also fragmentation containers that capture region breaks
Inherited: no
Percentages: N/A
Computed value: the keyword none or an integer
Canonical order: per grammar
Animation type: by computed value type

This property has no effect on boxes that are not fragmentation containers that capture region breaks.

Otherwise, if the value of max-lines is not none, a region break is forced after its Nth descendant in-flow line box, where N is the specified value of max-lines. Only lines boxes in the same Block Formatting Context are counted: the contents of descendants that establish independent formatting contexts are skipped over while counting line boxes.

If fewer than N line boxes exist, then max-lines introduces no region break.

As continue: discard does not cause the element to establish an independent formatting context, lines in a nested element with line-clamp are counted, as can be seen in the examples below.
<div id=a>
  a: line 1<br>
  a: line 2<br>
  <div id=b>
    b: line 1<br>
    b: line 2<br>
    b: line 3<br>
    b: line 4<br>
  </div>
  a: line 3<br>
  a: line 4<br>
</div>

Sample rendering given #a { line-clamp: 5; } #b { line-clamp: 2; }:

a: line 1
a: line 2
b: line 1
b: line 2…
a: line 3…

Sample rendering given #a { line-clamp: 3; } #b { line-clamp: 2; }:

a: line 1
a: line 2
b: line 1…

Note that in the second case, the maximum of 2 lines set on element #b does not take effect, since a forced break is introduced before the second line of this element.

Note: This implies that max-lines has no effect when applied to multi-column containers, since any line box they contain are nested into independent formatting contexts.

Only positive integers are accepted. Zero or negative integers are invalid and must cause the declaration to be ignored.

Note: The widows, orphans, and break-inside properties do not affect the position of the forced region break introduced by the max-lines property.

Note: Despite the “region break” name, this is not a dependency on [CSS-REGIONS-1]. The word “region” is only used as a classifier for forced breaks: they can be “page breaks” (breaks across pages [css-page-3]), “column breaks” (breaks across multi-column layout columns [css-multicol-1]), or “region breaks” (breaks across any other kind of CSS-induced fragmentation containers).

If an implementation supports neither [CSS-REGIONS-1] nor CSS Overflow 4 § 5 Redirection of Overflow, then it will have had no occasion yet to run into that kind of breaks, and this will be an addition. However the addition does not involve bringing over any of the [CSS-REGIONS-1] functionality. All that is needed is:

5.3. Fragmentation of Overflow: the continue property

Name: continue
Value: auto | discard
Initial: auto
Applies to: block containers and multicol containers
Inherited: no
Percentages: N/A
Computed value: specified keyword
Canonical order: per grammar
Animation type: discrete

The continue property gives authors the ability to turn a box into a fragmentation container (see [CSS-BREAK-3]) and to specify that content after the fragmentation break must be discarded.

This property is meant to generalize and replace the region-fragment property from [CSS-REGIONS-1]. Once it is sufficiently stable in this specification, region-fragment should be removed from the regions specification in favor of this.

auto

If the box has more content than can fit, the excess content is handled according to the usual rules.

discard
The box becomes a fragmentation container that captures region breaks, if it is not already. [CSS-BREAK-3] Content after the first region break is not rendered (see below). (If the box is a multi-column container, any overflow columns are also not rendered.)

Note: This region break might be forced (e.g. imposed by max-lines or by another mechanism, such as the break-before/break-after properties) or unforced (e.g. if the content would otherwise overflow this fragmentation container due to its size constraints). Breaks applying to other fragmentation contexts (such as pagination of this box itself) do not cause any content to be discarded.

Note: This property does not cause the box to establish an independent formatting context.

Given an article with one excessively long overflowing line, and four more lines than can fit in the fragmentation direction as in the illustration bellow, different renderings are possible based on the combination of the overflow and continue property.
article with one excessively long line and four more that can fit in the block direction
continue: discard continue: auto
overflow: visible rendering with continue:discard and overflow:visible rendering with continue:auto and overflow:visible
overflow: hidden rendering with continue:discard and overflow:hidden rendering with continue:auto and overflow:hidden

Content that is “not rendered” due to continue: discard is discarded, similar to display: none:

However, since intrinsic sizes are calculated across fragmentation containers, this content is taken into account for the purpose of finding the box’s min-content and max-content inline sizes (see CSS Fragmentation 3 § 5.1 Breaking into Varying-size Fragmentainers). Min-content and max-content block sizes are calculated based on the content from the start of the fragmented flow to the first forced break if any, or to the end of the fragmented flow if there is no forced break.

Note: In the case of parallel fragmentation flows, content occurring after the fragmentation break in the box tree could still be rendered, if it is laid out above the position representing the end of this fragmentation container.

Appendix A: Redirection of Overflow

This section is highly experimental. It documents current attempts at extending the capabilities of the continue property to solve additional use cases. However, it does not currently have consensus. It is presented here to encourage discussion, but non-experimental implementation is not recommended.

In CSS Level 1 [CSS1], placing more content than would fit inside an element with a specified size was generally an authoring error. Doing so caused the content to extend outside the bounds of the element, which would likely cause that content to overlap with other elements.

CSS Level 2 [CSS2] introduced the overflow property, which allows authors to have overflow be handled by scrolling, which means it is no longer an authoring error. It also allows authors to specify that overflow is handled by clipping, which makes sense when the author’s intent is that the content not be shown. This was further refined in the CSS Overflow Module Level 3 [CSS-OVERFLOW-3].

However, scrolling is not the only way to present large amounts of content, and may even not be the optimal way. After all, the codex replaced the scroll as the common format for large written works because of its advantages.

This specification introduces a mechanism for Web pages to specify that an element of a page should handle overflow through pagination rather than through scrolling.

This specification also extends the concept of overflow in another direction. Instead of requiring that authors specify a single area into which the content of an element must flow, this specification allows authors to specify multiple fragments, each with their own dimensions and styles, so that the content of the element can flow from one to the next, using as many as needed to place the content without overflowing.

In both of these cases, implementations must break the content in the block-progression dimension. Implementations must do this is described in the CSS Fragmentation Module [CSS-BREAK-3].

Channeling Overflow: the continue property

The continue property gives authors the ability to request that content that does not fit inside an element be fragmented (in the sense of [CSS-BREAK-3]), and provides alternatives for where the remaining content should continue.

Notably, this property explains traditional pagination, and extends it further.

Name: continue
New values: overflow | paginate | fragments
Initial: auto
Applies to: block containers [CSS2], flex containers [CSS3-FLEXBOX], and grid containers [CSS3-GRID-LAYOUT]
Inherited: no
Percentages: N/A
Computed value: see below
Animation type: discrete

The naming of this property and its values is preliminary. This was initially proposed as "fragmentation: auto | none | break | clone | page" in https://lists.w3.org/Archives/Public/www-style/2015Jan/0357.html, and there is not yet wide agreement as to which naming is better.

This property is meant to generalize and replace region-fragment. Once it is sufficiently stable in this specification, region-fragment should be removed from the regions specification in favor of this.

Note: continue: fragments replaces "overflow:fragments" from earlier versions of this specification, while continue: paginate replaces "overflow: paged-x | paged-y | paged-x-controls | paged-y-controls"

auto
auto may only occur as a computed value if the element is a CSS Region other than the last one in a region chain. Content that doesn’t fit is pushed to the next region of the chain.

In all other cases, auto computes to one of the other values.

this is different from the definition in § 5.3 Fragmentation of Overflow: the continue property, where the specified value is the computed value. Which is model better?

overflow
Content that doesn’t fit overflows, according to the overflow property
paginate
Content that doesn’t fit paginates. This creates a paginated view inside the element similar to the way that 'overflow: scroll' creates a scrollable view.

See paginated overflow

Note: Print is effectively "continue: paginate" on the root.

fragments
content that doesn’t fit causes the element to copy itself and continue laying out.

See fragment overflow.

The computed value of the continue for a given element or pseudo element is determined as follow:

  1. On elements or pseudo elements with layout containment (see [CSS-CONTAIN-1]), if the specified value is auto or fragments then the computed value is overflow.
  2. Otherwise, if the specified value is auto
    1. On a CSS Region other than the last one in a region chain, the computed value is auto
    2. On a page the computed value is paginate
    3. On a fragment box the computed value is fragments
    4. Otherwise, the computed value is overflow
  3. Otherwise, if the specified value is fragments
    1. On a page the computed value is paginate
    2. Otherwise, the computed value is the specified value
  4. In all other cases, the computed value is the specified value

If we introduce a pseudo element that can select columns in a multicol, we would need to specify that auto computes to auto on it, or introduce a new value and have auto compute to that (but what would that value compute to on things that aren’t columns?).

Note: For background discussions leading to this property, see these threads: discussion of overflow, overflow-x, overflow-y and overflow-style and proposal for a fragmentation property

Paginated overflow

This section introduces and defines the meaning of the paginate value of the continue property.

Write this section

Pages should be possible to style with @page rules. How does that work for nested pages?

Should traditional pagination (e.g. when printing) be expressed through some magic in the computed value of auto, or by inserting this in the UA stylesheet:
@media (overflow-block: paged), (overflow-block: optional-paged) {
  :root {
    continue: paginate;
  }
}

Traditional pagination (e.g. when printing) assumes that :root is contained in the page box, rather than having the page box be a pseudo element child of :root. Can we work around that using something similar to fragment boxes? Or maybe by having a fragment box (reproducing :root) inside a page box inside :root?

How does the page box model work when it is a child of a regular css box?

The initial proposal in [CSS3GCPM] and implementation from Opera used 4 values instead of paginate: "paged-x | paged-y | paged-x-controls | paged-y-controls". Should this property also include these values, or are they better handled as separate properties? (e.g.: "pagination-layout: auto | horizontal | vertical", "pagination-controls: auto | none")

Ability to display N pages at once rather than just one page at once? Could this be a value of "pagination-layout", such as: "pagination-layout: horizontal 2;"

Brad Kemper has proposed a model for combining pagination and fragment overflow, which also deals with displaying multiple pages. https://www.w3.org/mid/[email protected]

The current implementation of paginated overflow uses the overflow/overflow-x/overflow-y properties rather than the overflow-style property as proposed in the [CSS3GCPM] draft (which also matches the [CSS3-MARQUEE] proposal). or the continue property as described here.

Fragmented Overflow

This section introduces and defines the meaning of the fragments value of the continue property.

When the computed value of continue for an element is fragments, and implementations would otherwise have created a box for the element, then implementations must create a sequence of fragment boxes for that element. (It is possible for an element with continue: fragments to generate only one fragment box. However, if an element’s computed continue is not fragments, then its box is not a fragment box.) Every fragment box is a fragmentation container, and any overflow that would cause that fragmentation container to fragment causes another fragment box created as a next sibling of the previous one. Or is it as though it’s a next sibling of the element? Need to figure out exactly how this interacts with other box-level fixup. Additionally, if the fragment box is also a multi-column box (as defined in [css-multicol-1] though it defines multi-column container) any content that would lead to the creation of overflow columns [css-multicol-1] instead is flown into an additional fragment box. However, fragment boxes may themselves be broken (due to fragmentation in a fragmentation context outside of them, such as pages, columns, or other fragment boxes); such breaking leads to fragments of the same fragment box rather than multiple fragment boxes. (This matters because fragment boxes may be styled by their index; such breaking leads to multiple fragments of a fragment box with a single index. This design choice is so that breaking a fragment box across pages does not break the association of indices to particular pieces of content.) Should a forced break that breaks to an outer fragmentation context cause a new fragment of a single fragment box or a new fragment box? Should we find a term other than fragment box here to make this a little less confusing?

What if we want to be able to style the pieces of an element split within another type of fragmentation context? These rules prevent ever using ::nth-fragment() for that, despite that the name seems the most logical name for such a feature.

<!DOCTYPE HTML><title>Breaking content into
  equal-sized cards</title>
<style>
  .in-cards {
    continue: fragments;

    width: 13em;
    height: 8em;

    padding: 4px;
    border: medium solid blue;
    margin: 6px;

    font: medium/1.3 Times New
      Roman, Times, serif;
  }
</style>
<div class="in-cards">
  In this example, the text in the div
  is broken into a series of cards.
  These cards all have the same style.
  The presence of enough content to
  overflow one of the cards causes
  another one to be created.  The second
  card is created just like it’s the
  next sibling of the first.
</div>
In this example, the text in the
div is broken into a series of
cards. These cards all have the
same style. The presence of
enough content to overflow
one of the cards causes another
one to be created. The second
card is created just like it’s the
next sibling of the first.
Authors may wish to style the opening lines of an element with different styles by putting those opening lines in a separate fragment. However, since it may be difficult to predict the exact height occupied by those lines in order to restrict the first fragment to that height, it is more convenient to use the max-lines property, which forces a fragment to break after a specified number of lines. This forces a break after the given number of lines contained within the element or its descendants, as long as those lines are in the same block formatting context.
<!DOCTYPE HTML><style>
  .article {
    continue: fragments;
  }
  .article::first-letter {
    font-size: 2em;
    line-height: 0.9;
  }
  .article::nth-fragment(1) {
    font-size: 1.5em;
    max-lines: 3;
  }
  .article::nth-fragment(2) {
    column-count: 2;
  }
</style>
<div class="article">
  ...
</div>
The max-lines property allows
authors to use a larger font for the first
few lines of an article. Without the
max-lines property, authors
might have to use the
height property instead, but
that would leave a slight gap
if the author miscalculated
how much height a given
number of lines would
occupy (which might be
particularly hard if the author
didn’t know what text would
be filling the space, exactly
what font would be used, or
exactly which platform’s font
rendering would be used to
display the font).

We should specify that continue: fragments does not apply to at least some table parts, and perhaps other elements as well. We need to determine exactly which ones.

This specification needs to say which type of fragmentation context is created so that it’s clear which values of the break-* properties cause breaks within this context. We probably want break-*: region to apply.

This specification needs a processing model that will apply in cases where the layout containing the fragments has characteristics that use the intrinsic size of the fragments to change the amount of space available for them, such as [CSS3-GRID-LAYOUT]. There has already been some work on such a processing model in [CSS-REGIONS-1], and the work done on a model there, and the editors of that specification, should inform what happens in this specification.

Fragment styling

The ::nth-fragment() pseudo-element

The ::nth-fragment() pseudo-element is a pseudo-element that describes some of the fragment boxes generated by an element. The argument to the pseudo-element takes the same syntax as the argument to the :nth-child() pseudo-class defined in [SELECT], and has the same meaning except that the number is relative to fragment boxes generated by the element instead of siblings of the element.

Selectors that allow addressing fragments by counting from the end rather than the start are intentionally not provided. Such selectors would interfere with determining the number of fragments.

Depending on future discussions, this ::nth-fragment(an+b) syntax may be replaced with the new ::fragment:nth(an+b) syntax.

Styling of fragments

Should this apply to continue:fragments only, or also to continue:paginate? (If it applies, then stricter property restrictions would be needed for continue:paginate.)

In the absence of rules with ::nth-fragment() pseudo-elements, the computed style for each fragment box is the computed style for the element for which the fragment box was created. However, the style for a fragment box is also influenced by rules whose selector’s subject [SELECT] has an ::nth-fragment() pseudo-element, if the 1-based number of the fragment box matches that ::nth-fragment() pseudo-element and the selector (excluding the ::nth-fragment() pseudo-element) matches the element generating the fragments.

When determining the style of the fragment box, these rules that match the fragment pseudo-element cascade together with the rules that match the element, with the fragment pseudo-element adding the specificity of a pseudo-class to the specificity calculation. Does this need to be specified in the cascading module as well?

<!DOCTYPE HTML><style>
  .bouncy-columns {
    continue: fragments;
    width: 6em;
    height: 10em;
    float: left;
    margin: 1em;
    font: medium/1.25 Times New
      Roman, Times, serif;
  }
  .bouncy-columns::nth-fragment(1) {
    background: aqua; color: black;
    transform: rotate(-3deg);
  }
  .bouncy-columns::nth-fragment(2) {
    background: yellow; color: black;
    transform: rotate(3deg);
  }
</style>
<div class="bouncy-columns">
  ...
</div>
In this
example, the
text in the div
is broken into
a series of
columns. The
author
probably
intended the
text to fill two
columns. But
if it happens to
fill three
columns, the
third column is
still created. It
just doesn’t
have any
fragment-specific
styling because
the author
didn’t give it
any.

Styling an ::nth-fragment() pseudo-element with the continue property does take effect; if a fragment box has a computed value of continue other than fragments then that fragment box is the last fragment. However, overriding continue on the first fragment does not cause the fragment box not to exist; whether there are fragment boxes at all is determined by the computed value of overflow for the element.

Styling an ::nth-fragment() pseudo-element with the content property has no effect; the computed value of content for the fragment box remains the same as the computed value of content for the element.

Specifying display: none for a fragment box causes the fragment box with that index not to be generated. However, in terms of the indices used for matching ::nth-fragment() pseudo-elements of later fragment boxes, it still counts as though it was generated. However, since it is not generated, it does not contain any content.

Specifying other values of display, position, or float is permitted, but is not allowed to change the inner display type. (Since continue only applies to block containers, flex containers, and grid containers). Need to specify exactly how this works

To match the model for other pseudo-elements where the pseudo-elements live inside their corresponding element, declarations in ::nth-fragment() pseudo-elements override declarations in rules without the pseudo-element. The relative priority within such declarations is determined by normal cascading order (see [CSS2]).

Styles specified on ::nth-fragment() pseudo-elements do affect inheritance to content within the fragment box. In other words, the content within the fragment box must inherit from the fragment box’s style (i.e., the pseudo-element style) rather than directly from the element. This means that elements split between fragment boxes may have different styles for different parts of the element.

This inheritance rule allows specifying styles indirectly (by using explicit inherit or using default inheritance on properties that don’t apply to ::first-letter) that can’t be specified directly (based on the rules in the next section). This is a problem. The restrictions that apply to styling inside fragments should also apply to inheritance from fragments.

<!DOCTYPE HTML><style>
  .article {
    continue: fragments;
  }
  .article::nth-fragment(1) {
    font-size: 1.5em;
    margin-bottom: 1em;
    height: 4em;
  }
  .article::nth-fragment(2) {
    margin-left: 5em;
    margin-right: 2em;
  }
</style>
<div class="article">
  The <code>font-size</code> property...
</div>
The font-size property
specified on the fragment
is inherited into the
descendants of the fragment.
This means that inherited
properties can be used
reliably on a fragment, as in
this example.

Styling inside fragments

Should this apply to continue:fragments only, or also to continue:paginate?

The ::nth-fragment() pseudo-element can also be used to style content inside of a fragment box. Unlike the ::first-line and ::first-letter pseudo-elements, the ::nth-fragment() pseudo-element can be applied to parts of the selector other than the subject: in particular, it can match ancestors of the subject. However, the only CSS properties applied by rules with such selectors are those that apply to the ::first-letter pseudo-element.

To be more precise, when a rule’s selector has ::nth-fragment() pseudo-elements attached to parts of the selector other than the subject, the declarations in that rule apply to a fragment (or pseudo-element thereof) when:

  1. the declarations are for properties that apply to the ::first-letter pseudo-element,
  2. the declarations would apply to that fragment (or pseudo-element thereof) had those ::nth-fragment() pseudo-elements been removed, with a particular association between each sequence of simple selectors and the element it matched, and
  3. for each removed ::nth-fragment() pseudo-element, the fragment lives within a fragment box of the element associated in that association with the selector that the pseudo-element was attached to, and whose index matches the pseudo-element.
<!DOCTYPE HTML><style>
  .dark-columns {
    continue: fragments;
    width: 6em;
    height: 10em;
    float: left;
    margin-right: 1em;
    font: medium/1.25 Times New
      Roman, Times, serif;
  }
  .dark-columns::nth-fragment(1) {
    background: aqua; color: black;
  }
  .dark-columns::nth-fragment(1) :link {
    color: blue;
  }
  .dark-columns::nth-fragment(1) :visited {
    color: purple;
  }
  .dark-columns::nth-fragment(2) {
    background: navy; color: white;
  }
  .dark-columns::nth-fragment(2) :link {
    color: aqua;
  }
  .dark-columns::nth-fragment(2) :visited {
    color: fuchsia;
  }
</style>
<div class="dark-columns">
  ...
</div>
In this
example, the
text flows
from one
light-colored
fragment into
another
dark-colored
fragment. We
therefore want
different styles
for hyperlinks
in the different
fragments.

Appendix B: Possible extensions for scrollbar-gutter

This section is non-normative.

This section documents current attempts at extending the scrollbar-gutter property to solve additional use cases. However, it does not currently have consensus. It is presented here to encourage discussion, but non-experimental implementation is not recommended.

This example exercises all the additional values of the scrollbar-gutter property:
With classic scrollbars
With overlay scrollbars
Name: scrollbar-gutter
New values: auto | [ [ stable | always ] && both-edges? && force? ] || match-parent
Applies to: all elements

For overlay scrollbars, the precise width of the scrollbar gutter, if present, is UA defined. However, it must not be 0, and it must not change based on user interactions with the page or the scrollbar even if the scrollbar itself changes, with the expectation that it covers the width of the overlay scrollbar in its widest form, to the extent that this is well defined.

The new values of this property have the following meaning:

always
The scrollbar gutter is always present when overflow is scroll, hidden, or auto, regardless of the type of scrollbar or of whether the box is overflowing.
scrollbar-gutter: always can be bused to solve the problem of (small) interactive elements near the edge of the element getting covered by an appearing overlay scrollbar. A representative case would be a basic todo list, with each line starting with some text and ending with a right-aligned checkbox. With a classic scrollbar, everything is fine, but an overlay scrollbar could obscure the check boxes and make them hard to interact with.
Checkboxes adjacent to a classic scrollbar

					A scrollable todo list with checkboxes on the right edge,
					adjecent to the scrollbar.
					This situation poses no particular problem.
Checkboxes and an overlay scrollbar classic scrollbar

					A scrollable todo list with checkboxes on the right edge.
					When the overlay scrollbar is hidden,
					the situation poses no particular problem,
					but when it pops in,
					it covers the checkboxes,
					getting in the way of interacting with them.

Overlay Scrollbar are typically transient and disappear when not interacted with, so the checkboxes they cover are not impossible to use. But when the scrollbar is shown it does get in the way, and that makes for an awkward interaction. The author might try and solve the problem by adding some right padding, but (1) how much?, and (2) that padding isn’t needed in the case of classic scrollbars. scrollbar-gutter: always solves this problem, yielding an identical result in first case of classic scrollbars, but adding the desired gutter with overlay scrollbars:

Checkboxes and an overlay scrollbar and scrollbar-gutter: always

					A scrollable todo list with checkboxes on the right edge,
					shifted left by a gutter.
					Whether the overlay scrollbar is hidden or visible,
					the checkboxes remain uncovered,
					and can be interacted with.
Apple is reluctant to add this value, as authors may use it too broadly, inserting gutters with overlay scrollbars even when not justified by interactive elements, defeating the space-saving advantage of overlay scrollbars.

An alternative solution has been suggested: as the focus is interactive elements, maybe we could have a property that applies to the elements that needs to avoid being under the scrollbar. When turned on, it would enlarge the right or left margin of the element as appropriate by just the right value to push it out from under an overlay scrollbar if that’s where it would end up, but would leave the element unchanged otherwise.

Possibly, an addition toggle would cause the element to enlarge both its inline-end and inline-start margins or neither, rather than just one. This could typically be useful for block-level descendants of the scroller with visible borders or background: adding space on one side to avoid collisions with the overlay scrollbar would make them look off-center when the scrollbar disapears. Increasing the margin on both sides avoids that.

Yet another possibility is to have a choice between growing the margin to protect the element, or growing the padding to protect the element’s content.

The syntax could be something like scrollbar-avoid: none | [self | content] && both-edges?.

An interesting consideration is that this may alleviate the need for scrollbar-gutter: match-parent, as it seems that situations that would have been addressed by scrollbar-gutter: stable or scrollbar-gutter: always on the parent and scrollbar-gutter: match-parent on the select children could instead be addressed by leaving the parent as scrollbar-gutter: auto and using scrollbar-avoid: self or scrollbar-avoid: content on the relevant children.

force
When the force keyword is present stable and always take effect when overflow is visible, hidden or clip in addition auto or scroll. This does not cause a scrollbar to be displayed, only a scrollbar gutter.
This value enables authors to reserve the same amount of space on the edges of an element that is adjacent to a scroller as is being reserved in the scroller itself, so that their content would visually line up. The same effect could be achieved by adding padding for classic scrollbars and none for overlay scrollbars, but without this there is no reliable way for authors to know if they should be adding that padding, and if so how much.

A concrete example can be seen (at the time of writing) in the UI of Gmail: it attempts, not always successfully, to line up the controls in the toolbar above the list of mails with those in the list of mails. Here are two screenshots, one with classic scrollbars turned on (at the OS level), where Gmail correctly guesses how much padding it should be adding to the toolbar above the list, and one with overlay scrollbars turned on, where Gmail incorrectly adds padding, throwing things out of alignment (orange dotted line added manually to highlight the point under discussion).

The Gmail UI with classic scrollbars

				Icons in and out of the scroller are properly aligned:
				those in the scroller are shifted left from the right edge of their container due to the scrollbar
				while those outside of it are shifted left by the same amount through padding.
The Gmail UI with overlay scrollbars

				Icons in and out of the scroller are not aligned:
				those in the scroller are flush to the right edge of the container
				while those outside of it are shifted left due to unnecessary padding.

Creating this spacing in the toolbar using scrollbar-gutter: stable force rather than padding would keep icons in alignment in both cases, as well as on systems where the scrollbar has an atypical size.

It is because of this value that the property has been be made to apply to all elements, rather than merely to scroll containers, so that it can apply to overflow: visible elements as shown in the example. This could pause implementations difficulties, as user agents cannot just rely on existing code to place the gutter, since they may have to do so on elements which previously could not have one. Restricting it to all elements where overflow applies would probably have no negative effect on use cases and could make implementation easier; however, even that may still be more difficult that limiting it to scroll containers.

In addition to the implementation challenges mentioned above, it is not clear that this value solves the problem as reliably as it intends to. As the size and side of the scrollbar and its gutter are UA defined, they may vary between different elements. Since the appearance and position of scrollbars are up to the user agent, there is no limit to the list of properties that might influence them. It is probable that setting properties such as direction (via setting the HTML dir attribute) or scrollbar-width could give enough context to the user agent to know how it would create a scrollbar on that element if it were scrollable, and therefore to create a gutter of the same size at the right place, but it cannot be guaranteed.

In early iterations of the specification, this value was the only way to achieve the effect described in the example. However, since then, scrollbar-gutter: stable has been made to apply to overflow: hidden elements. While applying overflow: hidden has other effects which may be undesirable in that context, the combination of scrollbar-gutter: stable and overflow: hidden does add spacing in the same way as scrollbar-gutter: stable force, and may prove to be a sufficient workaround, particularly considering the other issues described above.

match-parent
On a block-level box whose parent has a scrollbar gutter (or gutters on both edges), this causes the box to have scrollbar gutter on the same side(s) and of the same width as its parent’s gutter(s). Moreover, that gutter is made to overlap that of the parent box.
The gutter of a <fake-maybe-placeholder bs-autolink-syntax='''scrollbar-gutter: match-parent'''>scrollbar-gutter: match-parent</fake-maybe-placeholder> box overlaps with that of its parent.

If the box with scrollbar-gutter: match-parent has a non-zero border or margin on the side where the gutter is expected, then the size of that box’s gutter is parent.gutter - child.border - child.margin, and the gutter+border+margin is what collapses with the parent’s gutter.

If the box with scrollbar-gutter/ match-parent is itself a scroll container, depending on the type of scrollbars, on its overflow property, and on the other values of the scrollbar-gutter property, it may need additional gutter for its own scrollbars. This comes in addition to the amount of gutter added for the sake of the match-parent value and does not collapse with the parent’s gutter.

A scroller with an child whose background intrudes into the gutter, thanks to match-parent
A match-parent box inside a scroll container with classic scrollbars, overflow: auto, and scrollbar-gutter: stable
The background of the match-parent element is visible in the gutter when the scrollbar isn’t there.
A scrollable box with match-parent inside another scroll container
The element has a double gutter, one for its own scrollbar, one to match its parent’s.
A scrollable box with match-parent inside another scroll container, with bidi
The element has a two gutters, one for its own scrollbar, one to match its parent’s, on opposite sides.
A scrollable box with scrollbar-gutter:match-parent stable inside another scroll container, with bidi
The element has a two gutters, one for its own scrollbar (not shown, as it’s not overflowing), one to match its parent’s, on opposite sides.
Note: The following table summarizes the interaction of overflow and scrollbar-gutter for different types of scrollbars, showing in which case space is reserved for the scrollbar gutter.
Should space be reserved for the scrollbar gutter?
overflow scrollbar-gutter Classic scrollbars Overlay scrollbars (whether overflowing or not)
Overflowing Not overflowing
scroll auto yes yes
stable yes yes
always yes yes yes
auto auto yes
stable yes yes
always yes yes yes
hidden auto
stable yes yes
always yes yes yes
visible, clip auto
stable if force if force
always if force if force if force

Appendix C: Privacy Considerations

This specification introduces no new privacy considerations.

Appendix D: Security Considerations

This specification introduces no new security considerations.

Changes

Recent Changes

Significant changes since the June 2017 Working Draft include:

Changes Since Level 3

TBD

Acknowledgments

Thanks especially to the feedback from Rossen Atanassov, Bert Bos, Tantek Çelik, John Daggett, fantasai, Daniel Glazman, Vincent Hardy, Håkon Wium Lie, Peter Linss, Robert O’Callahan, Florian Rivoal, Alan Stearns, Steve Zilles, and all the rest of the www-style community.

Conformance

Document conventions

Conformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology. The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in the normative parts of this document are to be interpreted as described in RFC 2119. However, for readability, these words do not appear in all uppercase letters in this specification.

All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. [RFC2119]

Examples in this specification are introduced with the words “for example” or are set apart from the normative text with class="example", like this:

This is an example of an informative example.

Informative notes begin with the word “Note” and are set apart from the normative text with class="note", like this:

Note, this is an informative note.

Advisements are normative sections styled to evoke special attention and are set apart from other normative text with <strong class="advisement">, like this: UAs MUST provide an accessible alternative.

Conformance classes

Conformance to this specification is defined for three conformance classes:

style sheet
A CSS style sheet.
renderer
A UA that interprets the semantics of a style sheet and renders documents that use them.
authoring tool
A UA that writes a style sheet.

A style sheet is conformant to this specification if all of its statements that use syntax defined in this module are valid according to the generic CSS grammar and the individual grammars of each feature defined in this module.

A renderer is conformant to this specification if, in addition to interpreting the style sheet as defined by the appropriate specifications, it supports all the features defined by this specification by parsing them correctly and rendering the document accordingly. However, the inability of a UA to correctly render a document due to limitations of the device does not make the UA non-conformant. (For example, a UA is not required to render color on a monochrome monitor.)

An authoring tool is conformant to this specification if it writes style sheets that are syntactically correct according to the generic CSS grammar and the individual grammars of each feature in this module, and meet all other conformance requirements of style sheets as described in this module.

Partial implementations

So that authors can exploit the forward-compatible parsing rules to assign fallback values, CSS renderers must treat as invalid (and ignore as appropriate) any at-rules, properties, property values, keywords, and other syntactic constructs for which they have no usable level of support. In particular, user agents must not selectively ignore unsupported component values and honor supported values in a single multi-value property declaration: if any value is considered invalid (as unsupported values must be), CSS requires that the entire declaration be ignored.

Implementations of Unstable and Proprietary Features

To avoid clashes with future stable CSS features, the CSSWG recommends following best practices for the implementation of unstable features and proprietary extensions to CSS.

Non-experimental implementations

Once a specification reaches the Candidate Recommendation stage, non-experimental implementations are possible, and implementors should release an unprefixed implementation of any CR-level feature they can demonstrate to be correctly implemented according to spec.

To establish and maintain the interoperability of CSS across implementations, the CSS Working Group requests that non-experimental CSS renderers submit an implementation report (and, if necessary, the testcases used for that implementation report) to the W3C before releasing an unprefixed implementation of any CSS features. Testcases submitted to W3C are subject to review and correction by the CSS Working Group.

Further information on submitting testcases and implementation reports can be found from on the CSS Working Group’s website at https://www.w3.org/Style/CSS/Test/. Questions should be directed to the [email protected] mailing list.

Index

Terms defined by this specification

Terms defined by reference

References

Normative References

[COMPAT]
Mike Taylor. Compatibility Standard. Living Standard. URL: https://compat.spec.whatwg.org/
[CSS-BACKGROUNDS-3]
Bert Bos; Elika Etemad; Brad Kemper. CSS Backgrounds and Borders Module Level 3. 14 February 2023. CR. URL: https://www.w3.org/TR/css-backgrounds-3/
[CSS-BOX-4]
Elika Etemad. CSS Box Model Module Level 4. 3 November 2022. WD. URL: https://www.w3.org/TR/css-box-4/
[CSS-BREAK-3]
Rossen Atanassov; Elika Etemad. CSS Fragmentation Module Level 3. 4 December 2018. CR. URL: https://www.w3.org/TR/css-break-3/
[CSS-BREAK-4]
Rossen Atanassov; Elika Etemad. CSS Fragmentation Module Level 4. 18 December 2018. WD. URL: https://www.w3.org/TR/css-break-4/
[CSS-CASCADE-5]
Elika Etemad; Miriam Suzanne; Tab Atkins Jr.. CSS Cascading and Inheritance Level 5. 13 January 2022. CR. URL: https://www.w3.org/TR/css-cascade-5/
[CSS-CONTAIN-1]
Tab Atkins Jr.; Florian Rivoal. CSS Containment Module Level 1. 25 October 2022. REC. URL: https://www.w3.org/TR/css-contain-1/
[CSS-CONTAIN-2]
Tab Atkins Jr.; Florian Rivoal; Vladimir Levin. CSS Containment Module Level 2. 17 September 2022. WD. URL: https://www.w3.org/TR/css-contain-2/
[CSS-CONTENT-3]
Elika Etemad; Dave Cramer. CSS Generated Content Module Level 3. 2 August 2019. WD. URL: https://www.w3.org/TR/css-content-3/
[CSS-DISPLAY-3]
Tab Atkins Jr.; Elika Etemad. CSS Display Module Level 3. 16 March 2023. CR. URL: https://www.w3.org/TR/css-display-3/
[CSS-INLINE-3]
Dave Cramer; Elika Etemad. CSS Inline Layout Module Level 3. 14 November 2022. WD. URL: https://www.w3.org/TR/css-inline-3/
[CSS-MASKING-1]
Dirk Schulze; Brian Birtles; Tab Atkins Jr.. CSS Masking Module Level 1. 5 August 2021. CR. URL: https://www.w3.org/TR/css-masking-1/
[CSS-MULTICOL-1]
Florian Rivoal; Rachel Andrew. CSS Multi-column Layout Module Level 1. 12 October 2021. CR. URL: https://www.w3.org/TR/css-multicol-1/
[CSS-OVERFLOW-3]
Elika Etemad; Florian Rivoal. CSS Overflow Module Level 3. 31 December 2022. WD. URL: https://www.w3.org/TR/css-overflow-3/
[CSS-POSITION-3]
Elika Etemad; Tab Atkins Jr.. CSS Positioned Layout Module Level 3. 17 February 2023. WD. URL: https://www.w3.org/TR/css-position-3/
[CSS-PSEUDO-4]
Daniel Glazman; Elika Etemad; Alan Stearns. CSS Pseudo-Elements Module Level 4. 30 December 2022. WD. URL: https://www.w3.org/TR/css-pseudo-4/
[CSS-REGIONS-1]
Rossen Atanassov; Alan Stearns. CSS Regions Module Level 1. 9 October 2014. WD. URL: https://www.w3.org/TR/css-regions-1/
[CSS-SIZING-3]
Tab Atkins Jr.; Elika Etemad. CSS Box Sizing Module Level 3. 17 December 2021. WD. URL: https://www.w3.org/TR/css-sizing-3/
[CSS-SYNTAX-3]
Tab Atkins Jr.; Simon Sapin. CSS Syntax Module Level 3. 24 December 2021. CR. URL: https://www.w3.org/TR/css-syntax-3/
[CSS-TEXT-3]
Elika Etemad; Koji Ishii; Florian Rivoal. CSS Text Module Level 3. 13 February 2023. CR. URL: https://www.w3.org/TR/css-text-3/
[CSS-TEXT-4]
Elika Etemad; et al. CSS Text Module Level 4. 1 March 2023. WD. URL: https://www.w3.org/TR/css-text-4/
[CSS-VALUES-3]
Tab Atkins Jr.; Elika Etemad. CSS Values and Units Module Level 3. 1 December 2022. CR. URL: https://www.w3.org/TR/css-values-3/
[CSS-VALUES-4]
Tab Atkins Jr.; Elika Etemad. CSS Values and Units Module Level 4. 19 October 2022. WD. URL: https://www.w3.org/TR/css-values-4/
[CSS-WRITING-MODES-3]
Elika Etemad; Koji Ishii. CSS Writing Modes Level 3. 10 December 2019. REC. URL: https://www.w3.org/TR/css-writing-modes-3/
[CSS-WRITING-MODES-4]
Elika Etemad; Koji Ishii. CSS Writing Modes Level 4. 30 July 2019. CR. URL: https://www.w3.org/TR/css-writing-modes-4/
[CSS2]
Bert Bos; et al. Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification. 7 June 2011. REC. URL: https://www.w3.org/TR/CSS21/
[CSS22]
Bert Bos. Cascading Style Sheets Level 2 Revision 2 (CSS 2.2) Specification. 12 April 2016. WD. URL: https://www.w3.org/TR/CSS22/
[CSS3-FLEXBOX]
Tab Atkins Jr.; et al. CSS Flexible Box Layout Module Level 1. 19 November 2018. CR. URL: https://www.w3.org/TR/css-flexbox-1/
[CSS3-GRID-LAYOUT]
Tab Atkins Jr.; et al. CSS Grid Layout Module Level 1. 18 December 2020. CR. URL: https://www.w3.org/TR/css-grid-1/
[RFC2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Best Current Practice. URL: https://datatracker.ietf.org/doc/html/rfc2119
[SELECT]
Tantek Çelik; et al. Selectors Level 3. 6 November 2018. REC. URL: https://www.w3.org/TR/selectors-3/
[UAX29]
Christopher Chapman. Unicode Text Segmentation. 26 August 2022. Unicode Standard Annex #29. URL: https://www.unicode.org/reports/tr29/tr29-41.html

Informative References

[CSS-OVERFLOW-4]
David Baron; Florian Rivoal. CSS Overflow Module Level 4. 31 December 2022. WD. URL: https://www.w3.org/TR/css-overflow-4/
[CSS-PAGE-3]
Elika Etemad; Simon Sapin. CSS Paged Media Module Level 3. 18 October 2018. WD. URL: https://www.w3.org/TR/css-page-3/
[CSS-SCROLLBARS-1]
Tantek Çelik; Rossen Atanassov; Florian Rivoal. CSS Scrollbars Styling Module Level 1. 9 December 2021. CR. URL: https://www.w3.org/TR/css-scrollbars-1/
[CSS-UI-4]
Florian Rivoal. CSS Basic User Interface Module Level 4. 16 March 2021. WD. URL: https://www.w3.org/TR/css-ui-4/
[CSS1]
Håkon Wium Lie; Bert Bos. Cascading Style Sheets, level 1. 13 September 2018. REC. URL: https://www.w3.org/TR/CSS1/
[CSS3-MARQUEE]
Bert Bos. CSS Marquee Module Level 3. 14 October 2014. NOTE. URL: https://www.w3.org/TR/css3-marquee/
[CSS3GCPM]
Dave Cramer. CSS Generated Content for Paged Media Module. 13 May 2014. WD. URL: https://www.w3.org/TR/css-gcpm-3/
[HTML]
Anne van Kesteren; et al. HTML Standard. Living Standard. URL: https://html.spec.whatwg.org/multipage/

Property Index

Name Value Initial Applies to Inh. %ages Anim­ation type Canonical order Com­puted value Logical property group
-webkit-line-clamp none | <integer [1,∞]> none see individual properties see individual properties N/A see individual properties per grammar see individual properties
block-ellipsis none | auto | <string> none block containers yes N/A discrete per grammar specified value
continue auto | discard auto block containers and multicol containers no N/A discrete per grammar specified keyword
line-clamp none | <integer [1,∞]> <'block-ellipsis'>? none see individual properties see individual properties N/A see individual properties per grammar see individual properties
max-lines none | <integer [1,∞]> none block containers which are also fragmentation containers that capture region breaks no N/A by computed value type per grammar the keyword none or an integer
overflow-clip-margin <visual-box> || <length [0,∞]> 0px boxes to which overflow applies no see individual properties see individual properties per grammar see individual properties
overflow-clip-margin-block <visual-box> || <length [0,∞]> 0px boxes to which overflow applies no see individual properties see individual properties per grammar see individual properties
overflow-clip-margin-block-end <visual-box> || <length [0,∞]> 0px boxes to which overflow applies no see individual properties per computed value if the <visual-box> values match; otherwise discrete per grammar the computed <length> and a <visual-box> keyword overflow-clip-margin
overflow-clip-margin-block-start <visual-box> || <length [0,∞]> 0px boxes to which overflow applies no see individual properties per computed value if the <visual-box> values match; otherwise discrete per grammar the computed <length> and a <visual-box> keyword overflow-clip-margin
overflow-clip-margin-bottom <visual-box> || <length [0,∞]> 0px boxes to which overflow applies no see individual properties per computed value if the <visual-box> values match; otherwise discrete per grammar the computed <length> and a <visual-box> keyword overflow-clip-margin
overflow-clip-margin-inline <visual-box> || <length [0,∞]> 0px boxes to which overflow applies no see individual properties see individual properties per grammar see individual properties
overflow-clip-margin-inline-end <visual-box> || <length [0,∞]> 0px boxes to which overflow applies no see individual properties per computed value if the <visual-box> values match; otherwise discrete per grammar the computed <length> and a <visual-box> keyword overflow-clip-margin
overflow-clip-margin-inline-start <visual-box> || <length [0,∞]> 0px boxes to which overflow applies no see individual properties per computed value if the <visual-box> values match; otherwise discrete per grammar the computed <length> and a <visual-box> keyword overflow-clip-margin
overflow-clip-margin-left <visual-box> || <length [0,∞]> 0px boxes to which overflow applies no see individual properties per computed value if the <visual-box> values match; otherwise discrete per grammar the computed <length> and a <visual-box> keyword overflow-clip-margin
overflow-clip-margin-right <visual-box> || <length [0,∞]> 0px boxes to which overflow applies no see individual properties per computed value if the <visual-box> values match; otherwise discrete per grammar the computed <length> and a <visual-box> keyword overflow-clip-margin
overflow-clip-margin-top <visual-box> || <length [0,∞]> 0px boxes to which overflow applies no see individual properties per computed value if the <visual-box> values match; otherwise discrete per grammar the computed <length> and a <visual-box> keyword overflow-clip-margin
text-overflow [ clip | ellipsis | <string> | fade | <fade()> ]{1,2} clip block containers no refer to the width of the line box by computed value type per grammar as specified, with lengths made absolute

Issues Index

Copy Level 3 content when final.
Copy Level 3 content when final.
Application of overflow to replaced elements is still being worked out. [Issue #7144]
Application of overflow-clip-margin to replaced elements is still being worked out. [Issue #7144]
This section might need to be re-synced against [CSS-OVERFLOW-3].
Do we need to define the way the fade out is calculated so that the fading is identical across browsers? It should probably be something like mask-image: linear-gradient(to right, rgba(0,0,0,1), rgba(0,0,0,0)), except applied to the relevant portion of the line only.
If the line box is too short to display the fade effect at the desired length, should we drop the effect, or shrink the distance it is applied over until it fits, or clip the end of the fade?
How should we deal with things overflowing out of the line box, or overlapping onto it? Should fade apply to the logical content of the line, or to the physical area of the line box, or the intersection of both?
insert RTL example diagram here to illustrate note.
Should this apply to other types of fragmentation breaks (e.g. pages, columns)?
For the time being, experimental implementations are encouraged to follow the full behavior defined by this shorthand and its longhands, but to only expose the shorthand to authors. This is in order to facilitate further tweaking, and in particular potential renaming, of the longhand properties and their values.
This property is meant to generalize and replace the region-fragment property from [CSS-REGIONS-1]. Once it is sufficiently stable in this specification, region-fragment should be removed from the regions specification in favor of this.
Make sure effects on OM are well defined [Issue #2970]
What about positioned elements whose static position is in the discarded content are not rendered? See also discussions in the Sydney F2F meeting. [Issue #2971]
This section is highly experimental. It documents current attempts at extending the capabilities of the continue property to solve additional use cases. However, it does not currently have consensus. It is presented here to encourage discussion, but non-experimental implementation is not recommended.
The naming of this property and its values is preliminary. This was initially proposed as "fragmentation: auto | none | break | clone | page" in https://lists.w3.org/Archives/Public/www-style/2015Jan/0357.html, and there is not yet wide agreement as to which naming is better.
This property is meant to generalize and replace region-fragment. Once it is sufficiently stable in this specification, region-fragment should be removed from the regions specification in favor of this.
this is different from the definition in § 5.3 Fragmentation of Overflow: the continue property, where the specified value is the computed value. Which is model better?
If we introduce a pseudo element that can select columns in a multicol, we would need to specify that auto computes to auto on it, or introduce a new value and have auto compute to that (but what would that value compute to on things that aren’t columns?).
Write this section
Pages should be possible to style with @page rules. How does that work for nested pages?
Should traditional pagination (e.g. when printing) be expressed through some magic in the computed value of auto, or by inserting this in the UA stylesheet:
@media (overflow-block: paged), (overflow-block: optional-paged) {
  :root {
    continue: paginate;
  }
}
Traditional pagination (e.g. when printing) assumes that :root is contained in the page box, rather than having the page box be a pseudo element child of :root. Can we work around that using something similar to fragment boxes? Or maybe by having a fragment box (reproducing :root) inside a page box inside :root?
How does the page box model work when it is a child of a regular css box?
The initial proposal in [CSS3GCPM] and implementation from Opera used 4 values instead of paginate: "paged-x | paged-y | paged-x-controls | paged-y-controls". Should this property also include these values, or are they better handled as separate properties? (e.g.: "pagination-layout: auto | horizontal | vertical", "pagination-controls: auto | none")
Ability to display N pages at once rather than just one page at once? Could this be a value of "pagination-layout", such as: "pagination-layout: horizontal 2;"
Brad Kemper has proposed a model for combining pagination and fragment overflow, which also deals with displaying multiple pages. https://www.w3.org/mid/[email protected]
The current implementation of paginated overflow uses the overflow/overflow-x/overflow-y properties rather than the overflow-style property as proposed in the [CSS3GCPM] draft (which also matches the [CSS3-MARQUEE] proposal). or the continue property as described here.
Or is it as though it’s a next sibling of the element? Need to figure out exactly how this interacts with other box-level fixup.
though it defines multi-column container
Should a forced break that breaks to an outer fragmentation context cause a new fragment of a single fragment box or a new fragment box?
Should we find a term other than fragment box here to make this a little less confusing?
What if we want to be able to style the pieces of an element split within another type of fragmentation context? These rules prevent ever using ::nth-fragment() for that, despite that the name seems the most logical name for such a feature.
We should specify that continue: fragments does not apply to at least some table parts, and perhaps other elements as well. We need to determine exactly which ones.
This specification needs to say which type of fragmentation context is created so that it’s clear which values of the break-* properties cause breaks within this context. We probably want break-*: region to apply.
This specification needs a processing model that will apply in cases where the layout containing the fragments has characteristics that use the intrinsic size of the fragments to change the amount of space available for them, such as [CSS3-GRID-LAYOUT]. There has already been some work on such a processing model in [CSS-REGIONS-1], and the work done on a model there, and the editors of that specification, should inform what happens in this specification.
Depending on future discussions, this ::nth-fragment(an+b) syntax may be replaced with the new ::fragment:nth(an+b) syntax.
Should this apply to continue:fragments only, or also to continue:paginate? (If it applies, then stricter property restrictions would be needed for continue:paginate.)
Does this need to be specified in the cascading module as well?
Need to specify exactly how this works
This inheritance rule allows specifying styles indirectly (by using explicit inherit or using default inheritance on properties that don’t apply to ::first-letter) that can’t be specified directly (based on the rules in the next section). This is a problem. The restrictions that apply to styling inside fragments should also apply to inheritance from fragments.
Should this apply to continue:fragments only, or also to continue:paginate?
This section documents current attempts at extending the scrollbar-gutter property to solve additional use cases. However, it does not currently have consensus. It is presented here to encourage discussion, but non-experimental implementation is not recommended.
Apple is reluctant to add this value, as authors may use it too broadly, inserting gutters with overlay scrollbars even when not justified by interactive elements, defeating the space-saving advantage of overlay scrollbars.

An alternative solution has been suggested: as the focus is interactive elements, maybe we could have a property that applies to the elements that needs to avoid being under the scrollbar. When turned on, it would enlarge the right or left margin of the element as appropriate by just the right value to push it out from under an overlay scrollbar if that’s where it would end up, but would leave the element unchanged otherwise.

Possibly, an addition toggle would cause the element to enlarge both its inline-end and inline-start margins or neither, rather than just one. This could typically be useful for block-level descendants of the scroller with visible borders or background: adding space on one side to avoid collisions with the overlay scrollbar would make them look off-center when the scrollbar disapears. Increasing the margin on both sides avoids that.

Yet another possibility is to have a choice between growing the margin to protect the element, or growing the padding to protect the element’s content.

The syntax could be something like scrollbar-avoid: none | [self | content] && both-edges?.

An interesting consideration is that this may alleviate the need for scrollbar-gutter: match-parent, as it seems that situations that would have been addressed by scrollbar-gutter: stable or scrollbar-gutter: always on the parent and scrollbar-gutter: match-parent on the select children could instead be addressed by leaving the parent as scrollbar-gutter: auto and using scrollbar-avoid: self or scrollbar-avoid: content on the relevant children.

It is because of this value that the property has been be made to apply to all elements, rather than merely to scroll containers, so that it can apply to overflow: visible elements as shown in the example. This could pause implementations difficulties, as user agents cannot just rely on existing code to place the gutter, since they may have to do so on elements which previously could not have one. Restricting it to all elements where overflow applies would probably have no negative effect on use cases and could make implementation easier; however, even that may still be more difficult that limiting it to scroll containers.
In addition to the implementation challenges mentioned above, it is not clear that this value solves the problem as reliably as it intends to. As the size and side of the scrollbar and its gutter are UA defined, they may vary between different elements. Since the appearance and position of scrollbars are up to the user agent, there is no limit to the list of properties that might influence them. It is probable that setting properties such as direction (via setting the HTML dir attribute) or scrollbar-width could give enough context to the user agent to know how it would create a scrollbar on that element if it were scrollable, and therefore to create a gutter of the same size at the right place, but it cannot be guaranteed.
In early iterations of the specification, this value was the only way to achieve the effect described in the example. However, since then, scrollbar-gutter: stable has been made to apply to overflow: hidden elements. While applying overflow: hidden has other effects which may be undesirable in that context, the combination of scrollbar-gutter: stable and overflow: hidden does add spacing in the same way as scrollbar-gutter: stable force, and may prove to be a sufficient workaround, particularly considering the other issues described above.
TBD