How can I create a link to a specific position on a web page?

The vanilla way link to somewhere in-page is via an anchor point already present in the page.

This can be created using the <a>…</a> tag. Note that the link specified in "anchor point" (above) has #h-12.2 at the end. This corresponds to <a id="h-12.2">12.2</a> embedded in the HTML forming the page, and when clicked will reposition the page view to this anchor.

Note that prior to HTML5, the name attribute was used in the anchor tag, but is no longer supported and the id attribute should be used in its place (reference). This also means that you can use any element for an anchor tag, you are not limited to the <a> element.


Similar to Paul's answer, you can also link to the first occurrence of a tag ID in an HTML document. This won't be an exact number of pixels though.

For example, link/scroll to this page's question or answers.


Try right-clicking and Inspecting Elements on the page. You'll find the <a> tags, those are the anchor points.

Then take out the < before the first and last a so that they would not show up as the links. You can actually see the effects while writing in the response box when it shows you the preview below.

a href="https://superuser.com/questions/382047/linking-to-a-specific-scroll-position-on-a-web-page#question-header">question /a>

and

a href="https://superuser.com/questions/382047/linking-to-a-specific-scroll-position-on-a-web-page#answers">answers /a>

As you can see, the only difference is at the very end where the anchor names after the pound (#) symbol. the name after the > is for how the link reads to the user.

In this case "question-header" reads as "question" and answers happens to be the same.

Then the following should link to Mike's comment. Since their anchor point is 382094

To clarify, you can simply find the anchor and add the # after your link.

https://superuser.com/questions/382047/linking-to-a-specific-scroll-position-on-a-web-page#question-header

https://superuser.com/questions/382047/linking-to-a-specific-scroll-position-on-a-web-page#answers

https://superuser.com/questions/382047/linking-to-a-specific-scroll-position-on-a-web-page#880079

these will all take you to different places on the same page.