Dani Springer Dani Springer - 3 months ago 7x
HTML Question

#top Works By Itself

I added this:

<a href="#top">text</a>
to my website.

I clicked on it without adding
anywhere, and it worked.

How come?


This is built into HTML5 according to the spec:

If target is the top of the document, then scroll to the beginning of the document for the Document

In other words, it's a special case and you don't need to specify an ID for the top of the page.

See also MDN:

Note: You can use the special fragment "top" to create a link back to the top of the page; for example <a href="#top">Return to top</a>