CSS Scroll Snap Module Level 1

Editor’s Draft,

More details about this document
This version:
https://drafts.csswg.org/css-scroll-snap-1/
Latest published version:
https://www.w3.org/TR/css-scroll-snap-1/
Previous Versions:
Implementation Report:
https://wpt.fyi/results/css/css-scroll-snap
Feedback:
CSSWG Issues Repository
Editors:
Matt Rakow(Microsoft)
Jacob Rossi(Microsoft)
Tab Atkins-Bittner(Google)
Elika J. Etemad / fantasai(Apple)
Suggest an Edit for this Spec:
GitHub Editor

Abstract

This module contains features to control panning and scrolling behavior with “snap positions”.

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-scroll-snap” in the title, like this: “[css-scroll-snap]…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.

A test suite and an implementation report will be produced during the CR period.

The following features are at-risk, and may be dropped during the CR period:

“At-risk” is a W3C Process term-of-art, and does not necessarily imply that the feature is in danger of being dropped or delayed. It means that the WG believes the feature may have difficulty being interoperably implemented in a timely manner, and marking it as such allows the WG to drop the feature if necessary when transitioning to the Proposed Rec stage, without having to publish a new Candidate Rec without the feature first.

1.Introduction

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 hierarchical 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 position which leaves an item partially on-screen when panning.

To this end, this module introducesscroll snap positionswhich enforce the scroll positions that ascroll container’sscrollport may end at after a scrolling operation has completed.

Also, to offer better control over paging and scroll positioning even when snapping is off, this module defines thescroll-paddingproperty for use on allscroll containers, to adjust thescroll container’soptimal viewing regionfor the purpose of paging and scroll-into-view operations. Similarly thescroll-marginproperty can be used on any box to adjust its visual area for the purpose of scroll-into-view operations.

1.1.Module interactions

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

None of the properties in this module apply to the::first-lineand::first-letterpseudo-elements.

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

In this example, a series of images arranged in ascroll containerare used to build a photo gallery. In this example thescroll containeris larger than the photos contained within (such that multiple images may be seen simultaneously), and the image sizes vary. Using mandatory element-based snap positions, scrolling will always complete with an image centered in thescroll container’sscrollport.
img{
/* Specifies that the center of each photo
should align with the center of the scroll
container in the X axis when snapping */
scroll-snap-align: none center;
}
.photoGallery{
width:500px;
overflow-x:auto;
overflow-y:hidden;
white-space:nowrap;
/* Requires that the scroll position always be
at a snap position when the scrolling
operation completes. */
scroll-snap-type: x mandatory;
}
<divclass="photoGallery">
<imgsrc="img1.jpg">
<imgsrc="img2.jpg">
<imgsrc="img3.jpg">
<imgsrc="img4.jpg">
<imgsrc="img5.jpg">
</div>
The layout of the scroll container’s contents in the example. The snapport is represented by the red rectangle, and the snap area is represented by the yellow rectangle. Since the scroll-snap-align is “center” in the inline (horizontal) axis, a snap position is established at each scroll position which aligns the X-center of the snapport (represented by a red dotted line) with the X-center of a snap area (represented by a yellow dotted line).
This example builds a paginated document that aligns each page near to (but not exactly on) the edge of thescroll 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 positions instead of mandatory snap positions 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 position, then the scroll will be adjusted to align the page as specified.
.page{
/* Defines the top of each page as the
edge that should be used for snapping */
scroll-snap-align: start none;
}
.docScroller{
width:500px;
overflow-x:hidden;
overflow-y:auto;
/* Specifies that each element’s snap area should
align with a 100px offset from the top edge. */
scroll-padding:100px00;
/* Encourages scrolling to end at a snap position when the
operation completes, if it is near a snap position */
scroll-snap-type: y proximity;
}
<divclass="docScroller">
<divclass="page">Page 1</div>
<divclass="page">Page 2</div>
<divclass="page">Page 3</div>
<divclass="page">Page 4</div>
</div>
The layout of the scroll container’s contents in the example. The snapport is represented by the red rectangle (inset from the top by 100px due to the scroll-padding), and the snap area is represented by the yellow rectangle. Since the scroll-snap-align is “start” in the Y axis, a snap position is established at each scroll position which aligns the Y-start of the snapport (represented by a red dotted line) with the Y-start of a snap area (represented by a yellow dotted line).

3.Scroll Snap Model

This module defines controls forscroll snap positions, which are scroll positions that produce particular alignments of content within a scroll container. Using thescroll-snap-typeproperty on the relevantscroll container, the author can request a particular bias for the scrollport to land on asnap positionafter scrolling operations (including programmatic scrolls such as thescrollTo()method).

