HTML & CSS · Senior · Question 22 of 75

How do you build a horizontal gallery with slides that "snap" into place without JavaScript?

Explanation

CSS Scroll Snap: a container with overflow-x: auto and scroll-snap-type: x mandatory, slides with scroll-snap-align. The browser settles the scroll on the nearest slide and supports touch, wheel and keyboard. scroll-padding accounts for fixed elements. JS is only needed for prev/next buttons and indicators.

Further reading

Problem with a question

HTML & CSS · Senior · question 22

Test yourself

Take the HTML & CSS · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz