CSS Overscroll Behavior Module Level 1

Draft Community Group Report,

This version:
https://wicg.github.io/scroll-boundary-behavior/
Issue Tracking:
GitHub
Editor:
(Facebook)

Abstract

This module defines overscroll-behavior to control the behavior when the scroll position of a scroll container reaches the edge of the scrollport. This allows content authors to hint that the boundary default actions, such as scroll chaining and overscroll, should not be triggered.

Status of this document

This specification was published by the Web Platform Incubator Community Group. It is not a W3C Standard nor is it on the W3C Standards Track. Please note that under the W3C Community Contributor License Agreement (CLA) there is a limited opt-out and other conditions apply. Learn more about W3C Community and Business Groups.

1. Introduction

This section is not normative.

A content author does not necessarily want scroll chaining to occur for all scroll containers. Some scroll containers may be part of a containing block chain but may serve a different logical purpose in the document and may want to prevent scrolling from continuing up the scroll chain. To achieve this, a content author will install event listeners without the passive flag set and will use preventDefault 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 control scroll chaining and overscroll in a robust, performant and forward compatible way. The overscroll-behavior property fixes this shortcoming.

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 use contain on 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 use contain on 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 the author can use none on 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 chaining is when scrolling is propagated from one scroll container to an ancestor scroll container following the scroll chain. Typically scroll chaining is performed starting at the event target recursing up the containing block chain. When a scroll container in this chain receives a scroll event or gesture it may act on it and/or pass it up the chain. Chaining typically occurs when the scrollport has reached its boundary.

A scroll chain is the order in which scrolling is propagated from one scroll container to another.

Scroll boundary refers to when the scroll position of a scroll container reaches the edge of the scrollport. If a scroll container has no potential to scroll, because it does not overflow in the direction of the scroll, the element is always considered to be at the scroll boundary.

Boundary default action refers to the user-agent-defined default action performed when scrolling against the edge of the scrollport. A local boundary default action is a boundary default action which is performed on the scroll container without interacting with the page, for example displaying a overscroll UI affordance. Conversely, a non-local boundary default action interacts with the page, for example scroll chaining or a navigation action.

4. Overview

This module introduces control over the behavior of a scroll container element when its scrollport reaches the boundary of its scroll box. It allows the content author to specify that a scroll container element must prevent scroll chaining and/or overscroll affordances.

5. Overscroll Behavior Properties

These properties specify how a scroll container element must behave when scrolling. A element that is not scroll container must accept but ignore the values of this property. This property must be applied to all input methods supported by the user agent.

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

Name: overscroll-behavior-x, overscroll-behavior-y
Value: contain | none | auto
Initial: auto
Applies to: scroll container elements
Inherited: no
Percentages: N/A
Media: visual
Computed value: as specified
Canonical order: per grammar
Animatable: no

The overscroll-behavior-x property specifies the behavior of the overscroll-behavior in the horizontal direction and the overscroll-behavior-y property specifies the handling of the overscroll-behavior in the vertical direction. When scrolling is performed along both the horizontal and vertical axes at the same time, the overscroll-behavior of each respective axis should be considered independently.

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

The two values specify the behavior in the horizontal and vertical direction, respectively. 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 perform non-local boundary default actions such as scroll chaining or navigation. The user agent must not perform scroll chaining to any ancestors along the scroll chain regardless of whether the scroll originated at this element or one of its descendants. This value must not modify the behavior of how local boundary default actions should behave, such as overscroll behavior.
none
This value implies the same behavior as contain and in addition this element must also not perform local boundary default actions such as showing any overscroll affordances.
auto
This value indicates that the user agent should perform the usual boundary default action with respect to scroll 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 any boundary default actions.

6. 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

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:

This is an example of an informative example.

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.

Index

Terms defined by this specification

Terms defined by reference

References

Normative References

[CSS-OVERFLOW-3]
David Baron; Florian Rivoal. CSS Overflow Module Level 3. URL: https://www.w3.org/TR/css-overflow-3/
[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

Property Index

Name Value Initial Applies to Inh. %ages Media Ani­mat­able Canonical order Com­puted value
overscroll-behavior [ contain | none | auto ]{1,2} auto auto scroll container elements no n/a visual no per grammar see individual properties
overscroll-behavior-x contain | none | auto auto scroll container elements no N/A visual no per grammar as specified
overscroll-behavior-y contain | none | auto auto scroll container elements no N/A visual no per grammar as specified