Snap positionsare specified as a particular alignment (scroll-snap-align) of an element’sscroll snap area(its border bounding box, as modified byscroll-margin) within thescroll container’ssnapport(its scrollport, as reduced byscroll-padding). This is conceptually equivalent to specifying the alignment of analignment subjectwithin analignment container. A scroll position that satisfies the specified alignment is asnap position.

The act of adjusting the scroll position of a scroll container’s scrollport such that it is aligned to a snap area is calledsnapping, and ascroll containermay besnappedto asnap areain each axis if its scrollport is aligned with thatsnap areain that axis and there is no active scrolling operation. When there are multiple valid snap areas, a single one is chosen for each axis whensnappingaccording to the algorithm forselecting between multiple aligned snap areas. The CSS Scroll Snap Module intentionally does not specify nor mandate any precise animations or physics used to enforcesnap positions; this is left up to the user agent.

Snap positionsonly affect the nearest ancestorscroll containeron the element’scontaining block chain.

4.Capturing Scroll Snap Areas: Properties on the scroll container

4.1.Scroll Snapping Rules: thescroll-snap-typeproperty

Name: scroll-snap-type
Value: none|[ x|y|block|inline|both ] [ mandatory|proximity ]?
Initial: none
Applies to: all elements
Inherited: no
Percentages: n/a
Computed value: specified keyword(s)
Canonical order: per grammar
Animation type: discrete

Thescroll-snap-typeproperty specifies whether ascroll containeris ascroll snap container, howstrictlyitsnaps, andwhich axesare considered. If no strictness value is specified,proximityis assumed.

In this example, snapping to headings is enabled in theblock axis(the y axis for horizontal writing, x axis for vertical writing):
html {
scroll-snap-type: block; /* applied to main document scroller */
}
h1, h2, h3, h4, h5, h6 {
scroll-snap-align: start; /* snap to the start (top) of the viewport */
}

UAs must apply thescroll-snap-typevalue set on the root element to the document viewport. Note that, unlikeoverflow,scroll-snap-typevalues arenotpropagated from HTMLbody.

4.1.1.Scroll Snap Axis: thex,y,block,inline,andbothvalues

Theaxis valuesspecify what axis(es) are affected bysnap positions, and whethersnap positionsare evaluated independently per axis, or together as a 2D point. Values are defined as follows:

x
Thescroll containersnapstosnap positionsin its horizontal axis only.
y
Thescroll containersnapstosnap positionsin its vertical axis only.
block
Thescroll containersnapstosnap positionsin its block axis only.
inline
Thescroll containersnapstosnap positionsin its inline axis only.
both
Thescroll containersnapstosnap positionsin both of its axes independently (potentially snapping to different elements in each axis).

4.1.2.Scroll Snap Strictness: thenone,proximity,andmandatoryvalues

Thestrictness values(none,proximity,mandatory) specify how strictlysnap positionsare enforced on thescroll container(by forcing an adjustment to the scroll position). Values are defined as follows:

none
If specified on ascroll container, thescroll containermust notsnap.
mandatory
If specified on ascroll container, thescroll containeris required to besnappedto a snap position when there are no active scrolling operations. If a validsnap positionexists then the scroll container mustsnapat the termination of a scroll (if none exist then nosnappingoccurs).
proximity
If specified on ascroll container, thescroll containermaysnapto a snap position at the termination of a scroll, at the discretion of the UA given the parameters of the scroll.

Authors should use mandatory snap positions with consideration of varyingly-sized screens and (if applicable) varying-sized content. In particular, although access to snapped elements larger than the scrollport is handled by the UA, if authors assign mandatory snapping to non-adjacent siblings, content in between can become inaccessible in cases where it is longer than the screen.

A boxcaptures snap positionsif it is ascroll containerorhas a value other thannoneforscroll-snap-type. If a box’s nearestsnap-position capturingancestor on itscontaining block chainis ascroll containerwith a non-nonevalue forscroll-snap-type, that is the box’sscroll snap container. Otherwise, the box has noscroll snap container, and itssnap positionsdo not triggersnapping.

4.1.3.Re-snapping After Layout Changes

If the content or layout of the document changes (e.g. content is added, moved, deleted, resized) such that the content of asnapportchanges, the UA must re-evaluate the resultingscroll position, and re-snap if required. If thescroll containerwassnappedbefore the content change and those samesnap areasstill exist (e.g. their associated elements were not deleted), the scroll container must be re-snapped to those same snap areas after the content change. Asnap areacan besnappedin each axis, following the algorithm forselecting between multiple aligned snap areas. If it is not possible to snap to both (e.g. if snapping to one resulted in the other being offscreen), it must prefer the focused box, followed by the targeted box, followed by the block axis if neither box is focused or targeted.

