Back to Top – Link to Top of the Page

Here is a quick tip for you guys. I still remember the first time I needed a link that user can click to get to the top of the page. I used to add an anchor tag like this <a href=”#” name=”top”></a> to the top of the page and then somewhere down the page link to it as:

<a href="#top">Back to Top</a>

The problem with this method was that you had to add an extra element (anchor tag) to the top of the page. Recently, I achieved the same goal slightly differently. I added an id to the body of the page. e.g.

<body id="top">

Then down the page I created a link:

<a href="#top">Back to Top</a>

Thats it! You don’t need to add that anchor on top, simply use the existing body element and give it an ID.

Leave a Reply

Your email address will not be published. Required fields are marked *