• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
JavaScriptSource

JavaScriptSource

Search 5,000+ Free JavaScript Snippets

  • Home
  • Browse Snippets
    • Addon
    • Ajax
    • Buttons
    • Cookies
    • CSS
    • Featured
    • Forms
    • Games
    • Generators
    • Image Effects
    • Math Related
    • Miscellaneous
    • Multimedia
    • Navigation
    • Page Details
    • Passwords
    • Text Effects
    • Time & Date
    • User Details
Home / Navigation / Scroll to top of the page

Scroll to top of the page

Scroll to top of the page

In general, you can scroll to a point whose coordinates indicates the distance from it to the top and left side of document. So, the following code scrolls to top of the page:

// window.scrollTo(pageX, pageY);

window.scrollTo(0, 0);

Utilizing this snippet, you can add a button at the bottom of page that allows user to scroll to the top quickly.

Source

https://htmldom.dev/scroll-to-top-of-the-page/

Navigation

Related Snippets:

  • Smooth Scroll to the Top of the Page With JavaScript
  • Using the Target Attribute
  • Detecting when a visitor has stopped scrolling
  • Drag to scroll

Primary Sidebar

Popular Posts

Story Generator

IP Grabber – get a users IP address with JavaScript

Simple Calendar

Remove Ads

Astrological Calculator

Copyright © 2025 JavaScriptSource.com

  • About
  • Privacy Policy
  • FAQ
  • Jobs For Developers