CSS Overscroll Behavior Module Level 1

Editor’s Draft,

More details about this document
This version:
https://drafts.csswg.org/css-overscroll-1/
Latest published version:
https:// w3.org/TR/css-overscroll-1/
Feedback:
CSSWG Issues Repository
Editors:
(Facebook)
(Google)
Suggest an Edit for this Spec:
GitHub Editor

Abstract

This module definesoverscroll-behaviorto control the behavior when the scroll position of ascroll containerreaches the edge of thescrollport. This allows content authors to hint that theboundary default actions, such as scroll chaining and overscroll, should not be triggered.

CSSis a language for describing the rendering of structured documents (such as HTML and XML) on screen, on paper, 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.

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

This document is governed by the03 November 2023 W3C Process Document.

1.Introduction

This section is not normative.

A content author does not necessarily wantscroll chainingto occur for allscroll containers.Somescroll containersmay be part of acontaining block chainbut may serve a different logical purpose in the document and may want to prevent scrolling from continuing up thescroll chain.To achieve this, a content author will install event listeners without thepassive flagset and will usepreventDefault()when there is a risk that scroll chaining will occur. This is detrimental for the following reasons:

Thus, it is not possible for a content author to controlscroll chainingand overscroll in a robust, performant and forward compatible way. Theoverscroll-behaviorproperty fixes this shortcoming.

1.1.Value Definitions

This specification follows theCSS property definition conventionsfrom[CSS2]using thevalue definition syntaxfrom[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 theCSS-wide keywordsas their property value. For readability they have not been repeated explicitly.

2.Motivating Examples

A position fixed left navigation bar does not want to hand off scrolling to the document because a scroll gesture performed on the navigation bar is almost never meant to scroll the document. Note that using the native overscroll affordances are still desirable while scroll chaining is to be prevented.
#sidebar{
overscroll-behavior:contain;
}

In this case, the author can usecontainon the sidebar to prevent scrolling from being chained to the parent document element.

A page wants to implement their own pull-to-refresh effect and thus needs to disable browser native overscroll action.
html{
/* only disable pull-to-refresh but allow swipe navigations */
overscroll-behavior-y: contain;
}

In this case, the author can usecontainon the viewport defining element to prevent overscroll from triggering navigation actions.

A infinite scrollers loads more content as user reaches the boundary and thus wants to disable the potentially confusing rubber banding effect in addition to scroll chaining.
#infinite_scroller{
overscroll-behavior-y:none;
}

In this case the author can usenoneon the infinite scroller to prevent both scroll chaining and overscroll affordance.

3.Scroll chaining and boundary default actions

Operating Systems have rules for scrolling such as scroll chaining and overscroll affordances. This specification does not mandate if and how scroll chaining or overscroll affordances be implemented. This specification only allows the content author to disable them if any are implemented.

Scroll chainingis when scrolling is propagated from onescroll containerto an ancestorscroll containerfollowing thescroll chain.Typically scroll chaining is performed starting at the event target recursing up thecontaining block chain.When ascroll containerin this chain receives a scroll event or gesture it may act on it and/or pass it up the chain. Chaining typically occurs when thescrollporthas reached its boundary.

Ascroll chainis the order in which scrolling is propagated from onescroll containerto another. Theviewportparticipates inscroll chainingas the document’sscrollingElement,both regarding placement in the scroll chain as well as adhering to the chaining rules applied to it.

Scroll boundaryrefers to when the scroll position of ascroll containerreaches the edge of thescrollport.If a scroll container has no potential to scroll, because it does notoverflowin the direction of the scroll, the element is always considered to be at the scroll boundary.

Boundary default actionrefers to the user-agent-defineddefault actionperformed when scrolling against the edge of thescrollport.Alocal boundary default actionis aboundary default actionwhich is performed on thescroll containerwithout interacting with the page, for example displaying a overscroll UI affordance. Conversely, anon-local boundary default actioninteracts with the page, for example scroll chaining or a navigation action.

4.Overscroll Behavior Properties

Theoverscroll behaviorcontrols the permittedboundary default actionfor ascroll containerelement when itsscrollportreaches the boundary of its scroll box.

Theoverscroll-behaviorproperty specifies theoverscroll behaviorfor ascroll containerelement. It allows the content author to specify that ascroll containerelement must prevent scroll chaining and/or overscroll affordances.

An element that is notscroll containermust accept but ignore the values of this property. This property must be applied to all scrolling methods supported by the user agent.

