<body>
  Scroll
  <button onClick="scrollToTop()">Top</button>
</body>
body {
    height: 200vh;
    position: relative;
    font-size: 2rem;
    text-align: center;
}

button {
    background: #1a1a1a;
    color: white;
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
}
function scrollToTop() {
    window.scroll({
        top: 0,
        left: 0,
        behavior: 'smooth'  
    });
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.