Changes in HTML 5 - <a> Tag
What's new in HTML 5
The media
attribute has been added for consistency with the <link> tag.
The target
attribute has been resurrected in HTML 5. It really did not exist in either HTML 4 or XHTML, although it was the easiest way to open a web page in a new window. As a result, it was used on many web pages, which therefore would fail validation.
In HTML 5, you can put the <a> tag around block elements in addition to inline elements. This means that links can appear where they couldn't before. For example, you can turn a whole HTML table row into a link:
<table> <tr><td>Label:</td><td>Data...</td></tr> ... <tr onclick="location=this.getElementsByTagName('a')[0]"> <a href="new-row.html"/> <td colspan="2">Add a Row</td> </tr> </table>
Differences between HTML 5 and earlier versions of HTML
The <a>
tag with a name
or id
attribute is no longer used as a placemark for the target of a hypertext link. Most HTML tags may now include an id
attribute for that purpose. Therefore, whenever there is an <a> tag with an id
or name
attribute but no href
attribute, the value of the attribute should be coded as the id
attribute of the tag following it:
<a id="whats-new"/> <p>New features of HTML 5 include ....</p> <p id="whats-new">New features of HTML 5 include ....</p> <p>See <a href="#whats-new">What's New in HTML 5</a> above.</p>
An <a>
tag without an href
attribute is now only a placeholder that may later be turned into a hypertext link via dynamic JavaScript code.
The following attributes should not be coded on the <a> tag because they either have been deprecated or were never officially supported:
name
- if the tag is being used for both a hypertext link and the target of a reference from somewhere else, use theid
attribute instead; if it's not a hypertext link, code theid
attribute on a different tag at the target location as shown abovecharset
coords
ref
shape
The 2000-2010 Recommendations from the W3C HTML Working Group defined the HTML namespace for the a element type name along with the names of all HTML element types. In older (pre-2000) versions of HTML, element type names were not associated with a namespace.