8

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?

phxvyper
  • 364
  • 1
  • 4
  • 13

2 Answers2

10

Just markup the header on the target page with the id "about" i.e.

About

That way your link on the linking page http://www.thisisawebsite.com/page.php#about will go straight to the "about" header - a h1 in this example but it could be whatever you'd given the id of "about". Remember you should only use the id "about" once on the page though.

Nicolae Maties
  • 2,476
  • 1
  • 16
  • 26
Richard Jordan
  • 8,066
  • 3
  • 39
  • 45
  • I did forget to thank you for your answer as well. I will use yours considering i found it it can be used as an attribute an pretty much all tags, while name only works with a few... – phxvyper Dec 02 '12 at 01:57
9

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

Kevin Boucher
  • 16,426
  • 3
  • 48
  • 55