Title: CSS Overflow Module Level 3
Status: ED
Work Status: Revising
ED: https://drafts.csswg.org/css-overflow-3/
Shortname: css-overflow
Group: csswg
Level: 3
TR: https://www.w3.org/TR/css-overflow-3/
Previous version: https://www.w3.org/TR/2016/WD-css-overflow-3-20160531/
Previous version: https://www.w3.org/TR/2013/WD-css-overflow-3-20130418/
Editor: L. David Baron, Mozilla https://www.mozilla.org/, https://dbaron.org/, w3cid 15393
Editor: Elika J. Etemad / fantasai, Invited Expert, http://fantasai.inkedblade.net/contact, w3cid 35400
Editor: Florian Rivoal, On behalf of Bloomberg, http://florian.rivoal.net/, w3cid 43241
Abstract: This module contains the features of CSS relating to scrollable overflow handling in visual media.
!Change Log: from 27 January 2015 to the present
!Change Log: from 28 March 2013 to 27 January 2015
!Change Log: from 31 July 2012 to 27 March 2013
Ignored Vars: B, P
Ignored Terms: padding edge, viewport, line box, flex order
At Risk: the 'max-lines' property
Status Text: This update trims away most of the experimental new ideas
   for handling overflow that were described in the previous Working Draft.
   These ideas are not abandoned; they are merely deferred until Level 4.
   Level 3 is focused solely on completing a spec for the existing, shipped 'overflow' features;
   work will resume on fragmented overflow and other fun things once this is completed.
url: https://www.w3.org/TR/2008/CR-css3-marquee-20081205/#the-overflow-style; type: property; text: overflow-style;

Introduction

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 [[CSS21]] 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 specification introduces the long-standing de-facto 'overflow-x' and 'overflow-y' properties, adds a ''overflow/clip'' value, and defines overflow handling more fully. [Something something 'max-lines'.]

Types of Overflow

CSS uses the term overflow to describe the contents of a box that extend outside one of that box's edges (i.e., its content edge, padding edge, border edge, or margin edge). The term might be interpreted as elements or features that cause this overflow, the non-rectangular region occupied by these features, or, more commonly, as the minimal rectangle that bounds that region. A box's overflow is computed based on the layout and styling of the box itself and of all descendants whose containing block chain includes the box. In most cases, overflow can be computed for any box from the bounds and properties of that box itself, plus the overflow of each of its children. However, this is not always the case; for example, when ''transform-style: preserve-3d'' [[CSS3-TRANSFORMS]] is used on some of the children, any of their descendants with ''transform-style: preserve-3d'' must also be examined. There are two different types of overflow, which are used for different purposes by the UA:

Ink Overflow

The ink overflow of a box is the part of that box and its contents that creates a visual effect outside of the box's border box. Ink overflow is the overflow of painting effects defined to not affect layout or otherwise extend the scrollable overflow region, such as box shadows, border images, text decoration, overhanging glyphs (with negative side bearings, or with ascenders/descenders extending outside the em box), outlines, etc. Since some effects in CSS (for example, the blurs in 'text-shadow' [[CSS-TEXT-3]] and 'box-shadow' [[CSS-BACKGROUNDS-3]], which are theoretically infinite) do not define what visual extent they cover, the extent of the ink overflow is undefined. The ink overflow region is the non-rectangular area occupied by the ink overflow of a box and its contents, and the ink overflow rectangle is the minimal rectangle whose axes are aligned to the box's axes and that contains the ink overflow region. Note that the ink overflow rectangle is a rectangle in the box's coordinate system, but might be non-rectangular in other coordinate systems due to transforms. [[CSS3-TRANSFORMS]]

Scrollable Overflow

The scrollable overflow of a box is the set of things extending outside of that box's padding edge for which a scrolling mechanism needs to be provided. The scrollable overflow region is the non-rectangular region occupied by the scrollable overflow, and the scrollable overflow rectangle is the minimal rectangle whose axes are aligned to the box's axes and that contains the scrollable overflow region. The scrollable overflow region is the union of: The UA may additionally include the margin areas of boxes for which it is the containing block. The conditions under which such margin areas are included is undefined in this level. This needs further testing and investigation; is therefore deferred in this draft. Note: The scrollable overflow rectangle is always a rectangle in the box's own coordinate system, but might be non-rectangular in other coordinate systems due to transforms [[CSS3-TRANSFORMS]]. This means scrollbars can sometimes appear when not actually necessary.

Scrolling and Clipping Overflow: the 'overflow-x', 'overflow-y', and 'overflow' properties

