CARVIEW |
CSS Overflow Module Level 3
Editor’s Draft,
- This version:
- https://drafts.csswg.org/css-overflow/
- Latest version:
- https://www.w3.org/TR/css-overflow-3/
- Previous Versions:
- https://www.w3.org/TR/2013/WD-css-overflow-3-20130418/
- Feedback:
- www-style@w3.org with subject line “[css-overflow] … message topic …” (archives)
- Issue Tracking:
- Inline In Spec
- Editors:
- L. David Baron (Mozilla)
- Florian Rivoal (On behalf of Bloomberg) florian@rivoal.net
- Change Log:
- from 27 January 2015 to the present
- from 28 March 2013 to 27 January 2015
- from 31 July 2012 to 27 March 2013
- from 28 March 2013 to 27 January 2015
Copyright © 2016 W3C® (MIT, ERCIM, Keio, Beihang). W3C liability, trademark and document use rules apply.
Abstract
This module contains the features of CSS relating to scrollable overflow handling in visual media.
CSS is a language for describing the rendering of structured documents (such as HTML and XML) on screen, on paper, in speech, etc.Status of this document
This is a public copy of the editors’ draft. It is provided for discussion only and may change at any moment. Its publication here does not imply endorsement of its contents by W3C. Don’t cite this document other than as work in progress.
The (archived) public mailing list www-style@w3.org (see instructions) is preferred for discussion of this specification. When sending e-mail, please put the text “css-overflow” in the subject, preferably like this: “[css-overflow] …summary of comment…”
This document was produced by the CSS Working Group (part of the Style Activity).
This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.
This document is governed by the 1 September 2015 W3C Process Document.
1. 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, and defines overflow handling more fully.
[Something something max-lines.]
2. 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, 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 three different types of overflow, which are used for different purposes by the UA:
2.1. 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.
What about hanging-punctuation?
Since some effects in CSS (for example, the blurs in text-shadow [CSS3TEXT] and box-shadow [CSS3BG]) 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, and the ink overflow rectangle is the minimal rectangle whose axis is aligned to the box’s axes and 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].
2.2. 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 axis is aligned to the box’s axes and contains the scrollable overflow region.
The scrollable overflow region is the union of:
- the box’s own content and padding areas
- all line boxes directly contained by the box
- the margin boxes unioned with the border boxes of all boxes for which it is the containing block (accounting for transforms as described below). Issue: Only Blink (and presumably WebKit) use the margin box for abspos; other browsers use the border box. Can we convince everyone else to change? Because using the border box is kindof hostile.
- the scrollable overflow regions of all of the above boxes (accounting for transforms as described below), provided they themselves have overflow: visible (i.e. do not themselves trap the overflow) and that overflow is not already clipped by the clip or clip-path properties.
The following definition should be rewritten to use the concept of 3D rendering context [CSS3-TRANSFORMS] and related terms, particularly once those concepts stabilize following changes proposed in the CSS WG meeting on the morning of 2014-01-28.
Given the following definitions which belong in [CSS3-TRANSFORMS]:
- 3d-preserving child
- A child box B of a containing block C is a 3d-preserving child if it has transform-style: preserve-3d and the user-agent is not required to flatten it based on the requirements in [CSS3-TRANSFORMS].
- non-3d-preserving child
- A child C of a box P is a non-3d-preserving-child if it is not a 3d-preserving child.
- 3d-preserving descendant
- Box D is a 3d-preserving descendant of box A if A is an ancestor of D, and D and all of the boxes (if any) in the containing block chain from D to A are 3d-preserving child boxes.
The scrollable overflow of a box is the union of the following things, all adjusted for transforms undefined concept! into the box’s coordinate space:
-
for the box and all of its 3d-preserving descendant boxes:
- the box’s own padding edge (for the box itself) or border edge (for 3d-preserving descendant boxes)
- the bounds undefined term! of any text directly in the box
- MORE HERE!
- for all the non-3d-preserving child boxes of the box and its 3d-preserving descendant boxes, the scrollable overflow of the box
I wrote this definition off the top of my head, so it can’t possibly be right. It’s missing tons of pieces!
The handling of preserve-3d subtrees here is probably wrong; the elements should probably count only towards the overflow of the element that flattens them.
Note that the scrollable overflow rectangle is a always rectangle in the box’s own coordinate system, but might be non-rectangular in other coordinate systems due to transforms [CSS3-TRANSFORMS].
Browsers seem to agree on using axis-aligned rectangles (in the element’s own coord space) to determine overflow. This means scrollbars can appear when not actually necessary. See testcase (adjust the scale(.9) to scale(.7) to see the scrollbars disappear, as the blue grandchild is no longer growing the bounds of the green child). Is this behavior we want to spec, or is it something browsers would like to fix someday?
2.3. Border box overflow
This concept has been proposed for some uses, such as for determining what the outline property goes around, and as the basis of a coordinate system for specifying clips and masks, but it’s not clear if it’s needed.
The border-box overflow of a box is the union of the box’s border edge and the border edges of the box’s descendants.
If needed, define more formally, as for scrollable overflow above. (Maybe even share the definitions in an appropriate way!)
The border-box overflow region is the non-rectangular region occupied by the border-box overflow, and the border-box overflow rectangle is the minimal rectangle whose axis is aligned to the box’s axes and contains the border-box overflow region. Note that the border-box 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].
3. Scrollable 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 scrollable box that allows the user to scroll clipped parts of its scrollable overflow region into view.
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: | see below |
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, it may be rendered outside the box. The box is not a scrollable box.
- 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. However, the content may still be scrolled programatically, for example using the mechanisms defined in [CSSOM-VIEW], and the box is therefore still a scrollable box.
- 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 scrollable box.
Mozilla implements -moz-hidden-unscrollable, which is similar to clip, except that it does not cause the element to establish a BFC. Should we match that?
- 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 scrollable box). 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 this value is specified and the target medium is print, overflowing content may be printed.
- auto
- This value indicates that the box’s content is clipped to the padding box, but can be scrolled into view (and therefore the box is a scrollable box). However, 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 only be displayed if there is overflow.
If the computed value of overflow on a block box is not visible, it creates a new block formatting context for its content.
3.1. Overflow Value Computation and Propagation
The computed values of overflow-x and overflow-y are determined from the specified values [CSS3CASCADE] based on the following rules:
- If one specified value is visible and the other is not, then computed values are the specified values with visible changed to auto.
- Otherwise, if both specified values are visible and the computed value of contain is one that activates paint containment (e.g. contain:strict or contain: paint or contain: layout paint…), then the computed values of both overflow-x and overflow-y are changed to clip.
- Otherwise, the computed values are as specified.
UAs must apply the overflow property
set on the root element to the viewport.
For HTML UAs,
if this would result in the viewport having visible overflow,
the UA must instead apply the overflow property
set on the body
element to the viewport.
In either case,
the used value of overflow for the element from which the value is propagated
must evaluate to visible.
If this application would result in the viewport having visible overflow, the UA must instead treat the viewport as having auto overflow.
3.2. 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.
import examples from [CSS3-BOX].
3.3. 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.
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 scrollable boxes 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.
[CSS3-MARQUEE] describes an overflow-style property, but it has not picked up implementation experience that the working group is aware of. Should this document treat overflow-style as a defunct proposal, or should this document describe the overflow-style property and attempt to revive it, despite that implementations have implemented overflow-x and overflow-y instead?
4. Limiting Number of Visible Text Lines: the max-lines property
Name: | max-lines |
---|---|
Value: | none | <integer> |
Initial: | none |
Applies to: | all non-inline elements |
Inherited: | no |
Percentages: | N/A |
Media: | visual |
Computed value: | specified value |
Animatable: | as integer |
Add back max-lines, so we can kill the unspecified WebKit feature that does this poorly.
5. Overflow in static media
This specification should define useful behavior for all values of overflow in static media (such as print). Current implementation behavior is quite poor and produces unexpected results when authors have not considered what will happen when the content they produce for interactive media is printed.
6. Privacy and Security Considerations
This specification introduces no new privacy or security concerns.
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:
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.
Requirements for Responsible Implementation of CSS
The following sections define several conformance requirements for implementing CSS responsibly, in a way that promotes interoperability in the present and future.
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 property 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.
Implementations of CR-level Features
Once a specification reaches the Candidate Recommendation stage, implementers should release an unprefixed implementation of any CR-level feature they can demonstrate to be correctly implemented according to spec, and should avoid exposing a prefixed variant of that feature.
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 public-css-testsuite@w3.org mailing list.
Index
Terms defined by this specification
- 3d-preserving child, in §2.2
- 3d-preserving descendant, in §2.2
- auto, in §3
- border-box overflow, in §2.3
- border-box overflow rectangle, in §2.3
- border-box overflow region, in §2.3
- clip, in §3
- hidden, in §3
- initial scroll position, in §3.3
- ink overflow, in §2.1
- ink overflow rectangle, in §2.1
- ink overflow region, in §2.1
- max-lines, in §4
- non-3d-preserving child, in §2.2
-
overflow
- definition of, in §2
- (property), in §3
- overflow-x, in §3
- overflow-y, in §3
- scroll, in §3
- scrollable box, in §3
- scrollable overflow, in §2.2
- scrollable overflow rectangle, in §2.2
- scrollable overflow region, in §2.2
- visible, in §3
Terms defined by reference
- [css-align-3] defines the following terms:
- [css-backgrounds-3] defines the following terms:
- [css-cascade-4] defines the following terms:
- [css-containment-3] defines the following terms:
- [css-display-3] defines the following terms:
- [css-masking-1] defines the following terms:
- [css-text-3] defines the following terms:
- [css-text-decor-3] defines the following terms:
- [css-transforms-1] defines the following terms:
- [css-ui-3] defines the following terms:
- [css-values] defines the following terms:
- [css-writing-modes-3] defines the following terms:
- [HTML] defines the following terms:
- [mediaqueries-4] defines the following terms:
References
Normative References
- [CSS21]
- 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/CSS2
- [CSS3CASCADE]
- Elika Etemad; Tab Atkins Jr.. CSS Cascading and Inheritance Level 3. 16 April 2015. CR. URL: https://www.w3.org/TR/css-cascade-3/
- [HTML]
- Ian Hickson. HTML Standard. Living Standard. URL: https://html.spec.whatwg.org/multipage/
- [CSS-ALIGN-3]
- Elika Etemad; Tab Atkins Jr.. CSS Box Alignment Module Level 3. 18 December 2014. WD. URL: https://www.w3.org/TR/css-align-3/
- [CSS-BACKGROUNDS-3]
- CSS Backgrounds and Borders Module Level 3 URL: https://www.w3.org/TR/css3-background/
- [CSS-CASCADE-4]
- Elika Etemad; Tab Atkins Jr.. CSS Cascading and Inheritance Level 4. 14 January 2016. CR. URL: https://www.w3.org/TR/css-cascade-4/
- [CSS-CONTAINMENT-3]
- CSS Containment Module Level 3 URL: https://www.w3.org/TR/css-containment-3/
- [CSS-DISPLAY-3]
- Tab Atkins Jr.; Elika Etemad. CSS Display Module Level 3. 15 October 2015. WD. URL: https://www.w3.org/TR/css-display-3/
- [CSS-MASKING-1]
- Dirk Schulze; Brian Birtles; Tab Atkins Jr.. CSS Masking Module Level 1. 26 August 2014. CR. URL: https://www.w3.org/TR/css-masking-1/
- [CSS-TEXT-3]
- Elika Etemad; Koji Ishii. CSS Text Module Level 3. 10 October 2013. LCWD. URL: https://www.w3.org/TR/css-text-3/
- [CSS-TEXT-DECOR-3]
- Elika Etemad; Koji Ishii. CSS Text Decoration Module Level 3. 1 August 2013. CR. URL: https://www.w3.org/TR/css-text-decor-3/
- [CSS-TRANSFORMS-1]
- Simon Fraser; et al. CSS Transforms Module Level 1. 26 November 2013. WD. URL: https://www.w3.org/TR/css-transforms-1/
- [CSS-UI-3]
- Tantek Çelik; Florian Rivoal. CSS Basic User Interface Module Level 3 (CSS3 UI). 7 July 2015. CR. URL: https://www.w3.org/TR/css-ui-3/
- [CSS-VALUES]
- Tab Atkins Jr.; Elika Etemad. CSS Values and Units Module Level 3. 11 June 2015. CR. URL: https://www.w3.org/TR/css-values/
- [CSS-WRITING-MODES-3]
- Elika Etemad; Koji Ishii. CSS Writing Modes Level 3. 15 December 2015. CR. URL: https://www.w3.org/TR/css-writing-modes-3/
- [CSS3-FLEXBOX]
- Tab Atkins Jr.; Elika Etemad; Rossen Atanassov. CSS Flexible Box Layout Module Level 1. 14 May 2015. LCWD. URL: https://www.w3.org/TR/css-flexbox-1/
- [CSS3-GRID-LAYOUT]
- Tab Atkins Jr.; Elika Etemad; Rossen Atanassov. CSS Grid Layout Module Level 1. 17 September 2015. WD. URL: https://www.w3.org/TR/css-grid-1/
- [CSS3-TRANSFORMS]
- Simon Fraser; et al. CSS Transforms Module Level 1. 26 November 2013. WD. URL: https://www.w3.org/TR/css-transforms-1/
- [MEDIAQUERIES-4]
- Florian Rivoal; Tab Atkins Jr.. Media Queries Level 4. 26 January 2016. WD. URL: https://www.w3.org/TR/mediaqueries-4/
- [RFC2119]
- S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Best Current Practice. URL: https://tools.ietf.org/html/rfc2119
Informative References
- [CSS1]
- Håkon Wium Lie; Bert Bos. Cascading Style Sheets (CSS1) Level 1 Specification. 11 April 2008. REC. URL: https://www.w3.org/TR/CSS1/
- [CSS3BG]
- Bert Bos; Elika Etemad; Brad Kemper. CSS Backgrounds and Borders Module Level 3. 9 September 2014. CR. URL: https://www.w3.org/TR/css3-background/
- [CSS3TEXT]
- Elika Etemad; Koji Ishii. CSS Text Module Level 3. 10 October 2013. LCWD. URL: https://www.w3.org/TR/css-text-3/
- [CSS3-BOX]
- Bert Bos. CSS basic box model. 9 August 2007. WD. URL: https://www.w3.org/TR/css3-box
- [CSS3-MARQUEE]
- Bert Bos. CSS Marquee Module Level 3. 14 October 2014. NOTE. URL: https://www.w3.org/TR/css3-marquee
- [CSSOM-VIEW]
- Simon Pieters; Glenn Adams. CSSOM View Module. 17 December 2013. WD. URL: https://www.w3.org/TR/cssom-view/
Property Index
Name | Value | Initial | Applies to | Inh. | %ages | Media | Animatable | Canonical order | Computed value |
---|---|---|---|---|---|---|---|---|---|
overflow-x | visible | hidden | clip | scroll | auto | visible | block containers [CSS21], flex containers [CSS3-FLEXBOX], and grid containers [CSS3-GRID-LAYOUT] | no | N/A | visual | no | see below | |
overflow-y | visible | hidden | clip | scroll | auto | visible | block containers [CSS21], flex containers [CSS3-FLEXBOX], and grid containers [CSS3-GRID-LAYOUT] | no | N/A | visual | no | see below | |
overflow | visible | hidden | clip | scroll | auto | see individual properties | block containers [CSS21], flex containers [CSS3-FLEXBOX], and grid containers [CSS3-GRID-LAYOUT] | no | N/A | visual | no | per grammar | see individual properties |
max-lines | none | <integer> | none | all non-inline elements | no | N/A | visual | as integer | specified value |