Get your own website Result Size: 625 x 565
x
 
<!DOCTYPE html>
<html>
<head>
<style>
#container {
  width: 80%;
  aspect-ratio: 2/1;
  margin: auto;
  border: solid black 2px;
  overflow-x: hidden;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  scroll-padding-block-start: 0;
}
.blue {
  background-color: lightblue;
  width: 80%;
  aspect-ratio: 5/2;
}
.green {
  background-color: lightgreen;
  width: 60%;
  aspect-ratio: 2/1;
}
.blue, .green {
  margin: 2px;
  scroll-snap-align: start;
}
</style>
</head>
<body>
<h1>Change scroll-padding-block-start property with JavaScript</h1>
<p>Try first to scroll to see how the child elements snap into place on start of container in block direction.</p>
<p>Now, click button, click inside the container, and see how scrolling behaviour has changed. The elements still snap on start of container like before, but now with a 20px distance in block direction from the start of the container to the child elements.</p>
<button onclick="myFunction()">Try it</button>
<div id="container">
  <div class="blue"></div>
  <div class="green"></div>
  <div class="blue"></div>