Scroll to the top of the page using JavaScript?

// Get The Id
var topPage = document.getElementById(`top-page`)

// On Click, Scroll to the Top of Page
topPage.onclick = () => window.scrollTo({ top: 0, behavior: 'smooth' })

// On scroll, Show/Hide the button
window.onscroll = () => {
  window.scrollY > 500
    ? (topPage.style.display = 'block')
    : (topPage.style.display = 'none')
}

// CSS
body {
    background-color: #111;
    height:5000px;
}


#top-page {
  width: 50px;
  position: fixed;
  right: 30px;
  bottom: 30px;
  cursor: pointer;
  color: white;
  display: none;
}
// HTML
<img id="top-page" src="https://svgshare.com/i/LW3.sv" alt="Top">

3.5
4

                                    window.scroll({top: 0, left: 0});
//Or with jQuery
$('html,body').scrollTop(0);
//with animation
$('html, body').animate({ scrollTop: 0 }, 'fast');

3.5 (4 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
document scroll to top javascript js go to top of page to top page js how to go to top of page javascript scroll to top page javascript scroll section to the top javascript javascript scroll to top' js scroll to top page bring scroll to top javascript scroll to top of page javascript dom move page to top in javascript js document scroll top scroll to the very top javascript scroll to top with javascript scroll to top place on page js how to scroll in js to the top scroll to the top javascript js go top of page scroll top of the page javscript when page is scrolled to top js scroll window to top js how to scroll to top in js how to go to the top of the page in javascript scroll to the top page js how to scroll to the top of the page in javascript javascript scroll on top of page js scroll to the top scroll to top in javascript javascript scroll to top of page how to scroll top in javascript how to scroll top with javascript scroll to top in js scroll to top of page javascript scroll to top using js js scroll top of page scroll to top of page js scroll top page javascript javascript scroll page to top javascript go to top page how to make page scroll to top in javascript return to top of page javascript how to scroll page to top in javascript how to scroll the page to top in javascript scroll screen to top javascript scroll to top of screen javascript java script scroll to top javascript scroll to top scroll to the top of the page javascript scroll to top using javascript js scroll to top of page instantly always scroll to top of the page js javascript move to top of page scroll to the top using js page top javascript how to scroll to the top in javascript scrollto to top move scrollbar to top back to top in html jqury click scroll to top page up js js scroll go to top to the top website css javascript to page top how to find javascript on scroll top scroll bar on top of the page html how to scroll at up of the page when click a button javascript onclick scroll to top html move page up through js jquery to push user to top of page page scroll top page scroll top css How to get to know that site in on top from Js scroll to top jquery scroll to to javascript css scroll to top of page how to use back to top in html scrooll to top javascript how to scroll to top js how to scroll up innjs javascript move scroll to top make page scroll to top javascript is on top of page javascript scroll up scroll to top link to top javascript javascript click scroll to top how to scrolltop with click js click to scroll to #top? js scroll top javascript send to top of page onclick scroll to top javascript scroll page top top javascript top buuton js how to make the go to top button after user scrolls to a div javascript return to top of page add to top of html document js click button scroll scroll page in click in javascript scroll button js js how to go to top page javascript go top of page how to create a scroll back to top button page up in html js go top page scroll on top javascript how to scroll to top of a page automatically using javascript javascrip click go top scroll to top after click javascript on click take to top of page scroll to top javscript go to page top javascript How do I move scroll to top? javascript how to scroll to top of page trasitnation property on bottom to top button using jquery javascript scroll top jquery how to make scroll back top happening on click move to top using document scroll on top javascrip how to scroll top how to scroll up how to make scroll to top button button to scroll to top of page click button to scroll to top website button scroll down scroll page to top javascript add scroll to up html scroll to the top top javascript how to scroll to top of page javascript how to scroll to tio snap to top js javascript set page scroll to top add back to top to web page scrolls onclick page scroll up html javascript scroll to top how to get top screen scroll in js js page is on the top scroll top javascript on click scroll to top of page javascript to scroll to top of paeg jquery scroll to top Button onClick makes page not jump to top of page in mobile view to top of page html javascript scroll to top of page onclick javascript how to jump to top of page html scroll to top css to return to the top page js scroll page up move to the top of the page in javascript html onclick scroll to top js scroll top page scroll to top in jquery javascript set scroll to top of page function scrolup css scroll to top of div scroll top in jquery scroll to top window javascript js window scroll to top javascritp jumper to top of window scroll to top javascript jump to top of page html go to top of page html how to set easy scroll in a tag in html html esay scroll to top of page onclick to go to the top of the page bring page to the top of page html scrollto top GO TO TOP PAGE CSS scroll in the same page add top scroll css top scroll page to top setting the scroll page to top in javascript how to scroll to top in javascript to top using js return to top js scroll to top on click css scroll to top javascript scroll to top function scroll to top on click java how to make a scroll up in js php scroll to top of page auto scroll to top of page javascript how scroll top on page js scroll to topc js js scroll top top css button to go to the top of the page scroll to the top of the page with jquery Scroll to the top of the page using JavaScript js scroll to top js scroll to top of page Scroll to the top of the page using JavaScript? onclick auto scroll to to top of page js scroll to the top of the page javascript scroll to the top how to press a button and autmatically scroll down to the another portion html css start top of page onclick javascript button that scrolls to the top scroll up css js scroll to top of page on click how to find the top of page browers with javascript function when scrolltop to top function when scrolled to top send user to the top of the page javascript jvascript scroll to the top of the page html css jump to the complete top scroll back to top scroll top of page html go to top of page javascript top of page how to scroll top javascript how to scroll to top of page in javascript how to scroll to the top of a page body scroll to top how to scroll to top of the page javascrip move page to top on Link scroll to the top of the page on click scroll to top scroll to page how to bring on the top of page in html move to top of page javascript move to the top on scroll js go top goto to top in html window scroll to top on button click javascript scroll to the top css move scroll to top go to top page go to page begin from js js go to top scroolup by css javascript go to top site how to scroll to top HTML element click go top go to top of page javascript how to move to top of page in html on click html link back to top scroll to top html html top of page scroll to top js css to make scroll to top javascript go to top of page
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source