scroll-snap-coordinate

Deprecated
This feature has been removed from the Web standards. Though some browsers may still support it, it is in the process of being dropped. Avoid using it and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

The scroll-snap-coordinate CSS property defines the positions in x and y coordinates within the element which will align with the nearest ancestor scroll container's scroll-snap-destination for the respective axis.

If the element has been transformed, the snap coordinate is transformed in the same way in order to align the snap point with the element as it is displayed.

/* Keyword value */
scroll-snap-coordinate: none;
/* <position> values */
scroll-snap-coordinate: 50px 50px;                   /* Single coordinate */
scroll-snap-coordinate: 100px 100px, 100px bottom;   /* Multiple coordinates */
/* Global values */
scroll-snap-coordinate: inherit;
scroll-snap-coordinate: initial;
scroll-snap-coordinate: unset;
Initial valuenone
Applies toall elements
Inheritedno
Percentagesrefer to the element’s border box
Mediainteractive
Computed valueas specified, but with relative lengths converted into absolute lengths
Animation typea position
Canonical orderthe unique non-ambiguous order defined by the formal grammar

Syntax

Values

none
Specifies that the element does not contribute to a snap point.
<position>
Specifies the offset of the snap coordinates from the start edge of the element’s border box. For each pairing, the first value gives the x coordinate of the snap coordinate, the second value its y coordinate.

Formal syntax

none | <position>#

where
<position> = [[ left | center | right | top | bottom | <length-percentage> ] | [ left | center | right | <length-percentage> ] [ top | center | bottom | <length-percentage> ] | [ center | [ left | right ] <length-percentage>? ] && [ center | [ top | bottom ] <length-percentage>? ]]

where
<length-percentage> = <length> | <percentage>

Example

HTML Content

<div id="container">
  <div>
    <p>At coordinate (0, 0)</p>
    <div class="scrollContainer coordinate0">
      <div>1</div>
      <div>2</div>
      <div>3</div>
    </div>
  </div>
  <div>
    <p>At coordinate (25, 0)</p>
    <div class="scrollContainer coordinate25">
      <div>1</div>
      <div>2</div>
      <div>3</div>
    </div>
  </div>
  <div>
    <p>At coordinate (50, 0)</p>
    <div class="scrollContainer coordinate50">
      <div>1</div>
      <div>2</div>
      <div>3</div>
    </div>
  </div>
</div>

CSS Content

#container {
  display: flex;
}
#container > div:nth-child(-n+2) {
  margin-right: 20px;
}
.scrollContainer {
  width: 100px;
  overflow: auto;
  white-space: nowrap;
  scroll-snap-type: mandatory;
  font-size: 0;
}
.scrollContainer > div {
  width: 100px;
  height: 100px;
  display: inline-block;
  line-height: 100px;
  text-align: center;
  font-size: 50px;
}
.coordinate0 > div {
  scroll-snap-coordinate: 0 0;
}
.coordinate25 > div {
  scroll-snap-coordinate: 25px 0;
}
.coordinate50 > div {
  scroll-snap-coordinate: 50px 0;
}
.scrollContainer > div:nth-child(even) {
  background-color: #87ea87;
}
.scrollContainer > div:nth-child(odd) {
  background-color: #87ccea;
}

Specification

Specification Status Comment
CSS Scroll Snap Module Level 1
The definition of 'scroll-snap-coordinate' in that specification.
Candidate Recommendation Initial definition

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support ? 39.0 (39.0) No support No support No support
Feature Android Firefox Mobile (Gecko) Firefox OS IE Phone Opera Mobile Safari Mobile
Basic support No support 39.0 (39.0)[1] 39.0 (39.0) No support No support No support

[1] On Firefox Mobile, available since Gecko 39, but behind the preference layout.css.vertical-text.enabled, disabled by default.

Document Tags and Contributors

 Contributors to this page: chrisdavidmills, HTMLValidator, Sebastianz, fscholz, teoli
 Last updated by: chrisdavidmills,