The scroll-padding property defines the distance from the container
to the snap position of child elements. This means that when scrolling stops, the scroll will quickly adjust and stop at
a specified distance from the container to the snap position of the focused child element. The scroll-padding
property is a shorthand for scroll-padding-top,
scroll-padding-bottom,
scroll-padding-left, and
scroll-padding-right properties. The value can be set in various
ways.
EXAMPLE
RESULT
If the property has four values: scroll-padding: 100px 150px 200px 250px;
Top distance is 100px.
Right distance is 150px.
Bottom distance is 200px.
Left distance is 250px.
If the property has three values: scroll-padding: 150px 100px 200px;
Top distance is 150px.
Right and left distance is 100px.
Bottom distance is 200px.
If the property has two values: scroll-padding: 100px 200px;
Top and bottom distance is 100px.
Right and left distance is 200px.
If the property has one value: scroll-padding: 150px;
All four distances are equal, 150px.
To see the effect of the scroll-padding property, the
scroll-snap-align property must be set on child elements, while
scroll-padding and scroll-snap-type properties must be set
on the parent element.
Comparison of Different scroll-padding Values:
Instructions for use:
The dashed red area shows the scroll-padding space
Scroll through each box and observe how elements "snap" at different
distances
Red numbers show the actual offset values
scroll-padding: 150px
150px
150px
150px
150px
Element 1
Element 2
Element 3
Element 4
scroll-padding: 100px 200px
100px
200px
100px
200px
Element 1
Element 2
Element 3
Element 4
scroll-padding: 150px 100px 200px
150px
100px
200px
100px
Element 1
Element 2
Element 3
Element 4
scroll-padding: 100px 150px 200px 250px
100px
150px
200px
250px
Element 1
Element 2
Element 3
Element 4
We use cookies for a better user experience and website functionality.