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.
Status of this document
This section describes the status of this document at the time of
its publication. Other documents may supersede this document. A list of
current W3C publications and the latest revision of this technical report
can be found in the W3C technical reports
index at http://www.w3.org/TR/.
This document is a First Public Working Draft.
Publication as a First Public Working Draft does not imply endorsement by the W3C
Membership. This is a draft document and may be updated, replaced or
obsoleted by other documents at any time. It is inappropriate to cite this
document as other than work in progress.
The (archived) public
mailing list email@example.com (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…”
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.
1.1. 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.
This specification follows the
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.
2. Motivating Examples
In this example, a series of images arranged in a scroll container
are used to build a photo gallery.
The scroll container 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 scroll container’s visual viewport.
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.
/* Sets up points to which scrolling
will snap along x-axis */
/* Requires that scrolling always end at a snap point when
the operation completes (hard snap) */
This example also builds a photo gallery as in example 1. However, in this example the scroll container
is larger than the photos contained within (such that multiple images may be seen simultaneously), and the image
sizes vary (such that a repeating snap interval would not be effective). Using mandatory element-based snap
points, scrolling will always complete with an image centered in the scroll container’s visual viewport.
/* Defines the center of each photo as the
coordinate that should be used for snapping */
scroll-snap-coordinate: 50% 50%;
/* 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). */
This example builds a paginated document that aligns each page near to (but not exactly on) the edge of the scroll container.
This allows the previous page to "peek" in from above in order to make the user aware that they are not yet at the top of the document.
Using proximity snap points instead of mandatory snap points allows the user to stop halfway through a page (rather than forcing them
to snap one page at a time). However, if a scrolling operation would finish near a snap point, then the scroll will be adjusted to
align the page as specified.
/* Defines the top center of each page as the
coordinate that should be used for snapping */
scroll-snap-coordinate: 50% 0;
/* 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 */
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.
The visual viewport of this scroll container must ignore snap points, if any, when scrolled.
The visual viewport of this scroll container is guaranteed to rest on a snap point when there are no active scrolling operations. That is, it must come to rest on a snap point at the termination of a scroll, if possible. If the content changes such that the visual viewport would no longer rest on a snap point (e.g. content is added, moved, deleted, resized), the scroll offset must be modified to maintain this guarantee.
The visual viewport of this scroll container 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. If the content changes such that the visual viewport would no longer rest on a snap point (e.g. content is added, moved, deleted, resized), the scroll offset may be modified to maintain this guarantee.
Describe the guarantee as an invariant for better clarity. Include edge case behavior such as mandatory snap points when there is no satisfiable snap point.
Specifies the offset of the snap destination from the start edge of the scroll container’s visual viewport. The first value gives the x coordinate of the snap destination, the second value its y coordinate.
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.
Specifies the offset of the snap coordinates from the start edge of the element’s border box. For each pairing, the first value gives the x coordinate of the snap coordinate, the second value its y coordinate.
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",
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
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
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