Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Putting some code through the html5 validator, I get this:

Warning: The name attribute on the a element is obsolete. Consider putting an id attribute on the nearest container instead.

I find that unclear. Is the "nearest container" for an anchor link the a itself, so that the correct code would be <a id='blah'> instead of <a name='blah'>? Or are empty placeholder <a> tags as a whole deprecated, and anchors can simply point to any element with an id instead?

share|improve this question

2 Answers 2

up vote 6 down vote accepted

[A]re empty placeholder tags as a whole deprecated, and anchors can simply point to any element with an id instead?

I prefer to jump users to heading tags (following MediaWiki's default behavior) where in-page links are needed, but yes, you could address the ID of any element.

share|improve this answer

If you need to jump users to in-page links, you can set the id attribute (which is used for more than just in-page links) on any element. Then use the usual # in the URL of a href attribute of an a element. Here's an example:

<body>
    <p>Despite the many
        <a href="#gum-benefits">benefits</a>
    you may experience while chewing gum, there are also many drawbacks,
    especially with 
        <a href="http://www.example.org/sugar.html#cons">non-sugarless</a>
    gum.</p>
    ...
    <section id="gum-benefits">
        <h1>Benefits of Gum Chewing</h1>
        ...
    </section>
</body>

When writing my own pages, I like to give an id to each <section> tag (HTML5), even if I don't plan on using it. You can achieve the same effect by assigning ids to <h1> (etc) tags.

Lastly, empty <a> tags are not deprecated, as indicated in the HTML5 docs:

If the a element has no href attribute, then the element represents a placeholder for where a link might otherwise have been placed

share|improve this answer
    
Typo in code example: "#gum-benefits needs a closing quote mark. –  Basil Bourque Dec 6 '12 at 11:41
    
@BasilBourque Thanks for catching the typo. I fixed it. –  chharvey Dec 7 '12 at 5:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.