Note:This property should provide guarantees that are, at least, as strong aspreventDefaultfor preventing both scroll chaining and overscroll. Doing otherwise would cause content authors to usepreventDefaultinstead.

Name: overscroll-behavior
Value: [ contain|none|auto ]{1,2}
Initial: auto auto
Applies to: scroll containerelements
Inherited: no
Percentages: n/a
Computed value: see individual properties
Canonical order: per grammar
Animation type: discrete
Media: visual

Theoverscroll-behaviorproperty is a shorthand property that sets the specified values ofoverscroll-behavior-xandoverscroll-behavior-yin that order. If only one value is specified, the second value defaults to the same value.

Values have the following meanings:

contain
This value indicates that the element must not performnon-local boundary default actionssuch as scroll chaining or navigation. The user agent must not perform scroll chaining to any ancestors along thescroll chainregardless of whether the scroll originated at this element or one of its descendants. This value must not modify the behavior of howlocal boundary default actionsshould behave, such as showing any overscroll affordances.
none
This value implies the same behavior ascontainand in addition this element must also not performlocal boundary default actionssuch as showing any overscroll affordances.
auto
This value indicates that the user agent should perform the usualboundary default actionwith respect toscroll chaining,overscroll and navigation gestures.

Note:In the case where a user agent does not implement scroll chaining and overscroll affordances, these values will have no side effects for a compliant implementation.

Note:Programmatic scrolling is clamped and can not trigger anyboundary default actions.

4.1.Overscroll and Positioned Elements

This specification does not generally dictate what, if any, "overscroll" or similar actions might occur as alocal boundary default action.

However, if a user agentdoesuse "overscroll" behavior (that is, allowing a scrollable element to be scrolled slightly "past the end" of its scrollable area, usually with a "rubber-banding" effect after the scroll or drag is completed), then the following applies:

If an element usesfixed positioningand is positioned relative to theinitial containing block, or is asticky positionedelement which is currently stuck to theviewport, then when theroot scrollerexperiences "overscroll", that elementmust notoverscroll with the rest of the document’s content; it must instead remain positioned as if the scroller was at its minimum/maximum scroll position, whichever it will return to when the overscroll is finished.

Even tho this can visually shift the fixed/sticky element relative to other elements on the page, it must be treated purely as a visual effect, and not reported as an actual layout/position change to APIs such asgetBoundingClientRect().

Note:This behavior is because fixpos and viewport-stuck stickypos elements are positioned relative to "the viewport", which is conceptually above the root scroller in the page hierarchy (effectively, it’s thescroll containerholding the root scroller). Thus, overscrolling the root scroller shouldn’t have any effect on them, just like how an abspos that is a child of a scroller but whose abspos containing block isabovethe scroller isn’t affected by the scroller doing anything at all, including overscroll.

4.2.Physical Longhands foroverscroll-behavior

Name: overscroll-behavior-x,overscroll-behavior-y
Value: contain|none|auto
Initial: auto
Applies to: scroll containerelements
Inherited: no
Percentages: N/A
Computed value: as specified
Canonical order: per grammar
Animation type: discrete
Logical property group: overscroll-behavior
Media: visual

Theoverscroll-behavior-xproperty specifies theoverscroll behaviorin the horizontal axis and theoverscroll-behavior-yproperty specifies theoverscroll behaviorin the vertical axis. When scrolling is performed along both the horizontal and vertical axes at the same time, theoverscroll behaviorof each respective axis should be considered independently.

4.3.Flow-relative Longhands foroverscroll-behavior

Name: overscroll-behavior-inline,overscroll-behavior-block
Value: contain|none|auto
Initial: auto
Applies to: scroll containerelements
Inherited: no
Percentages: N/A
Computed value: as specified
Canonical order: per grammar
Animation type: discrete
Logical property group: overscroll-behavior
Media: visual

These properties correspond to theoverscroll-behavior-xandoverscroll-behavior-yproperties. The mapping depends on the element’swriting-mode.

5.Security and Privacy Considerations

There are no known security or privacy impacts of this feature. The feature may be used to prevent certain native UI features such as overscroll affordances and overscroll navigations (e.g., pull- to-refresh, swipe navigations). However, this does not expose any additional abilities beyond what is already possible in the platform e.g., by preventing the default action of the event that would cause a scroll.

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 withclass= "example", like this:

This is an example of an informative example.

