CSS - scroll-padding-top
CSS scroll-padding-top property specifies the top offset of the scroll snap area of an element.
A scroll snap area is the area of a scrolling container that an element will snap to when the user scrolls.
Possible Values
-
<length> − A length value is a numeric value, such as px, em, percentage.
Applies to
All the HTML elements.
DOM Syntax
object.style.scrollPaddingTop = "length";
CSS Scroll Padding Top - Zero Value
The following example demonstrates how to use the scroll-padding-top property to make sure that there is no padding at the top of the container −
<html>
<head>
<style>
.scroll-container {
width: 350px;
height: 200px;
overflow-x: hidden;
overflow-y: scroll;
scroll-snap-type: y mandatory;
scroll-padding-top: 0;
}
.scrolling-section1,
.scrolling-section2,
.scrolling-section3 {
width: 350px;
height: 200px;
scroll-snap-align: start;
}
.scrolling-section1 {
background-color: rgb(220, 235, 153);
}
.scrolling-section2 {
background-color: rgb(230, 173, 218);
}
.scrolling-section3 {
background-color: rgb(119, 224, 210);
}
</style>
</head>
<body>
<h3>Scroll the content using the scrollbar arrows to see the effect.</h3>
<div class="scroll-container">
<div class="scrolling-section1">scroll-padding-top: 0</div>
<div class="scrolling-section2">scroll-padding-top: 0</div>
<div class="scrolling-section3">scroll-padding-top: 0</div>
</div>
</body>
</html>
CSS Scroll Padding Top - Length Value
The following example demonstrates how to use scroll-padding-top property to adds extra padding at the top of the scroll container −
<html>
<head>
<style>
.scroll-container {
width: 350px;
height: 200px;
overflow-x: hidden;
overflow-y: scroll;
scroll-snap-type: y mandatory;
scroll-padding-top: 25px;
}
.scrolling-section1,
.scrolling-section2,
.scrolling-section3 {
width: 350px;
height: 200px;
scroll-snap-align: start;
}
.scrolling-section1 {
background-color: rgb(220, 235, 153);
}
.scrolling-section2 {
background-color: rgb(230, 173, 218);
}
.scrolling-section3 {
background-color: rgb(119, 224, 210);
}
</style>
</head>
<body>
<h3>Scroll the content using the scrollbar arrows to see the effect.</h3>
<div class="scroll-container">
<div class="scrolling-section1">scroll-padding-top: 25px</div>
<div class="scrolling-section2">scroll-padding-top: 25px</div>
<div class="scrolling-section3">scroll-padding-top: 25px</div>
</div>
</body>
</html>
Advertisements