CSS Overflow Module Level 3
Status: ED
Work Status: Revising
ED: https://drafts.csswg.org/css-overflow/
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/
Editor: Florian Rivoal, On behalf of Bloomberg, florian@rivoal.net, http://florian.rivoal.net/
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
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.
spec:css-transforms-1; type:property; text:transform-style
type: dfn; spec:css-multicol-1; text:overflow column
type: dfn; spec:css-transforms-1; text:3d rendering context
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,
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,
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' [[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]].
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
There's disagreement on the scrolling model.
2.1 apparently defined that you scrolled the *content* area;
the content would overflow the content-box,
and you would union that overflow with the content box to find the scrollable area.
In particular, this means that the content would be offset by the start-sides padding,
but if it overflowed,
it would go right to the edge on the end sides.
This is what Firefox and IE do.
At least some authors (and spec authors)
instead have the mental model that the padding box is what's scrollable,
so when you scroll to the end of the overflow,
there's the right/bottom padding.
Chrome/WebKit do this for the block axis, at least.
They're somewhat inconsistent for the inline axis;
there's something weird about how they handle lineboxes.
It seems that the block-axis padding is probably web-compatible to honor.
It's unclear that the inline-axis padding will be.
Further experimentation is needed.
-
all line boxes directly contained by the box
-
the border boxes
of all boxes for which it is the containing block,
accounting for transforms by projecting each box onto
the plane of the element that establishes its 3D rendering context.
[[!CSS3-TRANSFORMS]]
Issue: Is this description of handling transforms
sufficiently accurate?
-
the scrollable overflow regions of all of the above boxes
(accounting for transforms as described above),
provided they themselves have ''overflow: visible''
(i.e. do not themselves trap the overflow)
and that scrollable overflow is not already clipped
(e.g. by the 'clip' property or the 'contain' property).
Note: The 'mask-*' properties [[!CSS-MASKING-1]]
do not affect the scrollable overflow region.
Issue: Need to evaluate compat of honoring or ignoring 'clip' and 'clip-path'.
-
Optionally,
additional padding on the end-edge sides,
corresponding to the end-side padding of the scroll container, such that the end edges of its in-flow content
coincide with the end edges of its content area
when scrolled to the end.
Issue: It's not yet clear if including the end-side padding in the scrollable layer is Web-compatible, so this clause is under investigation.
It appears that Chrome and Safari include such padding in the block axis;
and the behavior in the inline axis is not clear.
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.
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 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'' computing to ''auto'' if one of 'overflow-x' or 'overflow-y' is not ''visible''
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 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 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 scroll container).
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 ''overflow/visible'',
it creates a new block formatting context for its content.
Overflow Value Propagation
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 ''overflow/auto'' overflow.
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]].
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 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.
[[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?
Limiting Number of Visible Text Lines: the 'max-lines' property
Name: max-lines
Value: none | <>
Initial: none
Applies to: all non-inline elements
Inherited: no
Animatable: as integer
Percentages: N/A
Media: visual
Computed value: specified value
Issue: Add back 'max-lines', so we can kill the unspecified WebKit feature that does this poorly.
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.
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,
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.