Scrolling required by a re-snap operation to a new or different box must behave and animate the same way as any other scroll-into-view operation, including honoring controls such asscroll-behavior. Scrolling behavior for re-snapping to the same box as before however, is UA-defined. The UA may, for example, when snapped to the start of a section, choose not to animate the scroll to the section’s new position as content is dynamically added earlier in the document in order to create the illusion of not scrolling.

In the following example, the log console, when initially loaded and as each message is added to the bottom, remains snapped to the bottom of the content unless the user has scrolled away from that edge:
.log{
scroll-snap-type:y proximity;
align-content:end;
}
.log::after{
display:block;
content:"";
scroll-snap-align:end;
}

The rules create a singlescroll snap arearepresented by the::afterpseudo-element, positioned at the very bottom of ascroll snap container. If the user scrolls “near” the bottom, the container will snap to it. If more content is dynamically added to the container, it’ll remain snapped to it (because scroll containers are required to re-snap to the same scroll snap area if it still exists after any changes). However, if the user has scrolled to somewhere else in the logs, it won’t do anything at all.

4.2.Scroll Snapport: thescroll-paddingproperty

Name: scroll-padding
Value: [ auto|<length-percentage [0,∞]>]{1,4}
Initial: auto
Applies to: scroll containers
Inherited: no
Percentages: relative to the corresponding dimension of the scroll container’s scrollport
Computed value: per side, either the keywordautoor a computed<length-percentage>value
Animation type: by computed value type
Canonical order: per grammar

This property specifies (for allscroll containers,not justscroll snap containers) offsets that define theoptimal viewing regionof a scrollport: the region used as the target region for placing things in view of the user. This allows the author to exclude regions of thescrollportthat are obscured by other content (such as fixed-positioned toolbars or sidebars) or simply to put more breathing room between a targeted element and the edges of the scrollport.

Thescroll-paddingproperty is ashorthand propertythat sets all of thescroll-padding-*longhandsin one declaration, assigning values to the longhands representing each side exactly as thepaddingproperty does for its longhands. Values have the following meanings:

<length-percentage [0,∞]>

Defines an inward offset from the corresponding edge of thescrollport. When applied to the root viewport, the offset is calculated and applied relative to the layout viewport (rather than the visual viewport) the same way as the correspondinginset propertiesonfixed-positioned boxes; theoptimal viewing regionis the remaining area that intersects with the visual viewport.

auto

Indicates that the offset for the corresponding edge of thescrollportis UA-determined. This should generally default to a used length of0px, but UAs may use heuristics to detect when a non-zero value is more appropriate.

For example, a UA could detect when aposition:fixedelement is being used as an opaque unscrollable “header” that obscures the content below it, and resolve the top offset to the height of that element so that a “page down” operation (such as pressingPgDn) automatically scrolls by one “visible page” of content.

These offsets reduce the region of thescrollportthat is considered “viewable”for scrolling operations: they have no effect on layout, on the scroll origin or initial position, or on whether or not an element is considered actuallyvisible, but should affect whether an element or the caret is considered scrolled into view (e.g. for targeting or focusing operations), and reduce the amount of scrolling for paging operations (such as using thePgUpandPgDnkeys or triggering equivalent operations from the scrollbar) so that within theoptimal viewing regionof thescrollportthe user sees a continuous stream of content.

For ascroll snap containerthis region also defines thescroll snapport—​the area of the scrollport that is used as thealignment containerfor thescroll snap areaswhen calculatingsnap positions.

In this example,scroll-paddingis used to center slideshow images within the portion of the scrollport that is not obscured by a fixed-position toolbar.
html{
overflow-x:auto;
overflow-y:hidden;
scroll-snap-type:x mandatory;
scroll-padding:0500px00;
}
.toolbar{
position:fixed;
height:100%;
width:500px;
right:0;
}
img{
scroll-snap-align:none center;
}

UAs must apply thescroll-paddingvalues set on the root element to the document viewport. (Note that, unlikeoverflow,scroll-paddingvalues arenotpropagated from HTMLbody.)

5.Aligning Scroll Snap Areas: Properties on the elements

5.1.Scroll Snapping Area: thescroll-marginproperty

Name: scroll-margin
Value: <length>{1,4}
Initial: 0
Applies to: all elements
Inherited: no
Percentages: n/a
Computed value: per side, an absolute length
Canonical order: per grammar
Animation type: by computed value type

This property is ashorthand propertythat sets all of thescroll-margin-*longhandsin one declaration, assigning values to the longhands representing each side exactly as themarginproperty does for its longhands.

Values represent outsets defining thescroll snap areathat is used for snapping this box to the snapport. Thescroll snap areais determined by taking the transformed border box, finding its rectangular bounding box (axis-aligned in thescroll container’scoordinate space), then adding the specified outsets.

Note:This ensures that thescroll snap areais always rectangular and axis-aligned to thescroll container’scoordinate space.

