Search code examples
htmlurlhyperlinkheader

in HTML, url contains #, scroll page to header?


If my url is something like: http://www.thisisawebsite.com/page.php#about
How do i make it so when the link is clicked, it'll go to the header "about", or anywhere else i so desire?


Solution

  • You need to define the anchor in your markup (near your 'About' header):

    <a name="about"></a>
    

    Anyone else having a question about this should explore using an ID attribute on the actual element they want to link to:

    <h1 id="about">About</h1>
    

    UPDATE As mentioned by some in the comments, name is a deprecated attribute on the a tag:

    Was required to define a possible target location in a page. In HTML 4.01, id and name could both be used on , as long as they had identical values.

    Note: Use the global attribute id instead.

    https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a