How do I link to part of a page? (hash?)

Haroldo picture Haroldo · May 14, 2010 · Viewed 357.7k times · Source

How do you link (with <a>) so that the browser goes to certain subheading on the target page as opposed to the top?

Answer

Daniel DiPaolo picture Daniel DiPaolo · May 14, 2010

If there is any tag with an id (e.g., <div id="foo">), then you can simply append #foo to the URL. Otherwise, you can't arbitrarily link to portions of a page.

Here's a complete example: <a href="http://example.com/page.html#foo">Jump to #foo on page.html</a>

Linking content on the same page example: <a href="#foo">Jump to #foo on same page</a>

It is called URL fragment.