Informative notes begin with the word “Note” and are set apart from the normative text withclass= "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.

Tests

Tests relating to the content of this specification may be documented in “Tests” blocks like this one. Any such block is non-normative.


Conformance classes

Conformance to this specification is defined for three conformance classes:

style sheet
ACSS style sheet.
renderer
AUAthat interprets the semantics of a style sheet and renders documents that use them.
authoring tool
AUAthat writes a style sheet.

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

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

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

Partial implementations

So that authors can exploit the forward-compatible parsing rules to assign fallback values, CSS renderersmusttreat as invalid (andignore 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 agentsmust notselectively ignore unsupported component values and honor supported values in a single multi-value property declaration: if any value is considered invalid (as unsupported values must be), CSS requires that the entire declaration be ignored.

Implementations of Unstable and Proprietary Features

To avoid clashes with future stable CSS features, the CSSWG recommendsfollowing best practicesfor the implementation ofunstablefeatures andproprietary extensionsto CSS.

Non-experimental implementations

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

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

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

Index

Terms defined by this specification

Terms defined by reference

References

Normative References

[CSS-DISPLAY-4]
CSS Display Module Level 4.Editor's Draft. URL:https://drafts.csswg.org/css-display-4/
[CSS-OVERFLOW-3]
Elika Etemad; Florian Rivoal.CSS Overflow Module Level 3.URL:https://drafts.csswg.org/css-overflow-3/
[CSS-POSITION-3]
Elika Etemad; Tab Atkins Jr..CSS Positioned Layout Module Level 3.URL:https://drafts.csswg.org/css-position-3/
[CSS-VALUES-3]
Tab Atkins Jr.; Elika Etemad.CSS Values and Units Module Level 3.URL:https://drafts.csswg.org/css-values-3/
[CSS-VALUES-4]
Tab Atkins Jr.; Elika Etemad.CSS Values and Units Module Level 4.URL:https://drafts.csswg.org/css-values-4/
[CSS-WRITING-MODES-4]
Elika Etemad; Koji Ishii.CSS Writing Modes Level 4.URL:https://drafts.csswg.org/css-writing-modes-4/
[CSS2]
Bert Bos; et al.Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification.URL:https://drafts.csswg.org/css2/
[CSSOM-VIEW-1]
Simon Pieters.CSSOM View Module.URL:https://drafts.csswg.org/cssom-view/
[DOM]
Anne van Kesteren.DOM Standard.Living Standard. URL:https://dom.spec.whatwg.org/
[EPUB-33]
Ivan Herman; Matt Garrish; Dave Cramer.EPUB 3.3.URL:https://w3c.github.io/epub-specs/epub33/core/
[RFC2119]
S. Bradner.Key words for use in RFCs to Indicate Requirement Levels.March 1997. Best Current Practice. URL:https://datatracker.ietf.org/doc/html/rfc2119

Informative References

[TOUCH-EVENTS]
Doug Schepers; et al.Touch Events.URL:https://w3c.github.io/touch-events/

Property Index

Name Value Initial Applies to Inh. %ages Anim­ation type Canonical order Com­puted value Logical property group Media
overscroll-behavior [ contain | none | auto ]{1,2} auto auto scroll container elements no n/a discrete per grammar see individual properties visual
overscroll-behavior-block contain | none | auto auto scroll container elements no N/A discrete per grammar as specified overscroll-behavior visual
overscroll-behavior-inline contain | none | auto auto scroll container elements no N/A discrete per grammar as specified overscroll-behavior visual
overscroll-behavior-x contain | none | auto auto scroll container elements no N/A discrete per grammar as specified overscroll-behavior visual
overscroll-behavior-y contain | none | auto auto scroll container elements no N/A discrete per grammar as specified overscroll-behavior visual
MDN

overscroll-behavior-block

In all current engines.

Firefox73+Safari16+Chrome77+
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?

overscroll-behavior-inline

In all current engines.

Firefox73+Safari16+Chrome77+
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
MDN

overscroll-behavior-x

In all current engines.

Firefox59+Safari16+Chrome63+
Opera?Edge79+
Edge (Legacy)18IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?

overscroll-behavior-y

In all current engines.

Firefox59+Safari16+Chrome63+
Opera?Edge79+
Edge (Legacy)18IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
MDN

overscroll-behavior

In all current engines.

Firefox59+Safari16+Chrome63+
Opera?Edge79+
Edge (Legacy)18IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?