Don't Name Anchor Elements? ~ Fri, 29 Oct 2010 14:26:49 +0000
I have not used XHTML, regularly, in years. In fact, when I was writing all the markup for this site myself, I dropped XHTML back in 2004. Instead, I wrote strict compliant HTML 4.01. But nowadays I'm switching to HTML5 for all of my new work. It simplifies several things and adds some awesome new features (which more and more browsers are implementing). But HTML5 seems to also be pulling in some XHTML ideas.
I had a need to link to a specific section of a document earlier. So, naturally, I created an anchor element and gave it a 'name' attribute. The editor I was using gave me a validation warning that HTML5 doesn't support the name attribute on the anchor element. This confused me, so I had to research it. Not able to find any information regarding this issue in the draft specification, I turned to the IRC. In #whatwg on irc.freenode.org I got the answer. Turns out, XHTML 1.0 deprecated the name attribute and the HTML5 working group brought that decision along as making the name attribute "obsolete." Instead, the id attribute is to be used.
Further, the 'a' element, in HTML5, is now strictly considered a "hyperlink" and not either an "anchor" or a "hyperlink." So the real recommendation is to give a parent element, such as a div, an id attribute and create links to that element. In other words, this (HTML 4.01):
Becomes this (HTML5):
Hopefully you won't be as confused as I was, now.