Copyright © 2014 W3C® (MIT, ERCIM, Keio, Beihang), All Rights Reserved. W3C liability, trademark and document use rules apply.
This module contains features to control panning and scrolling behavior with "snap points".
CSS is a language for describing the rendering of structured documents (such as HTML and XML) on screen, on paper, in speech, etc.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.
The (archived) public mailing list www-style@w3.org (see instructions) is preferred for discussion of this specification. When sending e-mail, please put the text “css-snappoints” in the subject, preferably like this: “[css-snappoints] …summary of comment…”
This document was produced by the CSS Working Group (part of the Style Activity).
This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.
This document is governed by the 1 August 2014 W3C Process Document.
This section is not normative.
Popular UX paradigms for scrollable content frequently employ paging through 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 to 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 paging through content. 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 scroll container’s visual viewport may end at after a scrolling operation has completed.
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.
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.
img {
width:500px;
}
.photoGallery {
width: 500px;
overflow-x: auto;
overflow-y: hidden;
white-space: nowrap;
/* Sets up points to which scrolling
will snap along x-axis */
scroll-snap-points-x: repeat(100%);
/* Requires that scrolling always end at a snap point when
the operation completes (hard snap) */
scroll-snap-type: mandatory;
}
<div class="photoGallery">
<img src="img1.jpg">
<img src="img2.jpg">
<img src="img3.jpg">
<img src="img4.jpg">
<img src="img5.jpg">
</div>
img {
/* Defines the center of each photo as the
coordinate that should be used for snapping */
scroll-snap-coordinate: 50% 50%;
}
.photoGallery {
width: 500px;
overflow-x: auto;
overflow-y: hidden;
white-space: nowrap;
/* Specifies that each element’s snap coordinate should
align with the center of the scroll container */
scroll-snap-destination: 50% 50%;
/* Requires that scrolling always end at a snap point
when the operation completes (hard snap). */
scroll-snap-type: mandatory;
}
<div class="photoGallery">
<img src="img1.jpg">
<img src="img2.jpg">
<img src="img3.jpg">
<img src="img4.jpg">
<img src="img5.jpg">
</div>
.page {
/* Defines the top center of each page as the
coordinate that should be used for snapping */
scroll-snap-coordinate: 50% 0;
}
.docScroller {
width: 500px;
overflow-x: hidden;
overflow-y: auto;
/* Specifies that each element’s snap coordinate should
align with the center of the scroll container, offset
a short distance from the top edge. */
scroll-snap-destination: 50% 100px;
/* Encourages scrolling to end at a snap point when the
operation completes, if it is near a snap point */
scroll-snap-type: proximity;
}
<div class="docScroller">
<div class="page">Page 1</div>
<div class="page">Page 2</div>
<div class="page">Page 3</div>
<div class="page">Page 4</div>
</div>
The scroll-snap-type property is used to define how strictly snap points are enforced on the scroll container, if any are present. It defines how and when snap points are enforced on the visual viewport of the scroll container it is applied to in order to adjust scroll offset. It intentionally does not specify nor mandate any precise animations or physics used to enforce those snap points; this is left up to the user agent.
| Name: | scroll-snap-type |
|---|---|
| Value: | none | mandatory | proximity |
| Initial: | none |
| Applies to: | scroll containers |
| Inherited: | no |
| Percentages: | n/a |
| Media: | interactive |
| Computed value: | specified value |
| Animatable: | no |
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 scroll container they are applied to.
| Name: | scroll-snap-points-x, scroll-snap-points-y |
|---|---|
| Value: | none | repeat(<length>) |
| Initial: | none |
| Applies to: | scroll containers |
| Inherited: | no |
| Percentages: | relative to same axis of the padding-box of the scroll container |
| Media: | interactive |
| Computed value: | specified value, with lengths made absolute |
| Animatable: | no |
The scroll-snap-destination property is used to define the x and y coordinate within the scroll container’s visual viewport which element snap points will align with.
| Name: | scroll-snap-destination |
|---|---|
| Value: | <position> |
| Initial: | 0px 0px |
| Applies to: | scroll containers |
| Inherited: | no |
| Percentages: | relative to width and height of the padding-box of the scroll container |
| Media: | interactive |
| Computed value: | specified value, with lengths made absolute |
| Animatable: | yes |
The scroll-snap-coordinate property is used to define the x and y coordinate within the element which will align with the nearest ancestor scroll container’s snap-destination for the respective axis. In the case that the element has been transformed, the snap coordinate is also transformed in the same way (such that the snap-point is aligned with the element as-drawn).
How does this work with fragmentation?
Consider alternative naming besides "coordinate". Consider naming conventions like in Grid Layout for grouping properties on the container vs. items.
| Name: | scroll-snap-coordinate |
|---|---|
| Value: | none | <position># |
| Initial: | none |
| Applies to: | all elements |
| Inherited: | no |
| Percentages: | refer to the element’s border box |
| Media: | interactive |
| Computed value: | specified value, with lengths made absolute |
| Animatable: | yes |
How can an alternative box be specified?
Many thanks to lots of people for their proposals and recommendations, some of which are incorporated into this document.
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.
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.
Conformance to this specification is defined for three conformance classes:
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.
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.
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.
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.
| Name | Value | Initial | Applies to | Inh. | %ages | Media | Animatable | Computed value |
|---|---|---|---|---|---|---|---|---|
| scroll-snap-type | none | mandatory | proximity | none | scroll containers | no | n/a | interactive | no | specified value |
| scroll-snap-points-x | none | repeat(<length>) | none | scroll containers | no | relative to same axis of the padding-box of the scroll container | interactive | no | specified value, with lengths made absolute |
| scroll-snap-points-y | none | repeat(<length>) | none | scroll containers | no | relative to same axis of the padding-box of the scroll container | interactive | no | specified value, with lengths made absolute |
| scroll-snap-destination | <position> | 0px 0px | scroll containers | no | relative to width and height of the padding-box of the scroll container | interactive | yes | specified value, with lengths made absolute |
| scroll-snap-coordinate | none | <position># | none | all elements | no | refer to the element’s border box | interactive | yes | specified value, with lengths made absolute |