CSS Scroll Snap Points Module Level 1

[LONGSTATUS]

This version:
[VERSION]
Latest version:
http://www.w3.org/TR/css-snappoints/
Issue Tracking:
http://wiki.csswg.org/spec/css-snappoints
Feedback:
www-style@w3.org with subject line “[css-snappoints] … message topic …” (archives)
Editors:
Matt Rakow, Microsoft Corporation
Jacob Rossi, Microsoft Corporation

Abstract

CSS is a language for describing the rendering of structured documents (such as HTML and XML) on screen, on paper, in speech, etc. This module contains the features of CSS to control panning and scrolling behavior with "snap points."

Status of this document

Table of Contents

Introduction

This section is not normative.

Popular UX paradigms for scrollable content frequently employ pagination of content, or sectioning into logical divisions. This is especially true for touch interactions where it is quicker and easier for users to quickly pan through a flatly-arranged breadth of content rather than delving into a heirarchical structure through tap navigation. For example, it is easier for a user view many photos in a photo album by panning through a photo slideshow view rather than tapping on individual photos in an album.

However, given the imprecise nature of scrolling inputs like touch panning and mousewheel scrolling, it is difficult for web developers to guarantee a well-controlled scrolling experience, in particular creating the effect of pagination. For instance, it is easy for a user to land at an awkward scroll offset which leaves a page partially on-screen when panning.

To this end, we introduce scroll snap points which enforce the scroll offsets that a scroller may end at after a scrolling operation has completed.

Module interactions

This module extends the scrolling user interface features defined in [[!CSS21]] section 11.1.

None of the properties in this module apply to the ::first-line and ::first-letter pseudo-elements.

Values

This specification follows the CSS property definition conventions from [[!CSS21]]. Value types not defined in this specification are defined in CSS Level 2 Revision 1 [[!CSS21]]. Other CSS modules may expand the definitions of these value types: for example [[CSS3VAL]], when combined with this module, expands the definition of the <length> value type as used in this specification.

In addition to the property-specific values listed in their definitions, all properties defined in this specification also accept the inherit keyword as their property value. For readability it has not been repeated explicitly.

Examples

In this example, a series of images arranged in a scroller are used to build a photo gallery. The scroller is sized to the same size of the images contained therein. Using mandatory snap points, scrolling will always complete with a snap point aligned to the edge of the scroller. By aligning a snap point at the edge of each image, this creates a photo viewer were users can scroll through the images one at a time.

img {
    width:500px;
}
.photoGallery {
    width: 500px;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    scroll-snap-points-x: snapInterval(0px,100%); /*Sets up points to which scrolling will snap along x-axis */
    scroll-snap-type: mandatory; /* requires that scrolling always end at a snap point when the operation completes (hard snap) */
}
<div class="photoGallery"> <img src="img1.jpg"><img src="img2.jpg"><img src="img3.jpg"><img src="img4.jpg"><img src="img5.jpg"> </div>

The layout of the scroller's contents in the example. Snap points are set along the x-axis, starting at 0px and repeating at intervals of 100% of the containing block's width.

The layout of the scroller's contents in the example. Snap points are set along the x-axis, starting at 0px and repeating at intervals of 100% of the containing block's width.

Definitions

scroller
An element which provides a scrolling user interface as described in [[!CSS21]], particularly in the section on overflow.

Scroll Snap Types: the 'scroll-snap-type' property

The ''scroll-snap-type'' property is used to define the physics characteristics of panning and scrolling, if any. It defines how and when snap points are enforced on the scroller it is applied to.

Name: scroll-snap-type
Value: none | mandatory | proximity
Initial: none
Applies to: block-level scrollers
Inherited: no
Percentages: N/A
Media: interactive
Computed value: specified value
Animatable: no
Canonical order: per grammar
''none''
This scroller must ignore snap points, if any, when scrolled.
''mandatory''
This scroller must come to rest on a snap point at the termination of a scroll, if possible.
''proximity''
This scroller may come to rest on a snap point at the termination of a scroll at the discretion of the UA given the parameters of the scroll.

Scroll Snap Points: the 'scroll-snap-points-x' and 'scroll-snap-points-y properties

The ''scroll-snap-points-x'' and ''scroll-snap-points-y'' properties are used to define the positioning of snap points within the content of the scroller they are applied to.

Name: scroll-snap-points-x, scroll-snap-points-y
Value: snapInterval(,) | snapList([,]*)
Initial: snapInterval(0px, 100%)
Applies to: block-level scrollers
Inherited: no
Percentages: Refer to the padding-box of the scroller
Media: interactive
Computed value: specified value
Animatable: no
Canonical order: per grammar
''snapList(point1,point2,…)''
Defines one or more discrete snap points for the scroller.
''snapInterval(start, interval) ''
Defines a starting snap point and an interval at which additional snap points are defined. The first argument is the starting snap point and the second argument is the interval to repeat thereafter.

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:

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.

Conformance classes

Conformance to CSS Scroll Snap Points Module 1 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 CSS Scroll Snap Points Module 1 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 CSS Scroll Snap Points Module 1 if, in addition to interpreting the style sheet as defined by the appropriate specifications, it supports all the features defined by CSS Scroll Snap Points Module 1 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 CSS Scroll Snap Points Module 1 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 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 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.

Experimental implementations

To avoid clashes with future CSS features, the CSS2.1 specification reserves a prefixed syntax for proprietary and experimental extensions to CSS.

Prior to a specification reaching the Candidate Recommendation stage in the W3C process, all implementations of a CSS feature are considered experimental. The CSS Working Group recommends that implementations use a vendor-prefixed syntax for such features, including those in W3C Working Drafts. This avoids incompatibilities with future changes in the draft.

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 at http://www.w3.org/Style/CSS/Test/. Questions should be directed to the public-css-testsuite@w3.org mailing list.

Acknowledgments

Many thanks to lots of people for their proposals and recommendations, some of which are incorporated into this document.

References

Normative references

Other references

Index

Property index