1. Introduction
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.
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 [CSS3-BREAK].
The definition of the text-overflow property in this module supersedes the one in [CSS-UI-3] and [CSS-OVERFLOW-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.
2. Types of overflow
copy level 3 content when final
3. Overflow properties
copy level 3 content when final
4. 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 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
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 : 9 ch ;
text-overflow : ellipsis;
}
Sample HTML fragments, renderings, and your browser:
HTML | Reference rendering | Your Browser |
---|---|---|
|
123456 ם…
| |
|
…456 שלום
|
ellipsing details
- Ellipsing only affects rendering and must not affect layout nor dispatching of pointer events: The UA should dispatch any pointer event on the ellipsis to the elided element, as if text-overflow had been none.
- The ellipsis is styled and baseline-aligned according to the block.
- Ellipsing occurs after relative positioning and other graphical transformations.
- If there is insufficient space for the ellipsis, then clip the rendering of the ellipsis itself (on the same side that neutral characters on the line would have otherwise been clipped with the text-overflow:clip value).
user interaction with ellipsis
- When the user is interacting with content (e.g. editing, selecting, scrolling), the user agent may treat ellipsis, string values, fade or fade() as text-overflow:clip.
- Selecting the ellipsis should select the ellipsed text. If all of the ellipsed text is selected, UAs should show selection of the ellipsis. Behavior of partially-selected ellipsed text is up to the UA.
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.1 em ;
border : solid .1 em black;
padding : 0.2 em ; margin : 1 em 0 ;
}
sample HTML fragments, renderings, and your browser:
HTML | sample rendering | your browser |
---|---|---|
|
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
(
)
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.
sample CSS:
div.crawlbar {
text-overflow : ellipsis;
height : 2 em ;
overflow : scroll;
white-space : nowrap;
width : 15 em ;
border : 1 em 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:
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).
text-overflow: ellipsis ellipsis
, demonstrated:
If there is insufficient space for both start and end ellipses/strings, then only the end ellipsis/string should be rendered.
5. Fragmentation of overflow
The continue property gives authors the ability to request that content that does not fit inside an element be fragmented (in the sense of [CSS3-BREAK]), and provides alternatives for where the remaining content should continue.
Notably, this property explains traditional pagination, and extends it further.
Name: | continue |
---|---|
Value: | auto | overflow | paginate | fragments | discard |
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 |
Canonical order: | per grammar |
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.
- overflow
- Content that doesn’t fit overflows, according to the overflow property
- discard
-
Content that doesn’t fit is discarded at a fragmentation break
Note: generalized from region-fragment: break; on the last region of a region chain
When the element isn’t a fragmentation container already, should this work by turning it directly into one, or by creating a fragment box inside it like fragments does?
- 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.
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:
- 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.
-
Otherwise, if the specified value is auto
- On a CSS Region other than the last one in a region chain, the computed value is auto
- On a page the computed value is paginate
- On a fragment box the computed value is fragments
- Otherwise, the computed value is overflow
-
Otherwise, if the specified value is fragments
- On a page the computed value is paginate
- Otherwise, the computed value is the specified value
- 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
6. Paginated overflow
This section introduces and defines the meaning of the paginate value of the continue property.
Pages should be possible to style with @page rules. How does that work for nested pages?
@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. http://www.w3.org/mid/FF1704C5-D5C1-4D6F-A99D-0DD094036685@gmail.com
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.
7. Fragment 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 [CSS3COL] though it defines multi-column container) any content that would lead to the creation of overflow columns [CSS3COL] 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.
|
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. |
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 [CSS3-REGIONS], and the work done on a model there, and the editors of that specification, should inform what happens in this specification.
7.1. Fragment styling
7.1.1. 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.
7.1.2. 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?
|
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.
|
The
font-size propertyspecified 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. |
7.1.3. 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:
- the declarations are for properties that apply to the ::first-letter pseudo-element,
- 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
- 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.
|
7.2. The max-lines property
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, this specification introduces a max-lines property that 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.
Name: | max-lines |
---|---|
Value: | none | <integer> |
Initial: | none |
Applies to: | fragment boxes |
Inherited: | no |
Percentages: | N/A |
Computed value: | the keyword none or an integer |
Canonical order: | per grammar |
Animatable: | as integer |
Animation type: | by computed value type |
- none
-
Breaks occur only as specified elsewhere.
- <integer>
-
In addition to any breaks specified elsewhere, a break is forced before any line that would exceed the given number of lines being placed inside the element (excluding lines that are in a different block formatting context from the block formatting context to which an unstyled child of the element would belong).
If there are multiple boundaries between this line and the previous, where exactly (in terms of element boundaries) is the break forced?
Only positive integers are accepted. Zero or negative integers are a parse error.
Should this apply to fragment overflow only, or also to pagination? Given what we’re doing with the continue property, it should actually apply to any fragmentainer.
having max-lines do nothing on regular elements is not ideal. When applied to non fragmentainers, it should probably cause continue to compute to discard so that you only need to reach for one property rather than 2 to get that effect.
|
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). |
Appendix A: 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.
-
scrollbar-gutter: always force on the header/toolbar
-
scrollbar-gutter: always on the scroll container
-
scrollbar-gutter: match-parent on each row inside the scroll container
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, , 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.
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:
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
orscrollbar-avoid: content
on the relevant children. - force
-
When the force keyword is present stable and always take effect
when overflow is visible, 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).
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.
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.
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 | ||
auto | |||||
stable | yes | yes | |||
always | yes | yes | yes | ||
visible, clip | auto | ||||
stable | if force | if force | |||
always | if force | if force | if force |
Appendix B: Privacy and Security Considerations
This specification introduces no new security considerations.
The TAG has developed a self-review questionnaire to help editors and Working Groups evaluate the risks introduced by their specifications. Answers are provided below.
- Does this specification deal with personally-identifiable information?
- No.
- Does this specification deal with high-value data?
- No.
- Does this specification introduce new state for an origin that persists across browsing sessions?
- No.
- Does this specification expose persistent, cross-origin state to the web?
- No.
- Does this specification expose any other data to an origin that it doesn’t currently have access to?
- No.
- Does this specification enable new script execution/loading mechanisms?
- No.
- Does this specification allow an origin access to a user’s location?
- No.
- Does this specification allow an origin access to sensors on a user’s device?
- No.
- Does this specification allow an origin access to aspects of a user’s local computing environment?
- No.
- Does this specification allow an origin access to other devices?
- No.
- Does this specification allow an origin some measure of control over a user agent’s native UI?
- No
- Does this specification expose temporary identifiers to the web?
- No.
- Does this specification distinguish between behavior in first-party and third-party contexts?
- No.
- How should this specification work in the context of a user agent’s "incognito" mode?
- No difference in behavior is needed.
- Does this specification persist data to a user’s local device?
- No.
- Does this specification have a "Security Considerations" and "Privacy Considerations" section?
- Yes, this is the section you are currently reading.
- Does this specification allow downgrading default security characteristics?
- No.
Changes
Changes Since Level 3
The following changes were made to this specification since the CSS Overflow Module Level 3:
- The Fragmentation of overflow, Paginated overflow, and Fragment overflow sections and subsections have been removed form Level 3 and moved to Level 4.
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.