<pre class="metadata">
Title: CSS Scroll Snap Module Level 1
Group: csswg
Shortname: css-scroll-snap
TR: https://www.w3.org/TR/css-scroll-snap-1/
Level: 1
Status: ED
Implementation Report: https://wpt.fyi/results/css/css-scroll-snap
Previous Version: https://www.w3.org/TR/2021/CR-css-scroll-snap-1-20210311/
Previous Version: https://www.w3.org/TR/2019/CR-css-scroll-snap-1-20190319/
Previous Version: https://www.w3.org/TR/2019/CR-css-scroll-snap-1-20190131/
Previous Version: https://www.w3.org/TR/2018/CR-css-scroll-snap-1-20180814/
Previous Version: https://www.w3.org/TR/2017/CR-css-scroll-snap-1-20171214/
Previous Version: https://www.w3.org/TR/2017/CR-css-scroll-snap-1-20170824/
Previous Version: https://www.w3.org/TR/2017/CR-css-scroll-snap-1-20170209/
Previous Version: https://www.w3.org/TR/2016/CR-css-scroll-snap-1-20161020/
Previous Version: https://www.w3.org/TR/2016/WD-css-scroll-snap-1-20160623/
Previous Version: https://www.w3.org/TR/2016/WD-css-snappoints-1-20160329/
Previous Version: https://www.w3.org/TR/2015/WD-css-snappoints-1-20150326/
Work Status: Testing
ED: https://drafts.csswg.org/css-scroll-snap-1/
Editor: Matt Rakow, Microsoft, w3cid 62267
Editor: Jacob Rossi, Microsoft, w3cid 45616
Editor: Tab Atkins-Bittner, Google, http://xanthir.com/contact/, w3cid 42199
Editor: Elika J. Etemad / fantasai, Apple, http://fantasai.inkedblade.net/contact, w3cid 35400
Abstract: This module contains features to control panning and scrolling behavior with “snap positions”.
Ignored Terms: containing block chain, scroll position, scrollport
At Risk: 'scroll-snap-stop'
At Risk: whether 'scroll-snap-type' can cause boxes that are not [=scroll containers=] to [=capture snap positions=] (see <a href="https://github.com/w3c/csswg-drafts/issues/4496">discussion</a>)
Status Text:
 A test suite and an implementation report will be produced during the
 CR period.
</pre>

<pre class=link-defaults>
spec: css-pseudo-4; type: selector;
    text: ::first-line
    text: ::first-letter
spec: html; type: element; text: body
spec: selectors-4; type: selector; text: :target
</pre>

<style>
pre.ascii-art {
  display: table; /* shrinkwrap */
  margin: 1em auto;
  line-height: normal;
}
</style>

Introduction {#intro}
=====================

    <em>This section is not normative.</em>

    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 introduces <a>scroll snap positions</a>
    which enforce the scroll positions that a <a>scroll container’s</a> scrollport 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 the 'scroll-padding' property
    for use on all <a>scroll containers</a>,
    to adjust the <a>scroll container</a>’s <a>optimal viewing region</a>
    for the purpose of paging and scroll-into-view operations.
    Similarly the 'scroll-margin' property can be used on any box
    to adjust its visual area
    for the purpose of scroll-into-view operations.

Module interactions {#placement}
--------------------------------

    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-line'' and ''::first-letter'' pseudo-elements.

Value Definitions {#values}
-----------------

    This specification follows the <a href="https://www.w3.org/TR/CSS2/about.html#property-defs">CSS property definition conventions</a> from [[!CSS2]]
    using the <a href="https://www.w3.org/TR/css-values-3/#value-defs">value definition syntax</a> from [[!CSS-VALUES-3]].
    Value types not defined in this specification are defined in CSS Values &amp; 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 the <a>CSS-wide keywords</a> as their property value.
    For readability they have not been repeated explicitly.

<!--
████████ ██     ██    ███    ██     ██ ████████  ██       ████████  ██████
██        ██   ██    ██ ██   ███   ███ ██     ██ ██       ██       ██    ██
██         ██ ██    ██   ██  ████ ████ ██     ██ ██       ██       ██
██████      ███    ██     ██ ██ ███ ██ ████████  ██       ██████    ██████
██         ██ ██   █████████ ██     ██ ██        ██       ██             ██
██        ██   ██  ██     ██ ██     ██ ██        ██       ██       ██    ██
████████ ██     ██ ██     ██ ██     ██ ██        ████████ ████████  ██████
-->

Motivating Examples {#examples}
===============================

    <div class="example">
        In this example, a series of images arranged in a <a>scroll container</a>
        are used to build a photo gallery.  In this example the <a>scroll container</a>
        is 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 the <a>scroll container’s</a> scrollport.

        <pre class="lang-css">
            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;
            }
        </pre>

        <pre class="lang-html">
            &lt;div class="photoGallery">
                &lt;img src="img1.jpg">
                &lt;img src="img2.jpg">
                &lt;img src="img3.jpg">
                &lt;img src="img4.jpg">
                &lt;img src="img5.jpg">
            &lt;/div>
        </pre>

        <figure>
            <img src="images/element_snap_positions.png" width="775" height="214" alt="">

            <figcaption>
                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).
            </figcaption>
        </figure>
    </div>

    <div class="example">
        This example builds a paginated document that aligns each page near to (but not exactly on) the edge of the <a>scroll container</a>.
        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.

        <pre class="lang-css">
            .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: 100px 0 0;
                /* Encourages scrolling to end at a snap position when the
                    operation completes, if it is near a snap position */
                scroll-snap-type: y proximity;
            }
        </pre>

        <pre class="lang-html">
            &lt;div class="docScroller">
                &lt;div class="page">Page 1&lt;/div>
                &lt;div class="page">Page 2&lt;/div>
                &lt;div class="page">Page 3&lt;/div>
                &lt;div class="page">Page 4&lt;/div>
            &lt;/div>
        </pre>

        <figure>
            <img src="images/element_snap_positions_offset.png" width="286" height="1118" alt="">

            <figcaption>
                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).
            </figcaption>
        </figure>
    </div>

<!--
 ███████  ██     ██ ████████ ████████  ██     ██ ████ ████████ ██      ██
██     ██ ██     ██ ██       ██     ██ ██     ██  ██  ██       ██  ██  ██
██     ██ ██     ██ ██       ██     ██ ██     ██  ██  ██       ██  ██  ██
██     ██ ██     ██ ██████   ████████  ██     ██  ██  ██████   ██  ██  ██
██     ██  ██   ██  ██       ██   ██    ██   ██   ██  ██       ██  ██  ██
██     ██   ██ ██   ██       ██    ██    ██ ██    ██  ██       ██  ██  ██
 ███████     ███    ████████ ██     ██    ███    ████ ████████  ███  ███
-->

Scroll Snap Model {#overview}
=============================

    This module defines controls for
    <dfn export lt="scroll snap position" local-lt="snap position">scroll snap positions</dfn>,
    which are scroll positions that produce particular alignments
    of content within a scroll container.
    Using the 'scroll-snap-type' property on the relevant <a>scroll container</a>,
    the author can request a particular bias
    for the scrollport to land on a <a>snap position</a>
    after scrolling operations
    (including programmatic scrolls such as the {{Window/scrollTo()}} method).

    <a>Snap positions</a> are specified
    as a particular alignment ('scroll-snap-align')
    of an element’s <a>scroll snap area</a>
    (its border bounding box, as modified by 'scroll-margin')
    within the <a>scroll container</a>’s <a>snapport</a>
    (its scrollport, as reduced by 'scroll-padding').
    This is conceptually equivalent to specifying the alignment of
    an <a>alignment subject</a> within an <a>alignment container</a>.
    A scroll position that satisfies the specified alignment
    is a <a>snap position</a>.

    The act of adjusting the scroll position
    of a scroll container’s scrollport
    such that it is aligned to a snap area
    is called <dfn export lt="scroll snap" local-lt="snap">snapping</dfn>,
    and a <a>scroll container</a> may be
    <a>snapped</a> to a <a>snap area</a>
    in each axis
    if its scrollport is aligned with that <a>snap area</a> in that axis
    and there is no active scrolling operation.
    When there are multiple valid snap areas,
    a single one is chosen for each axis when <a>snapping</a>
    according to the algorithm for <a href="#multiple-aligned-snap-areas">selecting between multiple aligned snap areas</a>.
    The CSS Scroll Snap Module
    intentionally does not specify nor mandate
    any precise animations or physics used to enforce <a>snap positions</a>;
    this is left up to the user agent.

    <a>Snap positions</a> only affect the nearest ancestor <a>scroll container</a>
    on the element’s <a>containing block chain</a>.


Capturing Scroll Snap Areas:  Properties on the scroll container {#properties-on-the-scroll-container}
======================================================================================================

<!--
████████ ██    ██ ████████  ████████
   ██     ██  ██  ██     ██ ██
   ██      ████   ██     ██ ██
   ██       ██    ████████  ██████
   ██       ██    ██        ██
   ██       ██    ██        ██
   ██       ██    ██        ████████
-->

Scroll Snapping Rules: the 'scroll-snap-type' property {#scroll-snap-type}
--------------------------------------------------------------------------

    <pre class="propdef">
    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)
    Animation type: discrete
    </pre>

    The 'scroll-snap-type' property specifies
    whether a <a>scroll container</a> is a <a>scroll snap container</a>,
    how <a href="#snap-strictness">strictly</a> it <a>snaps</a>,
    and <a href="#snap-axis">which axes</a> are considered.
    If no strictness value is specified, ''proximity'' is assumed.

    <div class="example">
      In this example, snapping to headings is enabled in the <a>block axis</a>
      (the y axis for horizontal writing, x axis for vertical writing):

      <pre>
        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 */
        }
      </pre>
    </div>

    UAs must apply the 'scroll-snap-type' value set on the root element
    to the document viewport.
    Note that, unlike 'overflow',
    'scroll-snap-type' values are <em>not</em> propagated from HTML <{body}>.

<h4 id="snap-axis">
Scroll Snap Axis: the ''x'', ''y'', ''scroll-snap-type/block'', ''scroll-snap-type/inline'', and ''both'' values</h4>

    The <dfn noexport lt="axis value">axis values</dfn>
    specify what axis(es) are affected by <a>snap positions</a>,
    and whether <a>snap positions</a> are evaluated independently per axis,
    or together as a 2D point.
    Values are defined as follows:

    <dl dfn-type=value dfn-for="scroll-snap-type">
        <dt><dfn>x</dfn>
        <dd>
            The <a>scroll container</a> <a>snaps</a> to <a>snap positions</a>
            in its horizontal axis only.

        <dt><dfn>y</dfn>
        <dd>
            The <a>scroll container</a> <a>snaps</a> to <a>snap positions</a>
            in its vertical axis only.

        <dt><dfn>block</dfn>
        <dd>
            The <a>scroll container</a> <a>snaps</a> to <a>snap positions</a>
            in its block axis only.

        <dt><dfn>inline</dfn>
        <dd>
            The <a>scroll container</a> <a>snaps</a> to <a>snap positions</a>
            in its inline axis only.

        <dt><dfn>both</dfn>
        <dd>
            The <a>scroll container</a> <a>snaps</a> to <a>snap positions</a>
            in both of its axes independently
            (potentially snapping to different elements in each axis).
    </dl>

<h4 id="snap-strictness">
Scroll Snap Strictness: the ''scroll-snap-type/none'', ''proximity'', and ''mandatory'' values</h4>

    The <dfn noexport lt="strictness value">strictness values</dfn>
    (''scroll-snap-type/none'', ''proximity'', ''mandatory'')
    specify how strictly
    <a>snap positions</a> are enforced on the <a>scroll container</a>
    (by forcing an adjustment to the scroll position).
    Values are defined as follows:

    <dl dfn-type="value" dfn-for="scroll-snap-type">
        <dt><dfn>none</dfn>
        <dd>
            If specified on a <a>scroll container</a>,
            the <a>scroll container</a> must not <a>snap</a>.

        <dt><dfn>mandatory</dfn>
        <dd>
            If specified on a <a>scroll container</a>,
            the <a>scroll container</a> is required to be <a>snapped</a> to a snap position
            when there are no active scrolling operations.
            If a valid <a>snap position</a> exists
            then the scroll container must <a>snap</a> at the termination of a scroll
            (if none exist then no <a>snapping</a> occurs).


        <dt><dfn>proximity</dfn>
        <dd>
            If specified on a <a>scroll container</a>,
            the <a>scroll container</a> may <a>snap</a> to a snap position
            at the termination of a scroll,
            at the discretion of the UA given the parameters of the scroll.
    </dl>

    Advisement:
    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 box <dfn export>captures snap positions</dfn>
    if it is a <a>scroll container</a>
    <em>or</em> has a value other than ''scroll-snap-type/none'' for 'scroll-snap-type'.
    If a box’s nearest <a lt="captures snap positions">snap-position capturing</a> ancestor
    on its <a>containing block chain</a>
    is a <a>scroll container</a> with a non-''scroll-snap-type/none'' value for 'scroll-snap-type',
    that is the box’s <dfn export local-lt="snap container">scroll snap container</dfn>.
    Otherwise, the box has no <a>scroll snap container</a>,
    and its <a>snap positions</a> do not trigger <a>snapping</a>.

<h4 id="re-snap" dfn export lt="re-snap">
Re-snapping After Layout Changes</h4>

    If the content or layout of the document changes
    (e.g. content is added, moved, deleted, resized)
    such that the content of a <a>snapport</a> changes,
    the UA must re-evaluate the resulting <a>scroll position</a>,
    and re-snap if required.
    If the <a>scroll container</a> was <a>snapped</a> before the content change
    and those same [=snap areas=] still 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.
    A <a>snap area</a> can be [=snapped=] in each axis,
    following the algorithm for <a href="#multiple-aligned-snap-areas">selecting between multiple aligned snap areas</a>.
    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 as 'scroll-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.

    <div class="example">
        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:

        <pre class="lang-css">
            .log {
                scroll-snap-type: y proximity;
                align-content: end;
            }
            .log::after {
                display: block;
                content: "";
                scroll-snap-align: end;
            }
        </pre>

        The rules create a single [=scroll snap area=]
        represented by the ''::after'' pseudo-element,
        positioned at the very bottom of a [=scroll 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.
    </div>

<!--
████████     ███    ████████  ████████  ████ ██    ██  ██████
██     ██   ██ ██   ██     ██ ██     ██  ██  ███   ██ ██    ██
██     ██  ██   ██  ██     ██ ██     ██  ██  ████  ██ ██
████████  ██     ██ ██     ██ ██     ██  ██  ██ ██ ██ ██   ████
██        █████████ ██     ██ ██     ██  ██  ██  ████ ██    ██
██        ██     ██ ██     ██ ██     ██  ██  ██   ███ ██    ██
██        ██     ██ ████████  ████████  ████ ██    ██  ██████
-->

Scroll Snapport: the 'scroll-padding' property {#scroll-padding}
----------------------------------------------------------------

    <pre class="propdef shorthand">
    Name: scroll-padding
    Value: [ auto | <<length-percentage [0,∞]>> ]{1,4}
    Initial: auto
    Applies to: <a>scroll containers</a>
    Inherited: no
    Percentages: relative to the corresponding dimension of the scroll container’s scrollport
    Computed value: per side, either the keyword ''scroll-padding/auto'' or a computed <<length-percentage>> value
    Animation type: by computed value type
    </pre>

    This property specifies
    (for all <a>scroll containers</a>, not just <a>scroll snap containers</a>)
    offsets that define the
    <dfn export>optimal viewing region</dfn> of 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 the <a>scrollport</a>
    that 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.

    The 'scroll-padding' property is a <a>shorthand property</a> that sets
    all of the <a href="#longhands"><css>scroll-padding-*</css> longhands</a>
    in one declaration,
    assigning values to the longhands representing each side
    exactly as the 'padding' property does for its longhands.
    Values have the following meanings:

    <dl dfn-for="scroll-padding, scroll-padding-inline, scroll-padding-inline-start, scroll-padding-inline-end, scroll-padding-block, scroll-padding-block-start, scroll-padding-block-end" dfn-type=value>
        : <dfn><<length-percentage [0,∞]>></dfn>
        ::
            Defines an inward offset from the corresponding edge of the [=scrollport=].
            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 corresponding [=inset properties=]
            on [=fixed-positioned boxes=];
            the [=optimal viewing region=] is the remaining area
            that intersects with the visual viewport.

        : <dfn>auto</dfn>
        ::
            Indicates that the offset for the corresponding edge of the [=scrollport=] is UA-determined.
            This should generally default to a used length of ''0px'',
            but UAs may use heuristics to detect when a non-zero value is more appropriate.

            <div class=example>
                For example, a UA could detect when a ''position:fixed'' element
                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 pressing <kbd>PgDn</kbd>)
                automatically scrolls by one “visible page” of content.
            </div>
    </dl>

    These offsets reduce the region of the <a>scrollport</a>
    that is considered “viewable” <em>for scrolling operations</em>:
    they have no effect on layout,
    on the scroll origin or initial position,
    or on whether or not an element is considered actually <em>visible</em>,
    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 the <kbd>PgUp</kbd> and <kbd>PgDn</kbd> keys
    or triggering equivalent operations from the scrollbar)
    so that within the <a>optimal viewing region</a> of the <a>scrollport</a>
    the user sees a continuous stream of content.

    For a <a>scroll snap container</a> this region also defines
    the <dfn export local-lt="snapport">scroll snapport</dfn>--
    the area of the scrollport that is used as the <a>alignment container</a>
    for the <a>scroll snap areas</a> when calculating <a>snap positions</a>.

    <div class="example">
        In this example, 'scroll-padding' is used to center slideshow images
        within the portion of the scrollport
        that is not obscured by a fixed-position toolbar.

        <pre class="lang-css">
            html {
                overflow-x: auto;
                overflow-y: hidden;
                scroll-snap-type: x mandatory;
                scroll-padding: 0 500px 0 0;
            }
            .toolbar {
                position: fixed;
                height: 100%;
                width: 500px;
                right: 0;
            }
            img {
                scroll-snap-align: none center;
            }
        </pre>
    </div>

    UAs must apply the 'scroll-padding' values set on the root element
    to the document viewport.
    (Note that, unlike 'overflow',
    'scroll-padding' values are <em>not</em> propagated from HTML <{body}>.)


Aligning Scroll Snap Areas:  Properties on the elements {#properties-on-the-elements}
=====================================================================================

<!--
   ███    ████████  ████████    ███
  ██ ██   ██     ██ ██         ██ ██
 ██   ██  ██     ██ ██        ██   ██
██     ██ ████████  ██████   ██     ██
█████████ ██   ██   ██       █████████
██     ██ ██    ██  ██       ██     ██
██     ██ ██     ██ ████████ ██     ██
-->

Scroll Snapping Area: the 'scroll-margin' property {#scroll-margin}
-------------------------------------------------------------------

    <pre class="propdef">
    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
    Animation type: by computed value type
    </pre>

    This property is a <a>shorthand property</a> that sets
    all of the <a href="#longhands"><css>scroll-margin-*</css> longhands</a>
    in one declaration,
    assigning values to the longhands representing each side
    exactly as the 'margin' property does for its longhands.

    Values represent outsets defining the
    <dfn export local-lt="snap area">scroll snap area</dfn>
    that is used for snapping this box to the snapport.
    The <a>scroll snap area</a> is determined by taking the transformed border box,
    finding its rectangular bounding box
    (axis-aligned in the <a>scroll container’s</a> coordinate space),
    then adding the specified outsets.

    Note: This ensures that the <a>scroll snap area</a> is always rectangular
    and axis-aligned to the <a>scroll container’s</a> coordinate space.

    If a page is navigated to a fragment that defines a target element
    (one that would be matched by '':target'',
    or the target of {{scrollIntoView()}}),
    the UA should use the element's <a>scroll snap area</a>,
    rather than just its border box,
    to determine which area of the <a>scrollable overflow area</a>
    to bring into view,
    <em>even when snapping is off
    or not applied on this element</em>.

<!--
   ███    ██       ████  ██████   ██    ██
  ██ ██   ██        ██  ██    ██  ███   ██
 ██   ██  ██        ██  ██        ████  ██
██     ██ ██        ██  ██   ████ ██ ██ ██
█████████ ██        ██  ██    ██  ██  ████
██     ██ ██        ██  ██    ██  ██   ███
██     ██ ████████ ████  ██████   ██    ██
-->

Scroll Snapping Alignment: the 'scroll-snap-align' property {#scroll-snap-align}
--------------------------------------------------------------------------------

    <pre class="propdef">
    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
    Animation type: discrete
    </pre>

    The 'scroll-snap-align' property specifies
    the box’s <a>snap position</a> as an alignment of
    its <a>snap area</a> (as the <a>alignment subject</a>)
    within its <a>snap container’s</a> <a>snapport</a> (as the <a>alignment container</a>).
    The two values specify the snapping alignment
    in the <a>block axis</a> and <a>inline axis</a>, respectively,
    as determined by the [=snap container=]’s [=writing mode=].
    If only one value is specified, the second value defaults to the same value.

    Values are defined as follows:

    <dl dfn-type="value" dfn-for="scroll-snap-align">
        <dt><dfn>none</dfn>
        <dd>
            This box does not define a <a>snap position</a> in the specified axis.

        <dt><dfn>start</dfn>
        <dd>
            Start alignment of this box’s <a>scroll snap area</a>
            within the <a>scroll container</a>’s <a>snapport</a>
            is a <a>snap position</a>
            in the specified axis.

        <dt><dfn>end</dfn>
        <dd>
            End alignment of this box’s <a>scroll snap area</a>
            within the <a>scroll container</a>’s <a>snapport</a>
            is a <a>snap position</a>
            in the specified axis.

        <dt><dfn>center</dfn>
        <dd>
            Center alignment of this box’s <a>scroll snap area</a>
            within the <a>scroll container</a>’s <a>snapport</a>
            is a <a>snap position</a>
            in the specified axis.
    </dl>

    Start and end alignments are resolved
    with respect to the [=writing mode=] of the [=snap container=]
    unless the [=scroll snap area=] is larger than the [=snapport=],
    in which case they are resolved with respect to the [=writing mode=] of the box itself.
    (This allows items in a container to have consistent snap alignment in general,
    while ensuring that ''scroll-snap-align/start'' always aligns the item
    to allow reading its contents from the beginning.)

<h4 id="snap-scope">
Scoping Valid Snap Positions to Visible Boxes</h4>

    Since the purpose of scroll snapping is to align content within the <a>scrollport</a>
    for optimal viewing,
    a scroll position cannot be considered a valid <a>snap position</a>
    if <a>snapping</a> to it would leave the contributing <a>snap area</a>
    entirely outside the <a>snapport</a>,
    even if it otherwise satisfies the required alignment of the <a>snap area</a>.

    <div class="example">
        For example, a <a>snap area</a> is top-aligned to the <a>snapport</a>
        if its top edge is coincident with the <a>snapport</a>’s top edge;
        and this would be considered a valid <a>snap position</a>
        for block-axis start-aligned snapping of that <a>snap area</a>
        <em>if at least part of the <a>snap area</a> is on-screen</em>.
        If the entire <a>snap area</a> is outside the <a>snapport</a>, however,
        then the <a>scroll container</a> cannot be considered to be <a>snapped</a>
        because the required alignment, though satisfied, would not be relevant to the viewer.

        <figure>
            <pre class="ascii-art">
                ╔════viewport════╗┈┈┈┈┈┈┈┈┌──────────────┐
                ║  ┌─────┐ ┌──┐  ║        │ top-snapping │
                ║  ├──┐  │ └──┘  ║        │   element    │
                ║  └──┴──┘       ║        │              │
                ╚════════════════╝        │              │
                                          └──────────────┘
            </pre>
            <figcaption>
              Alignment of an off-screen element
              is not considered <a>snapping</a>.
            </figcaption>
        </figure>
    </div>

    <details class="note">
        <summary>Why limit snapping to only when the element is visible?</summary>
        As the <a href="https://www.webkit.org/blog/4017/scroll-snapping-with-css-snap-points/">WebKit implementers point out</a>,
        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.)
    </details>

    Note: Although ''scroll-snap-type: both'' evaluates [=snap positions=] independently in each axis,
    <a href="#choosing">choosing</a> of a [=snap position=] in one axis
    can be influenced by [=snap positions=] in the other axis.
    For example, snapping in one axis
    may push off-screen the [=snap area=] that the other axis would otherwise align to,
    making its [=snap position=] invalid and therefore unchooseable.

<h4 id="snap-overflow">
Snapping Boxes that Overflow the Scrollport</h4>

    If the <a>snap area</a> is larger than the <a>snapport</a> in a particular axis,
    then any scroll position in which
      * the <a>snap area</a> covers the <a>snapport</a>, and
      * the distance between the geometrically previous and subsequent
        otherwise-valid <a>snap positions</a> in that axis
        is larger than size of the <a>snapport</a> in that axis,

    is a valid <a>snap position</a> in that axis.

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

    <div class="example">
        For example, take the first example in [[#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 the <a>snap area</a> is larger than the <a>snapport</a>,
        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 different <a>snap position</a>.
    </div>

    <div class=example>
        For another example,
        mandatory top-snapping on nested <{section}> elements
        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.

        <figure>
            <pre class=ascii-art>
            ┌─ top-level section ─┐ ━┓        ┳ 1 (scroll position = 0)
            │                     │ 1┃        ┃
            │                     │  ┃        ┃
            │                     │ ━┩        ┃
            │                     │  ┆        ╿
            │                     │  ┆        │
            │                     │  ┆        │
            │┌─── sub-section ───┐│  ╯ ━┓     ┿ 2
            │└───────────────────┘│    2┃     │
            │┌─── sub-section ───┐│ ━┓  ┃     ┿ 3
            ││                   ││ 3┃ ━┛     │
            │└───────────────────┘│  ┃        │
            │┌─── sub-section ───┐│ ━┛ ━┓     ┿ 4
            │└───────────────────┘│    4┃     │
            │┌─── sub-section ───┐│ ━┓  ┃     ╈ 5
            ││                   ││ 5┃ ━┛     ┃
            ││                   ││  ┃        ┃
            ││                   ││ ━┩        ┃
            ││                   ││  ┆        ┃
            ││                   ││  ┆        ╹
            ││                   ││  ┆
            │└───────────────────┘│  ┆
            └─────────────────────┘  ╯
            </pre>
            <figcaption>
                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 valid [=snap 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’s [=snap area=] within the [=snapport=].
            </figcaption>
        </figure>

        Note: If the author had instead set mandatory snap positions
        on the <em>headings</em> of 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.
    </div>


<h4 id="unreachable">
Unreachable Snap Positions</h4>

    If a <a>snap position</a> is unreachable as specified,
    such that aligning to it would require scrolling the <a>scroll container</a>’s viewport
    past the edge of its <a>scrollable overflow area</a>,
    the <em>used</em> <a>snap position</a> for this <a>snap area</a>
    is the position resulting from scrolling <em>as much as possible</em>
    in each relevant axis
    toward the desired <a>snap position</a>.

<!--
 ██████  ████████  ███████  ████████
██    ██    ██    ██     ██ ██     ██
██          ██    ██     ██ ██     ██
 ██████     ██    ██     ██ ████████
      ██    ██    ██     ██ ██
██    ██    ██    ██     ██ ██
 ██████     ██     ███████  ██
-->

Scroll Snap Limits: the 'scroll-snap-stop' property {#scroll-snap-stop}
--------------------------

    <pre class="propdef">
    Name: scroll-snap-stop
    Value: normal | always
    Initial: normal
    Applies to: all elements
    Inherited: no
    Percentages: n/a
    Computed value: specified keyword
    Animation type: discrete
    </pre>

    When performing a [=relative scroll=],
    the <a>scroll container</a> can “pass over” several possible <a>snap positions</a>
    (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 final <a>scroll position</a>.
    The 'scroll-snap-stop' property allows such a possible <a>snap position</a>
    to “trap” the scrolling operation,
    forcing the <a>scroll container</a> to stop
    before the scrolling operation would naturally end.

    Values are defined as follows:

    <dl dfn-type=value dfn-for=scroll-snap-stop>
        <dt><dfn>normal</dfn>
        <dd>
            The <a>scroll container</a> may pass over a <a>snap position</a> defined
            by this element during the execution of a scrolling operation.

        <dt><dfn>always</dfn>
        <dd>
            The <a>scroll container</a> must not pass over a <a>snap position</a>
            defined by this element during the execution of a scrolling operation;
            it must instead snap to the first of this element's <a>snap positions</a>.
    </dl>

    This property has no effect on non-[=relative scrolling=] operations,
    as they do not conceptually “pass over” any <a>snap positions</a>.

Snapping Mechanics {#snap-concepts}
===================================

    The precise model algorithm to select a <a>snap position</a> to 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.


<!--
████████ ██    ██ ████████  ████████  ██████
   ██     ██  ██  ██     ██ ██       ██    ██
   ██      ████   ██     ██ ██       ██
   ██       ██    ████████  ██████    ██████
   ██       ██    ██        ██             ██
   ██       ██    ██        ██       ██    ██
   ██       ██    ██        ████████  ██████
-->

Types of Scrolling Methods {#scroll-types}
------------------------------------------

    There are many ways to cause a page to scroll,
    and they differ in their intent,
    which affects how scroll snapping and other features
    should <em>respond</em> to them.
    The types of scrolling intents are:

    : <dfn export>absolute scroll</dfn>
    ::
        An [=absolute scroll=] is a scrolling operation
        that is not intended to have any relation with the previous scroll position.
        Whether the new position is before or after the previous scroll position
        is not relevant to the operation;
        the scroll container just "goes straight there".

        <div class="example">
            Common examples of [=absolute scrolls=] include:

            * manipulating the scrollbar “thumb” explicitly
            * programmatically scrolling via APIs such as {{Window/scrollTo()}}
            * tabbing through the document’s focusable elements
            * navigating to an anchor within the page
            * homing operations such as the <kbd>Home</kbd>/<kbd>End</kbd> keys
        </div>

        Note: Scroll snapping responds to an [=absolute scroll=] 
        by finding the nearest valid [=snap position=],
        <em>regardless</em> of direction.

    : <dfn export>relative scroll</dfn>
    ::
        A [=relative scroll=] is a scrolling operation
        that does have a meaningful relation with the previous scroll position;
        that is, the fact that the new scroll position is before or after the old scroll position
        is an important quality of the scroll.

        Relative scrolls might or might not have an intended end position,
        but they always have an intended <em>direction</em>.

        <div class="example">
            Common examples of [=relative scrolls=] with both an intended direction and end position include:

            * a “fling” gesture, interpreted with momentum
            * a panning gesture,
                released with or without momentum
            * programmatically scrolling via APIs such as {{Window/scrollBy()}}
            * paging operations such as the <kbd>PgUp</kbd>/<kbd>PgDn</kbd> keys (or equivalent operations on the scrollbar)

            Common examples of [=relative scrolls=] with only an intended direction include:

            * pressing an arrow key on the keyboard
            * pressing an arrow button on the scrollbar
            * a swiping gesture interpreted as a fixed (rather than inertial) scroll
        </div>

        The intended end point of the scroll prior to intervention from features such
        as snap points is its <dfn noexport>natural end-point</dfn>.

        Note: Scroll snapping responds to a [=relative scroll=]
        by finding the nearest valid [=snap position=]
        <em>in the intended direction</em> (if possible),
        so a snapped element can't get "trapped"
        when the [=snap positions=] are far apart.

    : <dfn export>stationary scroll</dfn>
    ::
        A [=stationary scroll=] is a scrolling operation
        that isn't "intending" to move the scroller at all;
        instead, it's attempting to keep something stationary
        (usually, an element you're focusing on).

        <div class="example">
            Common examples of [=stationary scrolls=] include:

            * scroll anchoring with 'overflow-anchor',
                when off-screen content changes size
                and would move the current anchor
            * scroll snapping (especially ''scroll-snap-type/mandatory'')
                when another element changes size
                and causes the scroller to no longer be at a valid snap point
        </div> 

        Note: Scroll snapping responds to a [=stationary scroll=]
        by finding the nearest valid [=snap position=],
        similar to an [=absolute scroll=].

    Additionally, because page layouts usually align things vertically and/or horizontally,
    UAs sometimes <dfn export>axis-lock</dfn> a scroll when its direction
    is sufficiently vertical or horizontal.
    An <a>axis-locked</a> scroll 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.

<!--
 ██████  ██     ██  ███████   ███████   ██████  ████ ██    ██  ██████
██    ██ ██     ██ ██     ██ ██     ██ ██    ██  ██  ███   ██ ██    ██
██       ██     ██ ██     ██ ██     ██ ██        ██  ████  ██ ██
██       █████████ ██     ██ ██     ██  ██████   ██  ██ ██ ██ ██   ████
██       ██     ██ ██     ██ ██     ██       ██  ██  ██  ████ ██    ██
██    ██ ██     ██ ██     ██ ██     ██ ██    ██  ██  ██   ███ ██    ██
 ██████  ██     ██  ███████   ███████   ██████  ████ ██    ██  ██████
-->

Choosing Snap Positions {#choosing}
-----------------------------------

    A <a>scroll container</a> can have many <a>snap areas</a>
    scattered throughout its <a>scrollable overflow area</a>.
    A naïve algorithm for selecting a <a>snap position</a>
    can 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:

    * <a>Snap positions</a> should be chosen to minimize the distance between the end-point
        (or the <a>natural end-point</a>)
        and the final snapped scroll position,
        subject to the additional constraints listed in this section.

    * If a scroll is <a>axis-locked</a>,
        any <a>snap positions</a> in the other axis should be ignored
        during the scroll.
        (However, <a>snap positions</a> in the other axis can still effect the final scroll position.)

    * In order to prevent a far-offscreen element
        from having difficult-to-understand effects
        on the scroll position,
        <a>snap positions</a> should be ignored if their elements are far outside of the “corridor”
        that the <a>snapport</a> defines as it moves through the <a>scrollable overflow area</a>,
        or a hypothetical “corridor” in the direction of a [=relative scroll=],
        or the <a>snapport</a> after an [=absolute scroll=].

    * User agents <em>must</em> ensure that a user can “escape” a <a>snap position</a>,
        regardless of the scroll method.
        For example, if the snap type is ''mandatory''
        and the next <a>snap position</a> is more than two screen-widths away,
        a naïve “always snap to nearest” selection algorithm might “trap” the user
        if their end position was only one screen-width away.
        Instead, a smarter algorithm that only returned to the starting <a>snap position</a>
        if the end-point was a fairly small distance from it,
        and otherwise ignored the starting snap position,
        would give better behavior.

        (This implies that a [=relative scroll=] without an intended end position
        must always ignore the starting <a>snap positions</a>.)

    * If a page is navigated to a fragment that defines a target element
        (e.g. one that would be matched by '':target'',
        or the target of {{Element/scrollIntoView()}}),
        and that element defines some <a>snap positions</a>,
        the user agent must <a>snap</a> to one of that element’s <a>snap positions</a>
        if its nearest <a>scroll container</a> is a <a>scroll snap container</a>.
        The user agent <em>may</em> also do this even when the <a>scroll container</a> has ''scroll-snap-type: none''.

    * If a scroll by page operation (e.g. Page down / Page up) is being performed,
        eligible <a>snap positions</a> that require scrolling less than or equal to the size of the <a>optimal viewing region</a> of the <a>scroll container</a>
        should be selected before any farther away, ignoring the starting <a>snap positions</a> so that progress is still made in the intended direction.

<h4 id="multiple-aligned-snap-areas">Selecting between multiple aligned snap areas</h4>

    When <a>snapping</a> to a scroll position
    that is aligned with multiple [=scroll snap areas=],
    the following algorithm procedure is used to determined which box is <a>snapped</a> on the block and inline axes
    for a particular <a>scroll container</a>:

    1. Let |scroll position| be the scroll position of the <a>scroll container</a>
    1. Let |inline| be the set of boxes whose [=scroll snap areas=] are aligned at this |scroll position| in the inline axis.
    1. Let |block| be the set of boxes whose [=scroll snap areas=] are aligned at this |scroll position| in the block axis.
    1. For each |list| of |block| and |inline|:
        1. If |list| contains one or more boxes
            that are focused or have a focused descendant,
            remove all other boxes from |list|
        1. Else if |list| contains one or more boxes
            that are targetted or have a targetted descendant,
            remove all other boxes from |list|.
        1. For each |box| in |list|:
            1. Remove any box from |list| which is an ancestor of |box|.
    1. If |inline| and |block| are overlapping sets:
        1. Replace |inline| with the intersection of |inline| and |block|.
        1. Replace |block| with the intersection of |inline| and |block|.
    1. Select the first element in <a>tree order</a> from |inline| as the <a>snapped</a> inline axis box.
    1. Select the first element in <a>tree order</a> from |block| as the <a>snapped</a> block axis box.

<!--
██        ███████  ██    ██  ██████   ██     ██    ███    ██    ██ ████████   ██████
██       ██     ██ ███   ██ ██    ██  ██     ██   ██ ██   ███   ██ ██     ██ ██    ██
██       ██     ██ ████  ██ ██        ██     ██  ██   ██  ████  ██ ██     ██ ██
██       ██     ██ ██ ██ ██ ██   ████ █████████ ██     ██ ██ ██ ██ ██     ██  ██████
██       ██     ██ ██  ████ ██    ██  ██     ██ █████████ ██  ████ ██     ██       ██
██       ██     ██ ██   ███ ██    ██  ██     ██ ██     ██ ██   ███ ██     ██ ██    ██
████████  ███████  ██    ██  ██████   ██     ██ ██     ██ ██    ██ ████████   ██████
-->

Appendix A: Longhands {#longhands}
==================================

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

Physical Longhands for 'scroll-padding' {#padding-longhands-physical}
----------------------------------------------------------------------

    <pre class="propdef">
    Name: scroll-padding-top, scroll-padding-right, scroll-padding-bottom, scroll-padding-left
    Value: auto | <<length-percentage [0,∞]>>
    Initial: auto
    Applies to: <a>scroll containers</a>
    Inherited: no
    Logical property group: scroll-padding
    Percentages: relative to the scroll container’s scrollport
    Computed value: the keyword ''scroll-padding/auto'' or a computed <<length-percentage>> value
    Animation type: by computed value type
    </pre>

    These <a>longhands</a> of 'scroll-padding' specify
    the top, right, bottom, and left edges
    of the <a>snapport</a>, respectively.
    Negative values are invalid.

Flow-relative Longhands for 'scroll-padding'  {#padding-longhands-logical}
--------------------------------------------------------------------------

    <pre class="propdef">
    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: <a>scroll containers</a>
    Inherited: no
    Logical property group: scroll-padding
    Percentages: relative to the scroll container’s scrollport
    Computed value: the keyword ''scroll-padding/auto'' or a computed <<length-percentage>> value
    Animation type: by computed value type
    </pre>

    These <a>longhands</a> of 'scroll-padding' specify
    the block-start, inline-start, block-end, and inline-end edges
    of the <a>snapport</a>, respectively.
    Negative values are invalid.

    <pre class="propdef shorthand">
    Name: scroll-padding-block, scroll-padding-inline
    Value: [ auto | <<length-percentage [0,∞]>> ]{1,2}
    Initial: auto
    Applies to: <a>scroll containers</a>
    Inherited: no
    Percentages: relative to the scroll container’s scrollport
    Animation type: by computed value
    </pre>

    These <a>shorthands</a> of 'scroll-padding-block-start' + 'scroll-padding-block-end'
    and 'scroll-padding-inline-start' + 'scroll-padding-inline-end'
    are <a>longhands</a> of 'scroll-padding',
    and specify the block-axis and inline-axis edges of the <a>snapport</a>, 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 for 'scroll-margin'  {#margin-longhands-physical}
--------------------------------------------------------------------

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

    These <a>longhands</a> of 'scroll-margin' specify
    the top, right, bottom, and left edges
    of the <a>scroll snap area</a>, respectively.

Flow-relative Longhands for 'scroll-margin'  {#margin-longhands-logical}
------------------------------------------------------------------------

    <pre class="propdef">
    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
    Logical property group: scroll-margin
    Percentages: n/a
    Computed value: absolute length
    Animation type: by computed value type
    </pre>

    These <a>longhands</a> of 'scroll-margin' specify the
    block-start, inline-start, block-end, and inline-end edges
    of the <a>scroll snap area</a>, respectively.

    <pre class="propdef shorthand">
    Name: scroll-margin-block, scroll-margin-inline
    Value: <<length>>{1,2}
    Initial: 0
    Applies to: all elements
    Inherited: no
    Percentages: n/a
    Animation type: by computed value type
    </pre>

    These <a>shorthands</a> of 'scroll-margin-block-start' + 'scroll-margin-block-end'
    and 'scroll-margin-inline-start' + 'scroll-margin-inline-end'
    are <a>longhands</a> of 'scroll-margin',
    and specify the block-axis and inline-axis edges
    of the <a>scroll snap area</a>, 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.

Privacy Considerations {#privacy}
=================================

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

Security Considerations {#security}
===================================

    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 security considerations.

Acknowledgements {#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.

Changes {#changes}
==================

Changes Since 11 March 2021 CRS {#changes-20210311}
---------------------------------------------------

    Changes since the <a href="https://www.w3.org/TR/2021/CR-css-scroll-snap-1-20210311/">11 March 2021 Candidate Recommendation Snapshot</a> include:

    ISSUE: Fill this out properly.
    <ul>
        <li id="change-2021-snap-focus-ancestor">
            Clarified that ancestors of focused or targeted boxes are also prioritized.
            (<a href="https://github.com/w3c/csswg-drafts/issues/13673">Issue 13673</a>)
    </ul>

Changes Since 19 March 2019 CR {#changes-20190319}
----------------------------------------------------

    Changes since the <a href="https://www.w3.org/TR/2019/CR-css-scroll-snap-1-20190319/">19 March 2019 Candidate Recommendation</a> include:

    <ul>
        <li id="change-2019-clarify-writing-mode">
            Specified which writing mode is used to resolve 'scroll-snap-align'.
            (<a href="https://github.com/w3c/csswg-drafts/issues/3815">Issue 3815</a>)
        <li id="change-2019-resnap-multiple">
            Define requirements for re-snapping when multiple elements coincide.
            (<a href="https://github.com/w3c/csswg-drafts/issues/4651">Issue 4651</a>)
            <blockquote>
                <p>If the <a>scroll container</a> was <a>snapped</a> before the content change
                and that same <a>snap position</a> still exists
                (e.g. its associated element was not deleted),
                the scroll container must be re-snapped to that same snap position
                after the content change.
                <ins>If multiple boxes were [=snapped=] before
                and their [=snap positions=] no longer coincide,
                then if one of them is focused or targeted,
                the [=scroll container=] must re-snap to that one
                and otherwise which one to re-snap to is UA-defined.
                (The UA may, for example, track which element is snapped
                as layout shifts align and de-align
                the [=snap positions=] of other elements.)
                </ins></p>
            </blockquote>
        <li id="change-2019-resnap-animation">
            Require re-snapping to a new element to animate the same way
            as any other scroll-into-view operation.
            (<a href="https://github.com/w3c/csswg-drafts/issues/4609">Issue 4609</a>)
            <blockquote>
                <p><ins>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 as 'scroll-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 animation 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.
                </ins></p>
            </blockquote>
        <li id="change-2019-propagation">
            Defined explicitly that 'scroll-snap-type' and 'scroll-padding' values
            are propagated from the root element to the document viewport
            as would be expected.
            (<a href="https://github.com/w3c/csswg-drafts/issues/3740">Issue 3740</a>)
            <blockquote>
                <p><ins>UAs must apply the 'scroll-snap-type' value set on the root element
                to the document viewport.
                Note that, unlike 'overflow',
                'scroll-snap-type' values are <em>not</em> propagated from HTML <{body}>.</ins></p>
            </blockquote>
            <blockquote>
                <p><ins>UAs must apply the 'scroll-padding' values set on the root element
                to the document viewport.
                (Note that, unlike 'overflow',
                'scroll-padding' values are <em>not</em> propagated from HTML <{body}>.)</ins></p>
            </blockquote>
        <li id="change-2019-padding-viewport">
            Clarified that while snap alignment is relative to the visual viewport,
            'scroll-padding' is resolved against the layout viewport,
            so that 'scroll-padding' and 'inset' are consistent on the root viewport.
            (<a href="https://github.com/w3c/csswg-drafts/issues/4393">Issue 4393</a>)
            <blockquote>
                <p>Defines an inward offset from the corresponding edge of the [=scrollport=].
                <ins>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 corresponding [=inset properties=]
                on [=fixed-positioned boxes=];
                the [=optimal viewing region=] is the remaining area
                that intersects with the visual viewport.</ins></p>
            </blockquote>
        <li id="change-2019-padding-applies-to">
            Corrected the “Applies to” line for 'scroll-padding-inline' and 'scroll-padding-block'.
            (<a href="https://github.com/w3c/csswg-drafts/issues/5845">Issue 5845</a>)
    </ul>

    A <a href="https://drafts.csswg.org/css-scroll-snap-1/issues-cr-2019">Disposition of Comments</a> is available.

Changes Since 31 January 2019 CR {#changes-20190131}
----------------------------------------------------

    Changes since the <a href="https://www.w3.org/TR/2019/CR-css-scroll-snap-1-20190131/">31 January 2019 Candidate Recommendation</a> include:

    <ul>
        <li id="change-2019-clarify-nonsnapping">
            Emphasized that 'scroll-padding' and 'scroll-margin' do apply
            even when scroll snapping is off.
            (<a href="https://github.com/w3c/csswg-drafts/issues/3721">Issue 3721</a>)
            <blockquote>
                <p><ins>Also, to offer better control over paging and scroll positioning
                even when snapping is off,
                this module defines the 'scroll-padding' property
                for use on all <a>scroll containers</a>,
                to adjust the <a>scroll container</a>’s <a>optimal viewing region</a>
                for the purpose of paging and scroll-into-view operations;
                similarly the 'scroll-margin' property can be used on any box
                to adjust its visual area
                for the purpose of scroll-into-view operations.</ins></p>
            </blockquote>
            <blockquote>
                <p>This property specifies
                <ins>(for all <a>scroll containers</a>, not just <a>scroll snap containers</a>)</ins>
                offsets that define the
                <a>optimal viewing region</a> of a scrollport&hellip;</p>
            </blockquote>
            <blockquote>
                <p>If a page is navigated to a fragment that defines a target element
                (one that would be matched by '':target'',
                or the target of {{scrollIntoView()}}),
                the UA should use the element's <a>scroll snap area</a>,
                rather than just its border box,
                to determine which area of the <a>scrollable overflow area</a>
                to bring into view<ins>,
                <em>even when snapping is off
                or not applied on this element</em></ins>.</p>
            </blockquote>
    </ul>

Changes Since 14 August 2018 CR {#changes-20180814}
---------------------------------------------------

    Changes since the <a href="https://www.w3.org/TR/2018/CR-css-scroll-snap-1-20180814/">14 August 2018 Candidate Recommendation</a> include:

    <ul>
        <li id="change-2018-padding-initial">
            Corrected 'scroll-padding' longhands to list the new ''scroll-padding/auto'' keyword in their property definition tables.
            (<a href="https://github.com/w3c/csswg-drafts/issues/3189">Issue 3189</a>)
        <li id="change-2018-computed-animation">
            Fixed up “Computed value” and “Animation type” lines in the property definition tables.
        <li id="change-2018-margin-percentage">
            Cleaned up stray <<percentage>> values in 'scroll-margin' property definition tables.
            (<a href="https://github.com/w3c/csswg-drafts/issues/3289">3289</a>)
    </ul>

    A <a href="https://drafts.csswg.org/css-scroll-snap-1/issues-cr-2018">Disposition of Comments is available</a>.

Changes Since 14 December 2017 CR {#changes-20171214}
---------------------------------------------------

    Changes since the <a href="https://www.w3.org/TR/2017/CR-css-scroll-snap-1-20171214/">14 December 2017 Candidate Recommendation</a> include:

    <ul>
        <li id="change-2017-align-values-backwards">
            Fixed 'scroll-snap-align' shorthand to assign
            block-axis value first, inline-axis value second,
            accordingly to logical shorthand conventions.
            (<a href="https://github.com/w3c/csswg-drafts/issues/2232">Issue 2232</a>
        <li id="change-2017-scroll-padding-auto">
            Added ''scroll-padding/auto'' keyword to 'scroll-padding as its initial value
            to account for UA heuristics.
            (<a href="https://github.com/w3c/csswg-drafts/issues/2728">Issue 2728</a>
        <li id="change-2017-snap-vs-api-scroll">
            Clarified in the definition of 'scroll-snap-type'
            that programmatic scrolls such as {{Window/scrollTo()}}
            are also subject to snapping.
            (<a href="https://github.com/w3c/csswg-drafts/issues/2593">Issue 2593</a>)
            <blockquote>
                Using the 'scroll-snap-type' property on the relevant <a>scroll container</a>,
                the author can request a particular bias
                for the scrollport to land on a <a>snap position</a>
                after scrolling operations
                <ins>(including programmatic scrolls such as the {{Window/scrollTo()}} method)</ins>.
            </blockquote>
        <li id="change-2017-clarify-mandatory-visibility">
            Adjusted wording in [[#snap-scope]] to be clearer--
            compared to <a href="https://www.w3.org/TR/2017/CR-css-scroll-snap-1-20171214/#snap-scope">old version</a>.
            (<a href="https://github.com/w3c/csswg-drafts/issues/2526">Issue 2526</a>)
    </ul>

    A <a href="https://drafts.csswg.org/css-scroll-snap-1/issues-cr-2017-12">Disposition of Comments</a> is available.

Changes Since 24 August 2017 CR {#changes-20170824}
---------------------------------------------------

    Changes since the <a href="https://www.w3.org/TR/2017/CR-css-scroll-snap-1-20170824/">24 August 2017 Candidate Recommendation</a> include:

    <ul>
        <li id="change-2017-scroll-margin">
            '':target''/{{scrollIntoView()}}/etc should take 'scroll-margin' into account,
            regardless of whether snapping is turned on or not.
            (<a href="https://drafts.csswg.org/css-scroll-snap-1/issues-cr-2016-08#issue-1">Issue 1</a>
            <blockquote>
                <p><ins>If a page is navigated to a fragment that defines a target element
                (one that would be matched by '':target'',
                or the target of {{scrollIntoView()}}),
                the UA should use the element's <a>scroll snap area</a>,
                rather than just its border box,
                to determine which area of the <a>scrollable overflow area</a>
                to bring into view.</ins></p>
            </blockquote>

        <li id="change-2017-target-snap-must">
            '':target''/{{scrollIntoView()}}/etc must (rather than should)
            use snap positions if snapping is turned on.
            (<a href="https://drafts.csswg.org/css-scroll-snap-1/issues-cr-2016-08#issue-1">Issue 1</a>
            <blockquote>
                <p>If a page is navigated to a fragment that defines a target element
                (one that would be matched by '':target'',
                or the target of {{Element/scrollIntoView()}}),
                and that element defines some <a>snap positions</a>,
                the user agent <del>should</del> <ins>must</ins> <a>snap</a>
                to one of that element’s <a>snap positions</a>
                <ins>if its nearest <a>scroll container</a> is a <a>scroll snap container</a></ins>.
                The user agent <em>may</em> also do this even when
                the <a>scroll container</a> has ''scroll-snap-type: none''.</p>
            </blockquote>

        <li id="change-2017-rename-scroll-margin">
            Renamed <css>scroll-snap-margin</css> to 'scroll-margin'
            to reflect its more generic role in providing breathing space
            for scrolling to an element regardless of snapping behavior.
            (<a href="https://drafts.csswg.org/css-scroll-snap-1/issues-cr-2016-08#issue-4">Issue 4</a>)
    </ul>

    A <a href="https://drafts.csswg.org/css-scroll-snap-1/issues-cr-2016-08">Disposition of Comments</a> is available.

Changes Since 20 October 2016 CR {#changes-20161020}
----------------------------------------------------

    Changes since the <a href="https://www.w3.org/TR/2016/CR-css-scroll-snap-1-20161020/">20 October 2016 Candidate Recommendation</a> include:

    <ul>
        <li>Restricted 'scroll-padding' to non-negative values.
            (<a href="https://github.com/w3c/csswg-drafts/issues/1084">Issue 1084</a>)
            <blockquote>
                <p>Values <ins>must be non-negative and</ins>
                are interpreted as for 'padding' &hellip;</p>
            </blockquote>
        <li>Added paging and homing operations to examples in <a href="#scroll-types"></a>.
            (<a href="https://github.com/w3c/csswg-drafts/issues/1605">Issue 1605</a>)
        <li>Clarified that snapping in one axis may affect whether snapping to a particular snap area is possible in the other axis.
            (<a href="https://github.com/w3c/csswg-drafts/issues/950">Issue 950</a>)
            <blockquote>
                <ins><p class="note">Although ''scroll-snap-type: both'' evaluates [=snap positions=] independently in each axis,
                <a href="#choosing">choosing</a> of a [=snap position=] in one axis
                may be influenced by [=snap positions=] in the other axis.
                For example, snapping in one axis
                may push off-screen the [=snap area=] that the other axis would otherwise align to,
                making its [=snap position=] invalid and therefore unchooseable.</p></ins>
            </blockquote>
        <li>Clarified how the 'scroll-padding' and 'scroll-margin' shorthands
            assign values to their longhands.
            (<a href="https://github.com/w3c/csswg-drafts/issues/1050">Issue 1050</a>)
        <li>Clarified that scroll snapping does not mandate any particular input method.
            (<a href="https://github.com/w3c/csswg-drafts/issues/1305">Issue 1305</a>)
            <blockquote>
                <ins><p class="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.</p></ins>
            </blockquote>
        <li>Clarified the intended effects of 'scroll-snap-stop' on various scrolling operations.
            (<a href="https://github.com/w3c/csswg-drafts/issues/1552">Issue 1552</a>)
        <li>Clarified that 'scroll-snap-stop' is applied to the <a>snap positions</a> defined by the element,
            not applied to all <a>snap positions</a> in the <a>scroll snap container</a>.
        <li>Fixed some syntax errors in examples and added a new one to the 'scroll-snap-type' section.
            (<a href="https://github.com/w3c/csswg-drafts/issues/827">Issue 827</a>)
    </ul>


    A <a href="https://drafts.csswg.org/css-scroll-snap-1/issues-cr-2016">Disposition of Comments</a> is available.
