How to create a link that goes to the top of a web page

Updated: 12/30/2019 by Computer Hope

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.

<a name="top"></a>

The code above creates an anchor on the page named top.

Next, add the top of page link using the # symbol and "top" anchor name/id as the value of the href attribute, as shown below.

<a href="#top">Back to top of page</a>

If you scrolled down on this page, clicking this link takes you back to the top of the page.

Tip

All modern browsers understand the "#top" value. Even if the id or <a name="top"></a> anchor is not used, you still return to the top of the page. However, all other anchors need to be defined in the page.

Additional information