If a page is navigated to a fragment that defines a target element (one that would be matched by:target, or the target ofscrollIntoView()), the UA should use the element’sscroll snap area, rather than just its border box, to determine which area of thescrollable overflow areato bring into view,even when snapping is off or not applied on this element.

5.2.Scroll Snapping Alignment: thescroll-snap-alignproperty

Name: scroll-snap-align
Value: [ none|start|end|center ]{1,2}
Initial: none
Applies to: all elements
Inherited: no
Percentages: n/a
Computed value: two keywords
Canonical order: per grammar
Animation type: discrete

Thescroll-snap-alignproperty specifies the box’ssnap positionas an alignment of itssnap area(as thealignment subject) within itssnap container’ssnapport(as thealignment container). The two values specify the snapping alignment in theblock axisandinline axis,respectively, as determined by thesnap container’swriting mode. If only one value is specified, the second value defaults to the same value.

Values are defined as follows:

none
This box does not define asnap positionin the specified axis.
start
Start alignment of this box’sscroll snap areawithin thescroll container’ssnapportis asnap positionin the specified axis.
end
End alignment of this box’sscroll snap areawithin thescroll container’ssnapportis asnap positionin the specified axis.
center
Center alignment of this box’sscroll snap areawithin thescroll container’ssnapportis asnap positionin the specified axis.

Start and end alignments are resolved with respect to thewriting modeof thesnap containerunless thescroll snap areais larger than thesnapport, in which case they are resolved with respect to thewriting modeof the box itself. (This allows items in a container to have consistent snap alignment in general, while ensuring thatstartalways aligns the item to allow reading its contents from the beginning.)

5.2.1.Scoping Valid Snap Positions to Visible Boxes

Since the purpose of scroll snapping is to align content within thescrollportfor optimal viewing, a scroll position cannot be considered a validsnap positionifsnappingto it would leave the contributingsnap areaentirely outside thesnapport, even if it otherwise satisfies the required alignment of thesnap area.

For example, asnap areais top-aligned to thesnapportif its top edge is coincident with thesnapport’s top edge; and this would be considered a validsnap positionfor block-axis start-aligned snapping of thatsnap areaif at least part of thesnap areais on-screen. If the entiresnap areais outside thesnapport,however, then thescroll containercannot be considered to besnappedbecause the required alignment, though satisfied, would not be relevant to the viewer.
╔════viewport════╗┈┈┈┈┈┈┈┈┌──────────────┐
║ ┌─────┐ ┌──┐ ║ │ top-snapping │
║ ├──┐ │ └──┘ ║ │ element │
║ └──┴──┘ ║ │ │
╚════════════════╝ │ │
└──────────────┘
Alignment of an off-screen element is not consideredsnapping.
Why limit snapping to only when the element is visible? As theWebKit implementers point out, extending a snap edge infinitely across the canvas only allows for snapping gridded layouts, and produces odd behavior for the user when off-screen elements do not align with on-screen elements. (If this requirement is onerous for implementers however, we can default to a gridded behavior and introduce a switch to get smarter behavior later.)

Note:Althoughscroll-snap-type: bothevaluatessnap positionsindependently in each axis,choosingof asnap positionin one axis can be influenced bysnap positionsin the other axis. For example, snapping in one axis may push off-screen thesnap areathat the other axis would otherwise align to, making itssnap positioninvalid and therefore unchooseable.

5.2.2.Snapping Boxes that Overflow the Scrollport

If thesnap areais larger than thesnapportin a particular axis, then any scroll position in which

is a validsnap positionin that axis.

The UA may use the specified alignment as a more precise target for certain scroll operations (e.g. explicit paging).

For example, take the first example in§ 2 Motivating Examples, which had a photo as the area. The author wants mandatory snapping from item to item, but if the item happens to be larger than your viewport, you want to be able to scroll around the whole thing once you’re over it.

Since thesnap areais larger than thesnapport, while the area fully fills the viewport, the container can be scrolled arbitrarily and will not try to snap back to its aligned position. However, if the container is scrolled such that the area no longer fully fills the viewport in an axis, the area resists outward scrolling until it is scrolled sufficiently to trigger snapping to a differentsnap position.

For another example, mandatory top-snapping on nestedsectionelements can produce large snapping areas (from large top-level sections) potentially filled with smaller snapping areas (from the subsections). When the subsections are small enough, they snap normally; when they’re longer, the viewer can scroll arbitrarily within them, or within a large segment of the top-level section that has no subsections to snap to.
┌─ top-level section ─┐ ━┓ ┳ 1 (scroll position = 0)
│ │ 1┃ ┃
│ │ ┃ ┃
│ │ ━┩ ┃
│ │ ┆ ╿
│ │ ┆ │
│ │ ┆ │
│┌─── sub-section ───┐│ ╯ ━┓ ┿ 2
│└───────────────────┘│ 2┃ │
│┌─── sub-section ───┐│ ━┓ ┃ ┿ 3
││ ││ 3┃ ━┛ │
│└───────────────────┘│ ┃ │
│┌─── sub-section ───┐│ ━┛ ━┓ ┿ 4
│└───────────────────┘│ 4┃ │
│┌─── sub-section ───┐│ ━┓ ┃ ╈ 5
││ ││ 5┃ ━┛ ┃
││ ││ ┃ ┃
││ ││ ━┩ ┃
││ ││ ┆ ┃
││ ││ ┆ ╹
││ ││ ┆
│└───────────────────┘│ ┆
└─────────────────────┘ ╯
In the figure above, the five numbered viewports represent the five snap positions associated with the top-level section and its four subsections. Because the first and last snap positions are part of ranges taller than the viewport, the viewer is allowed to scroll freely between the top and bottom of each range.

Any position in that range is a validsnap position, which can be snapped to when it is the nearest position; however, if the element is targetted directly (such as by a fragment ID or a scrolling API), the UA will land on the bolded position, which corresponds to the ideal requested alignment of the element’ssnap areawithin thesnapport.

Note:If the author had instead set mandatory snap positions on theheadingsof each section (rather than the sections themselves), the contents of the first and fifth sections would be partially inaccessible to the user, as the heading snap area does not extend to cover the whole section. This is why it’s a bad idea to use mandatory snap positions on elements that might be widely spaced apart.

5.2.3.Unreachable Snap Positions

If asnap positionis unreachable as specified, such that aligning to it would require scrolling thescroll container’s viewport past the edge of itsscrollable overflow area, theusedsnap positionfor thissnap areais the position resulting from scrollingas much as possiblein each relevant axis toward the desiredsnap position.

5.3.Scroll Snap Limits: thescroll-snap-stopproperty

Name: scroll-snap-stop
Value: normal|always
Initial: normal
Applies to: all elements
Inherited: no
Percentages: n/a
Computed value: specified keyword
Canonical order: per grammar
Animation type: discrete

When scrolling with an intended direction, thescroll containercan “pass over” several possiblesnap positions(that would be valid to snap to, if the scrolling operation used the same direction but a lesser distance) before reaching the natural endpoint of the scroll operation and selecting its finalscroll position. Thescroll-snap-stopproperty allows such a possiblesnap positionto “trap” the scrolling operation, forcing thescroll containerto stop before the scrolling operation would naturally end.

Values are defined as follows:

normal
Thescroll containermay pass over asnap positiondefined by this element during the execution of a scrolling operation.
always
Thescroll containermust not pass over asnap positiondefined by this element during the execution of a scrolling operation; it must instead snap to the first of this element’ssnap positions.

This property has no effect on scrolling operations with only anintended end position, as they do not conceptually “pass over” anysnap positions.

6.Snapping Mechanics

The precise model algorithm to select asnap positionto snap to is intentionally left mostly undefined, so that user agents can take into account sophisticated models of user intention and interaction and adjust how they respond over time, to best serve the user.

This section defines some useful concepts to aid in discussing scroll-snapping mechanics, and provides some guidelines for what an effective scroll-snapping strategy might look like. User agents are encouraged to adapt this guidance and apply their own best judgement when defining their own snapping behavior. It also provides a small number of behavior requirements, to ensure a minimum reasonable behavior that authors can depend on when designing their interfaces with scroll-snapping in mind.

6.1.Types of Scrolling Methods

When a page is scrolled, the action is performed with an intended end position and/or an intended direction. Each combination of these two things defines a distinct category of scrolling, which can be treated slightly differently:

intended end position
Common examples of scrolls with only anintended end positioninclude:
  • a panning gesture, released without momentum

  • manipulating the scrollbar “thumb” explicitly

  • programmatically scrolling via APIs such asscrollTo()

  • tabbing through the document’s focusable elements

  • navigating to an anchor within the page

  • homing operations such as theHome/Endkeys

intended direction and end position
Common examples of scrolls with both anintended direction and end positioninclude:
  • a “fling” gesture, interpreted with momentum

  • programmatically scrolling via APIs such asscrollBy()

  • paging operations such as thePgUp/PgDnkeys (or equivalent operations on the scrollbar)

The intended end point of the scroll prior to intervention from features such as snap points is itsnatural end-point.

intended direction
Common examples of scrolls with only anintended directioninclude:
  • pressing an arrow key on the keyboard (or equivalent operations on the scrollbar)

  • a swiping gesture interpreted as a fixed (rather than inertial) scroll

Additionally, because page layouts usually align things vertically and/or horizontally, UAs sometimesaxis-locka scroll when its direction is sufficiently vertical or horizontal. Anaxis-lockedscroll is bound to only scroll along that axis. This prevents less-precise input mechanisms from drifting in the non-primary axis.

Note:This specification only applies to scrolling methods supported by the user agent; it does not require the user agent to support any particular input or scrolling method.

6.2.Choosing Snap Positions

Ascroll containercan have manysnap areasscattered throughout itsscrollable overflow area. A naïve algorithm for selecting asnap positioncan produce behavior that is unintuitive for users, so care is required when designing a selection algorithm. Here are a few pointers that can aid in the selection process:

6.2.1.Selecting between multiple aligned snap areas

Whensnappingto a scroll position that is aligned with multiplescroll snap areas, the following algorithm procedure is used to determined which box issnappedon the block and inline axes for a particularscroll container:

  1. Letscroll positionbe the scroll position of thescroll container

  2. Letinlinebe the set of boxes whosescroll snap areasare aligned at thisscroll positionin the inline axis.

  3. Letblockbe the set of boxes whosescroll snap areasare aligned at thisscroll positionin the block axis.

  4. For eachlistofblockandinline:

    1. Iflistcontains the focused box, remove all other boxes fromlist.

    2. Iflistcontains the targeted box, remove all other boxes fromlist.

    3. For eachboxinlist:

      1. Remove any box fromlistwhich is an ancestor ofbox.

  5. Ifinlineandblockare overlapping sets:

    1. Replaceinlinewith the intersection ofinlineandblock.

    2. Replaceblockwith the intersection ofinlineandblock.

  6. Select the first element intree orderfrominlineas thesnappedinline axis box.

  7. Select the first element intree orderfromblockas thesnappedblock axis box.

Appendix A: Longhands

The physical and logical longhands (and their shorthands) interact as defined in[CSS-LOGICAL-1].

Physical Longhands forscroll-padding

Name: scroll-padding-top,scroll-padding-right,scroll-padding-bottom,scroll-padding-left
Value: auto|<length-percentage [0,∞]>
Initial: auto
Applies to: scroll containers
Inherited: no
Percentages: relative to the scroll container’s scrollport
Computed value: the keywordautoor a computed<length-percentage>value
Canonical order: per grammar
Animation type: by computed value type
Logical property group: scroll-padding

Theselonghandsofscroll-paddingspecify the top, right, bottom, and left edges of thesnapport,respectively. Negative values are invalid.

Flow-relative Longhands forscroll-padding

Name: scroll-padding-inline-start,scroll-padding-block-start,scroll-padding-inline-end,scroll-padding-block-end
Value: auto|<length-percentage [0,∞]>
Initial: auto
Applies to: scroll containers
Inherited: no
Percentages: relative to the scroll container’s scrollport
Computed value: the keywordautoor a computed<length-percentage>value
Canonical order: per grammar
Animation type: by computed value type
Logical property group: scroll-padding

Theselonghandsofscroll-paddingspecify the block-start, inline-start, block-end, and inline-end edges of thesnapport,respectively. Negative values are invalid.

Name: scroll-padding-block,scroll-padding-inline
Value: [ auto|<length-percentage [0,∞]>]{1,2}
Initial: auto
Applies to: scroll containers
Inherited: no
Percentages: relative to the scroll container’s scrollport
Computed value: see individual properties
Animation type: by computed value
Canonical order: per grammar

Theseshorthandsofscroll-padding-block-start+scroll-padding-block-endandscroll-padding-inline-start+scroll-padding-inline-endarelonghandsofscroll-padding, and specify the block-axis and inline-axis edges of thesnapport,respectively.

If two values are specified, the first gives the start value and the second gives the end value.

If only one value is specified, the second value defaults to the same value.

Physical Longhands forscroll-margin

Name: scroll-margin-top,scroll-margin-right,scroll-margin-bottom,scroll-margin-left
Value: <length>
Initial: 0
Applies to: all elements
Inherited: no
Percentages: n/a
Computed value: absolute length
Canonical order: per grammar
Animation type: by computed value type
Logical property group: scroll-margin

Theselonghandsofscroll-marginspecify the top, right, bottom, and left edges of thescroll snap area,respectively.

Flow-relative Longhands forscroll-margin

Name: scroll-margin-block-start,scroll-margin-inline-start,scroll-margin-block-end,scroll-margin-inline-end
Value: <length>
Initial: 0
Applies to: all elements
Inherited: no
Percentages: n/a
Computed value: absolute length
Canonical order: per grammar
Animation type: by computed value type
Logical property group: scroll-margin

Theselonghandsofscroll-marginspecify the block-start, inline-start, block-end, and inline-end edges of thescroll snap area,respectively.

Name: scroll-margin-block,scroll-margin-inline
Value: <length>{1,2}
Initial: 0
Applies to: all elements
Inherited: no
Percentages: n/a
Computed value: see individual properties
Animation type: by computed value type
Canonical order: per grammar

Theseshorthandsofscroll-margin-block-start+scroll-margin-block-endandscroll-margin-inline-start+scroll-margin-inline-endarelonghandsofscroll-margin, and specify the block-axis and inline-axis edges of thescroll snap area,respectively.

If two values are specified, the first gives the start value and the second gives the end value.

If only one value is specified, the second value defaults to the same value.

7.Privacy and Security Considerations

This specification does not expose any information whatsoever that is not already exposed to the DOM directly; it just makes scrolling slightly more functional. There are no new privacy or security considerations.

8.Acknowledgements

Many thanks to David Baron, Simon Fraser, Håkon Wium Lie, Theresa O’Connor, François Remy, Majid Valpour, and most especially Robert O’Callahan for their proposals and recommendations, which have been incorporated into this document.

9.Changes

9.1.Changes Since 19 March 2019 CR

Changes since the19 March 2019 Candidate Recommendationinclude:

ADisposition of Commentsis available.

9.2.Changes Since 31 January 2019 CR

Changes since the31 January 2019 Candidate Recommendationinclude:

9.3.Changes Since 14 August 2018 CR

Changes since the14 August 2018 Candidate Recommendationinclude:

ADisposition of Comments is available.

9.4.Changes Since 14 December 2017 CR

Changes since the14 December 2017 Candidate Recommendationinclude:

ADisposition of Commentsis available.

9.5.Changes Since 24 August 2017 CR

Changes since the24 August 2017 Candidate Recommendationinclude:

ADisposition of Commentsis available.

9.6.Changes Since 20 October 2016 CR

Changes since the20 October 2016 Candidate Recommendationinclude:

