Mobile app version of vmapp.org
Login or Join
Alves908

: Name attribute is obsolete, what is the correct behavior when dealing with anchors? When testing my code using the w3 html5 validator, I get this warning message: Warning: The name attribute

@Alves908

Posted in: #Anchor #Html5 #Markup #W3cValidation

When testing my code using the w3 html5 validator, I get this warning message:


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


Question(s):


What does the nearest container mean?
Is <a> now deprecated?
Should I use id instead of name?

10.03% popularity Vote Up Vote Down


Login to follow query

More posts by @Alves908

3 Comments

Sorted by latest first Latest Oldest Best

 

@Martha676

For HTML5, name attribute is now deprecated, so that means to use id in place of name. Otherwise, everything else is the same.

<a> is NOT deprecated.

10% popularity Vote Up Vote Down


 

@Kevin317

If you need to jump users to in-page links, also known as fragment identifiers, you can set the id attribute (which is used for more than just frag ids) 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="#benefits-of-gum-chewing">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="benefits-of-gum-chewing">
<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. The value of the id is a URL-friendly version of its heading’s content. You can achieve the same effect by assigning the same id to an <h1>, etc.

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


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


Additionally the same applies for area elements:


The href attribute on a and area elements is not required; when those elements do not have href attributes they do not create hyperlinks.

10% popularity Vote Up Vote Down


 

@XinRu657

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

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme