Tag Archives: html

ID and ANCHOR – The Bookmark Connection

Some months ago I accidentally discovered the relationship between ID of a tag and the HREF attribute of the ANCHOR – <A> tag when I was searching for something. I got a link to a forum post. It had a BOOKMARK NAME at the end like #xyz. For something, which I don’t remember now, I right-clicked on the first line on the page (because of the bookmark, the page was scrolled down, and the linked post was at the top of the display area of the browser) which was the title/subject of that forum post and then instead of clicking on the desired menu option, I accidentally clicked on the “Inspect Element” option added by the Firebug plugin in Firefox context menu. And I found in the Firebug that there wasn’t any ANCHOR tag, there were lots of DIVisions only, and one division having the ID same as specified in the link to that post. Then some practice and all set in my mind.

You are aware of the relationship between BOOKMARK NAME and HREF attribute of the ANCHOR tag; the above mentioned relationship of BOOKMARK NAME and ID works the same way. Consider the following code:


Output of index.html


Output of book.html


Anchor-Id Illustration

Note that the book.html doesn’t have ANCHOR – <A> tag and NAME attribute for setting heading as bookmark. Still, in the index page, if user clicks on the link of Section 2.A, the book.html will be opened and the page will be scrolled down to the H2 heading of Section 2.A.

So, this works without using ANCHOR tag and NAME attribute in the target page. Don’t fear to use it, all browsers are supporting it, new and old versions as well.


Rate this article

1 vote, 5.00 avg. rating (94% score)