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?

- 364
- 1
- 4
- 13
-
Look at this. http://www.w3schools.com/html/html_links.asp – manuerumx Oct 23 '12 at 22:37
-
Take a look at http://www.w3.org/TR/xhtml1/#h-4.10, http://stackoverflow.com/questions/484719/html-anchors-with-name-or-id – Musa Oct 23 '12 at 22:47
2 Answers
Just markup the header on the target page with the id "about" i.e.
AboutThat 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.

- 2,476
- 1
- 16
- 26

- 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
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.

- 16,426
- 3
- 48
- 55
-
You're welcome. If that works for you, please feel free to 'Accept' this answer. – Kevin Boucher Oct 23 '12 at 22:43
-
Is that what the questioner is asking? I thought you wanted to go to the
about
on your page.php when someone clicks on a link in the format http://www.thisisawebsite.com/page.php#about in which case the answer is to markup the h1 itself with – Richard Jordan Oct 23 '12 at 22:50 -
6 of one, 1/2 dozen of the other. (Cool, though. Didn't know you could do it that way.) +1 for teaching me something new – Kevin Boucher Oct 23 '12 at 22:55
-
-
Thanks also, i'll use kevin's method though considering I'm not using an actual header, just text that is bold (and appears bigger than most of the other text). – phxvyper Oct 23 '12 at 23:17
-
1Hmm... but it's not the anchor you need to give the name - it's the element you want to be the target on the page. So the text in this case - it can be a span whatever. You should put the ID on the correct element NOT on an tag somewhere nearby. That's not the correct approach, and it's not the correct answer for others coming here and referencing this. – Richard Jordan Oct 23 '12 at 23:40
-
The `name` attribute (for `a` and some other elements) is [obsolete in HTML5](http://www.w3.org/TR/html5/obsolete.html#attr-a-name). Use `id` instead, as Richard Jordan suggested in [his answer](http://stackoverflow.com/a/13040490/1591669). – unor Oct 24 '12 at 15:01