skip to main content

TAMU Webmaster's Blog


Information and insight from the A&M Webmasters

Anorexic Anchors

October 16th, 2008 by Erick Beck

Credit for the catchy title goes to Tantek Celik who coined the phrase and first documented this interesting feature of HTML.

Anorexic Anchors are just a small part of a movement toward the use of semantic HTML, of which I am quickly becoming a fan. We have all seen introductory attempts to introduce the concept — using <strong> tags for <b> and <em> for <i> but it goes much farther. Our beloved anchor tags (<a name="anchorTarget"></a>) are not needed at all!

We can achieve the same result on any tag with the id attribute.

<a href=”#exampleAnchor”>Link to anchor</a>
. . .
. . .
<h2 id=”exampleAnchor”></h2>

Not that there was anything wrong with the old way, but look at the code again. We were including an empty anchor tag which held no value on its own and technically wasn’t even the target of the anchor link – we just put it in close proximity to the text that we really wanted the link to go to. Now you can put your target location directly on any element and have links from within the same page go directly there.

Thursday, October 16th, 2008 HTML
Share this article

4 Comments to Anorexic Anchors

  1. Kind of funny, I was just explaining this to someone in my office last week.

  2. Matt Herzberger on October 19th, 2008
  3. Very Nice. Are there any browsers that have issues with this setup?

  4. James on October 21st, 2008
  5. I haven’t done an exhaustive study, but it seems to work with the modern set of browsers anway.

  6. Erick on October 21st, 2008
  7. I believe there may be some IE6 issues. I have been using these for awhile and having weird issues.

  8. Matt herzberger on October 21st, 2008

Leave a comment

Categories

Archives