These properties specify whether a box’s content (including any ink overflow) is clipped to its padding edge, and if so, whether it is a scroll container that allows the user to scroll clipped parts of its scrollable overflow region into view. The visual viewport of the scroll container (through which the scrollable overflow region can be viewed) coincides with its padding box, and is called the scrollport.
		Name: overflow-x, overflow-y
		Value: ''visible'' | ''hidden'' | ''clip'' | ''scroll'' | ''auto''
		Initial: ''visible''
		Applies to: block containers [[!CSS21]], flex containers [[!CSS3-FLEXBOX]], and grid containers [[!CSS3-GRID-LAYOUT]]
		Inherited: no
		Percentages: N/A
		Media: visual
		Computed value: as specified, except with ''visible''/''clip'' computing to ''auto''/''hidden'' (respectively) if one of 'overflow-x' or 'overflow-y' is neither ''visible'' nor ''clip''
		Animatable: no
	
The 'overflow-x' property specifies the handling of overflow in the horizontal direction (i.e., overflow from the left and right sides of the box), and the 'overflow-y' property specifies the handling of overflow in the vertical direction (i.e., overflow from the top and bottom sides of the box).
		Name: overflow
		Value: ''visible'' | ''hidden'' | ''clip'' | ''scroll'' | ''auto''
		Initial: see individual properties
		Applies to: block containers [[!CSS21]], flex containers [[!CSS3-FLEXBOX]], and grid containers [[!CSS3-GRID-LAYOUT]]
		Inherited: no
		Percentages: N/A
		Media: visual
		Computed value: see individual properties
		Animatable: no
		Canonical order: per grammar
	
The 'overflow' property is a shorthand property that sets the specified values of both 'overflow-x' and 'overflow-y' to the value specified for 'overflow'. Values have the following meanings:
visible
There is no special handling of overflow, that is, the box’s content is rendered outside the box if positioned there. The box is not a scroll container.
hidden
This value indicates that the box’s content is clipped to its padding box and that the UA must not provide any scrolling user interface to view the content outside the clipping region, nor allow scrolling by direct intervention of the user, such as dragging on a touch screen or using the scrolling wheel on a mouse. However, the content must still be scrollable programatically, for example using the mechanisms defined in [[CSSOM-VIEW]], and the box is therefore still a scroll container.
clip
Like ''hidden'', this value indicates that the box’s content is clipped to its padding box and that no scrolling user interface should be provided by the UA to view the content outside the clipping region. In addition, unlike ''overflow: hidden'' which still allows programmatic scrolling, ''overflow: clip'' forbids scrolling entirely, through any mechanism, and therefore the box is not a scroll container.
scroll
This value indicates that the content is clipped to the padding box, but can be scrolled into view (and therefore the box is a scroll container). Furthermore, if the user agent uses a scrolling mechanism that is visible on the screen (such as a scroll bar or a panner), that mechanism should be displayed whether or not any of its content is clipped. This avoids any problem with scrollbars appearing and disappearing in a dynamic environment. When the target medium is ''print'', overflowing content may be printed; it is not defined where it may be printed.
auto
Like ''overflow/scroll'' when the box has scrollable overflow; like ''overflow/hidden'' otherwise. Thus, if the user agent uses a scrolling mechanism that is visible on the screen (such as a scroll bar or a panner), that mechanism will only be displayed if there is overflow.
If the computed value of 'overflow' on a block box is not ''overflow/visible'', it creates a new block formatting context for its content.

Overflow in Print and Other Static Media

Since scrolling is not possible in static media (such as print) authors should be careful to make content accessible in such media, for example by using ''@media print, (update: none) { … }'' to adjust layout such that all relevant content is simultaneously visible. On scroll containers in static media with an 'overflow' value of ''overflow/auto'' or ''overflow/scroll'' (but not ''overflow/hidden'') UAs may display an indication of any scrollable overflow, such as by displaying scrollbars or an ellipsis. Note: Not all paged media is static; for example, e-book readers page content, but are interactive.

Scrollbars and Layout

In the case of a scrollbar being placed on an edge of the element's box, it should be inserted between the inner border edge and the outer padding edge. Any space taken up by the scrollbars should be taken out of (subtracted from the dimensions of) the containing block formed by the element with the scrollbars. Issue: import examples from [[CSS3-BOX]].

Scrolling Origin, Direction, and Restriction

