Go to top scroll button showing after scrollbar from javascript

Adding a "Go to top" button to a web page is a common practice to help users easily navigate to the top of the page. You can use JavaScript to show or hide the "Go to top" button depending on the user's scrolling behavior.

To implement this functionality, you can create a button element in your HTML code with a unique ID, for example

Then, you can use JavaScript to add an event listener to the window object to detect when the user scrolls the page.

You can also add an event listener to the "Go to top" button to scroll the page back to the top when the user clicks.

This code uses the window.scrollTo() method to smoothly scroll the page back to the top when the button is clicked.