In a scenario where we need to scroll to the top of a web page, we can use JavaScript’s scrollTo. Consider the scenario where there is a page filled with text, and the scroll bar appears.

With a scroll button at the bottom:

We can add the following code to set the window to it’s x/y coordinates:
window.scrollTo(0,0);
Full code:

When clicking the button, the page will scroll to the top:


Keep learning. Keep building.
Explore AI, agents & Microsoft technology.
I share practical ideas, tutorials, and videos about AI, AI agents, Microsoft technologies, and the Power Platform.
Subscribe on YouTube →Carl de Souza Enterprise Architect at Microsoft · AI Technology Expert