ADisposition of Commentsis available.

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://www.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-ALIGN-3]
Elika Etemad; Tab Atkins Jr..CSS Box Alignment Module Level 3.URL:https://drafts.csswg.org/css-align/
[CSS-BOX-4]
Elika Etemad.CSS Box Model Module Level 4.URL:https://drafts.csswg.org/css-box-4/
[CSS-CASCADE-5]
Elika Etemad; Miriam Suzanne; Tab Atkins Jr..CSS Cascading and Inheritance Level 5.URL:https://drafts.csswg.org/css-cascade-5/
[CSS-DISPLAY-4]
CSS Display Module Level 4.Editor's Draft. URL:https://drafts.csswg.org/css-display-4/
[CSS-LOGICAL-1]
Rossen Atanassov; Elika Etemad.CSS Logical Properties and Values Level 1.URL:https://drafts.csswg.org/css-logical-1/
[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-PSEUDO-4]
Daniel Glazman; Elika Etemad; Alan Stearns.CSS Pseudo-Elements Module Level 4.URL:https://drafts.csswg.org/css-pseudo-4/
[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/
[HTML]
Anne van Kesteren; et al.HTML Standard.Living Standard. URL:https://html.spec.whatwg.org/multipage/
[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
[SELECTORS-4]
Elika Etemad; Tab Atkins Jr..Selectors Level 4.URL:https://drafts.csswg.org/selectors/

Property Index

Name Value Initial Applies to Inh. %ages Anim­ation type Canonical order Com­puted value Logical property group
scroll-margin <length>{1,4} 0 all elements no n/a by computed value type per grammar per side, an absolute length
scroll-margin-block <length>{1,2} 0 all elements no n/a by computed value type per grammar see individual properties
scroll-margin-block-end <length> 0 all elements no n/a by computed value type per grammar absolute length scroll-margin
scroll-margin-block-start <length> 0 all elements no n/a by computed value type per grammar absolute length scroll-margin
scroll-margin-bottom <length> 0 all elements no n/a by computed value type per grammar absolute length scroll-margin
scroll-margin-inline <length>{1,2} 0 all elements no n/a by computed value type per grammar see individual properties
scroll-margin-inline-end <length> 0 all elements no n/a by computed value type per grammar absolute length scroll-margin
scroll-margin-inline-start <length> 0 all elements no n/a by computed value type per grammar absolute length scroll-margin
scroll-margin-left <length> 0 all elements no n/a by computed value type per grammar absolute length scroll-margin
scroll-margin-right <length> 0 all elements no n/a by computed value type per grammar absolute length scroll-margin
scroll-margin-top <length> 0 all elements no n/a by computed value type per grammar absolute length scroll-margin
scroll-padding [ auto | <length-percentage [0,∞]> ]{1,4} auto scroll containers no relative to the corresponding dimension of the scroll container’s scrollport by computed value type per grammar per side, either the keyword auto or a computed <length-percentage> value
scroll-padding-block [ auto | <length-percentage [0,∞]> ]{1,2} auto scroll containers no relative to the scroll container’s scrollport by computed value per grammar see individual properties
scroll-padding-block-end auto | <length-percentage [0,∞]> auto scroll containers no relative to the scroll container’s scrollport by computed value type per grammar the keyword auto or a computed <length-percentage> value scroll-padding
scroll-padding-block-start auto | <length-percentage [0,∞]> auto scroll containers no relative to the scroll container’s scrollport by computed value type per grammar the keyword auto or a computed <length-percentage> value scroll-padding
scroll-padding-bottom auto | <length-percentage [0,∞]> auto scroll containers no relative to the scroll container’s scrollport by computed value type per grammar the keyword auto or a computed <length-percentage> value scroll-padding
scroll-padding-inline [ auto | <length-percentage [0,∞]> ]{1,2} auto scroll containers no relative to the scroll container’s scrollport by computed value per grammar see individual properties
scroll-padding-inline-end auto | <length-percentage [0,∞]> auto scroll containers no relative to the scroll container’s scrollport by computed value type per grammar the keyword auto or a computed <length-percentage> value scroll-padding
scroll-padding-inline-start auto | <length-percentage [0,∞]> auto scroll containers no relative to the scroll container’s scrollport by computed value type per grammar the keyword auto or a computed <length-percentage> value scroll-padding
scroll-padding-left auto | <length-percentage [0,∞]> auto scroll containers no relative to the scroll container’s scrollport by computed value type per grammar the keyword auto or a computed <length-percentage> value scroll-padding
scroll-padding-right auto | <length-percentage [0,∞]> auto scroll containers no relative to the scroll container’s scrollport by computed value type per grammar the keyword auto or a computed <length-percentage> value scroll-padding
scroll-padding-top auto | <length-percentage [0,∞]> auto scroll containers no relative to the scroll container’s scrollport by computed value type per grammar the keyword auto or a computed <length-percentage> value scroll-padding
scroll-snap-align [ none | start | end | center ]{1,2} none all elements no n/a discrete per grammar two keywords
scroll-snap-stop normal | always normal all elements no n/a discrete per grammar specified keyword
scroll-snap-type none | [ x | y | block | inline | both ] [ mandatory | proximity ]? none all elements no n/a discrete per grammar specified keyword(s)
MDN

scroll-margin-block-end

In all current engines.

Firefox68+Safari15+Chrome69+
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?

scroll-margin-block-start

In all current engines.

Firefox68+Safari15+Chrome69+
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?

scroll-margin-inline-end

In all current engines.

Firefox68+Safari15+Chrome69+
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?

scroll-margin-inline-start

In all current engines.

Firefox68+Safari15+Chrome69+
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
MDN

scroll-margin-block

In all current engines.

Firefox68+Safari15+Chrome69+
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
MDN

scroll-margin-bottom

In all current engines.

Firefox68+Safari14.1+Chrome69+
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari14.5+Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?

scroll-margin-left

In all current engines.

Firefox68+Safari14.1+Chrome69+
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari14.5+Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?

scroll-margin-right

In all current engines.

Firefox68+Safari14.1+Chrome69+
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari14.5+Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?

scroll-margin-top

In all current engines.

Firefox68+Safari14.1+Chrome69+
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari14.5+Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
MDN

scroll-margin-inline

In all current engines.

Firefox68+Safari15+Chrome69+
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
MDN

scroll-margin

In all current engines.

Firefox90+Safari14.1+Chrome69+
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari14.5+Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
MDN

scroll-padding-block-end

In all current engines.

Firefox68+Safari15+Chrome69+
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?

scroll-padding-block-start

In all current engines.

Firefox68+Safari15+Chrome69+
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?

scroll-padding-inline-end

In all current engines.

Firefox68+Safari15+Chrome69+
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?

scroll-padding-inline-start

In all current engines.

Firefox68+Safari15+Chrome69+
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
MDN

scroll-padding-block

In all current engines.

Firefox68+Safari15+Chrome69+
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
MDN

scroll-padding-bottom

In all current engines.

Firefox68+Safari14.1+Chrome69+
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?

scroll-padding-left

In all current engines.

Firefox68+Safari14.1+Chrome69+
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?

scroll-padding-right

In all current engines.

Firefox68+Safari14.1+Chrome69+
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?

scroll-padding-top

In all current engines.

Firefox68+Safari14.1+Chrome69+
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
MDN

scroll-padding-inline

In all current engines.

Firefox68+Safari15+Chrome69+
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
MDN

scroll-padding

In all current engines.

Firefox68+Safari14.1+Chrome69+
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
MDN

scroll-snap-align

In all current engines.

Firefox68+Safari11+Chrome69+
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
MDN

scroll-snap-stop

In all current engines.

Firefox103+Safari15+Chrome75+
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
MDN

scroll-snap-type

In all current engines.

Firefox99+Safari11+Chrome69+
Opera?Edge79+
Edge (Legacy)NoneIENone
Firefox for Android68+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?