{{CSSRef}}{{SeeCompatTable}}
Summary
The scroll-snap-destination
CSS property defines the position in x and y coordinates within the scroll container's visual {{Glossary("viewport")}} which element snap points align with.
{{cssinfo}}
Syntax
/* <position> value */ scroll-snap-destination: 400px 600px; /* Global values */ scroll-snap-destination: inherit; scroll-snap-destination: initial; scroll-snap-destination: unset;
Values
<position>
- Specifies the offset of the snap destination from the start edge of the scroll container’s visual viewport. The first value gives the x coordinate of the snap destination, the second value its y coordinate.
Formal syntax
{{csssyntax2}}
Example
HTML Content
<div id="container"> <div> <p>At coordinate (0, 0)</p> <div class="scrollContainer destination0"> <div>1</div> <div>2</div> <div>3</div> </div> </div> <div> <p>At coordinate (25, 0)</p> <div class="scrollContainer destination25"> <div>1</div> <div>2</div> <div>3</div> </div> </div> <div> <p>At coordinate (50, 0)</p> <div class="scrollContainer destination50"> <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-points-x: repeat(100%); scroll-snap-type: mandatory; scroll-snap-destination: 20px 0; font-size: 0; } .destination0 { scroll-snap-destination: 0 0; } .destination25 { scroll-snap-destination: 25px 0; } .destination50 { scroll-snap-destination: 50px 0; } .scrollContainer > div { width: 100px; height: 100px; display: inline-block; line-height: 100px; text-align: center; font-size: 50px; } .scrollContainer > div:nth-child(even) { background-color: #87EA87; } .scrollContainer > div:nth-child(odd) { background-color: #87CCEA; }
{{EmbedLiveSample("Example", "100%", "170")}}
Specification
Specification | Status | Comment |
---|---|---|
{{SpecName("CSS Scroll Snap Points", "#propdef-scroll-snap-destination", "scroll-snap-destination")}} | {{Spec2("CSS Scroll Snap Points")}} | Initial definition |
Browser compatibility
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | {{CompatUnknown}} | {{CompatGeckoDesktop("39.0")}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
Feature | Android | Firefox Mobile (Gecko) | Firefox OS | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | {{CompatNo}} | {{CompatGeckoMobile("39.0") }}[1] | {{CompatGeckoMobile("39.0") }} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
[1] On Firefox Mobile, available since Gecko 39, but behind the preference layout.css.vertical-text.enabled
, disabled by default.