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: scroll;
  overflow-y: hidden;
  white-space: nowrap;
  scroll-snap-type: x mandatory;
}
.blue {
  background-color: lightblue;
  height: 95%;
  aspect-ratio: 3/4;
}
.green {
  background-color: lightgreen;
  height: 80%;
  aspect-ratio: 2/3;
}
.blue, .green {
  margin: 2px;
  display: inline-block;
  scroll-snap-align: start;
  scroll-margin-inline: 0;
}
</style>
</head>
<body>
<h1>Change scroll-margin-inline property with JavaScript</h1>
<p>Try first to scroll to see how the scroll snaps on start of elements in inline direction.</p>
<p>Now, click button, click inside the container, and see how scrolling behaviour has changed. The elements still snap on start of element like before, but now with a 20px margin to container at the start of the elements in inline direction.</p>
<button onclick="myFunction()">Try it</button>
<div id="container">
  <div class="blue"></div>