{"id":238222,"date":"2016-03-02T06:45:41","date_gmt":"2016-03-02T13:45:41","guid":{"rendered":"http:\/\/css-tricks.com\/?p=238222"},"modified":"2019-07-28T15:04:24","modified_gmt":"2019-07-28T22:04:24","slug":"introducing-css-scroll-snap-points","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/introducing-css-scroll-snap-points\/","title":{"rendered":"Introducing CSS Scroll Snap Points"},"content":{"rendered":"

Before this new CSS I’m about to introduce existed, locking an element into the viewport on scroll<\/em> required rigging up some JavaScript. As you may know, JavaScript has a well-earned reputation to be tricky when paired with scrolling behavior.<\/p>\n

The new CSS Scroll Snap Points spec<\/a> promises to help, allowing for this kind of behavior using very few lines of CSS. <\/p>\n

As happens with very new web tech, this spec has changed over time. There is “old” and “new” properties and values. It’s promising though, as support<\/a> has shot up quickly. I’ll teach you how to get the widest support in this in-between stage.<\/p>\n

<\/p>\n

Polyfilled Demo<\/h3>\n

The demo below has horizontal scrolling. It’s responsive: each “panel” is the width and height of the viewport (thanks to vh<\/code> and vw<\/code> units). <\/p>\n

It uses a polyfill<\/a>, but in order to use it (and support is still low enough that I suggest you do), you have to support the “old” values, which is why I’ll cover them, too. <\/p>\n

See the Pen Simple Responsive Scroll Snap Point Demo<\/a> by CSS-Tricks (@css-tricks<\/a>) on CodePen<\/a>.<\/p>\n