The initial scroll position, that is, the initial position of the box’s scrollable overflow region with respect to its border box, prior to any user or programmatic scrolling that changes it, is dependent on the box’s writing mode, and is by default the block-start/inline-start edge of the box’s padding edge. However, the 'align-content' and 'justify-content' properties [[!CSS-ALIGN-3]] can be used to change this, see [[css-align-3#overflow-scroll-position]]. Due to Web-compatibility constraints (caused by authors exploiting legacy bugs to surreptitiously hide content from visual readers but not search engines and/or speech output), UAs must clip the scrollable overflow region of scroll containers on the block-start and inline-start sides of the box (thereby behaving as if they had no scrollable overflow on that side). The viewport uses the principal writing mode for these calculations.

Overflow Viewport Propagation

UAs must apply the 'overflow-*' values set on the root element to the viewport. However, when the root element is an [[!HTML]] <{html}> element (including XML syntax for HTML) whose 'overflow' value is ''overflow/visible'' (in both axes), and that element has a <{body}> element as a child, user agents must instead apply the 'overflow-*' values of the first such child element to the viewport. The element from which the value is propagated must then have a used 'overflow' value of ''overflow/visible''. If ''overflow/visible'' is applied to the viewport, it must be interpreted as ''overflow/auto''.

Limiting Visible Lines: the 'max-lines' property

		Name: max-lines
		Value: none | <>
		Initial: none
		Applies to: block containers (excluding multi-column containers)
		Inherited: no
		Animatable: as integer
		Percentages: N/A
		Media: visual
		Computed value: specified value
	
This property allows limiting the contents of a block container to the specified number of lines; remaining content is fragmented away and neither rendered nor measured. Specifically, if the value of 'max-lines' is not none: 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.

Indicating Block-Axis Overflow: the 'block-overflow' property

ISSUE: This section is an unofficial draft, posted here for discussion. See issue.
		Name: block-overflow
		Value: clip | ellipsis | <>
		Initial: clip
		Applies to: block containers
		Inherited: yes
		Animatable: no
		Percentages: N/A
		Media: visual
		Computed value: specified value
	
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. ISSUE: 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:
clip
The content is not altered.
ellipsis
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.
<>
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.
In this example, the lead paragraph of each article is listed in a shortened menu, truncated to fit within 10 lines that end with “… (continued on next page)”: li { max-lines: 5; block-overflow: "… (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 bureacracy 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)  |
			+---------------------------------------+
		
When 'block-overflow' is not ''block-overflow/clip'', 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 is placed in the line box after the last soft wrap opportunity [[!CSS-TEXT-3]] that would still allow the entire block overflow ellipsis to fit on the line. (This can result in the entire contents of the line box being replaced.) For this purpose, soft wrap opportunities added by 'overflow-wrap' are ignored. Text alignment and justification occurs after placement, and measures the inserted block overflow ellipsis together with the rest of the line’s content. If there is no next fragmentation container and thus the remainder of the content after the break would be discarded, then the UA may visually replace the contents of the line, as it does for 'text-overflow'. If, however, there is a next fragmentation container that would receive subsequent content, then the content replaced by the block overflow ellipsis must be pushed to the next fragmentation container and the block overflow ellipsis inserted and laid out exactly as if it were part of the in-flow contents of the line. This can result in changes to layout within or impacted by the line. The means of breaking any resulting cycles is up to the UA. If the block overflow ellipsis is too long to fit in the line, the result is undefined. (The UA may, for example, treat the block overflow ellipsis as an unbreakable string, or it may lay out the string across more than one line, replacing content in earlier lines as well.) The block overflow ellipsis does not capture events: pointer events are dispatched to whatever is underneath or otherwise visually replaced by 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-overflow' were ''block-overflow/clip''. 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).

Setting 'max-lines' and 'block-overflow' together: the 'line-clamp' property

		Name: line-clamp
		Value: none | <>
		Initial: none
		Applies to: see individual properties
		Inherited: see individual properties
		Animatable: see individual properties
		Percentages: N/A
		Media: visual
		Computed value: see individual properties
	
The 'line-clamp' property is a shorthand for the 'max-lines' and 'block-overflow' properties.
none
Sets 'max-lines' to ''max-lines/none'' and 'block-overflow' to ''block-overflow/clip''.
<>
Sets 'max-lines' to the specified <> and 'block-overflow' to ''block-overflow/ellipsis''.
For compatibility with legacy content, UAs that support 'line-clamp' must also support -webkit-line-clamp as an alias. Privacy and Security Considerations {#priv-sec} =============================================== This specification introduces no new privacy or security concerns.

Acknowledgments

Thanks especially to the feedback from Rossen Atanassov, Bert Bos, Tantek Çelik, John Daggett, 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.