How to create a link that goes to the top of a web page
To create a link that goes to the top of a web page, follow the steps below.
In your HTML code, find the opening <body> tag (this should be located right after the closing </head> tag). Immediately after the opening <body> tag, add the following code:
The above code would create an anchor on the page named top.
Next, place the link back to the top of the page by using the # symbol followed by the anchor name/id (in this case top) as the value of the href attribute, as shown below:
<a href="#top">Back to top of page</a>
If you have scrolled down on this page, clicking on this link takes you back to the top of the page.
All modern browsers today understand #top, so even if your id or <a name="top"></a> anchor is not in your page, it will still return you to the top of the page. However, all other anchors need to be defined in the page.