Deprecation of the "a" Tag Name Attribute
The name attribute of the "a" (link) tag is not supported in HTML5.
The function of the named anchor is for scrolling to a certain point on a page when a link is clicked. It is used to create a bookmark inside a web page.
Live example: Scroll to bottom of article.
The above link is:
<a href="#bottom_of_article">Scroll to bottom of article.</a>
Near the bottom of the article is the named anchor to be scrolled to:
<a name="bottom_of_article">[point scrolled to]</a>
Optionally, the link text may be absent:
<a name="bottom_of_article"></a>
The in-page bookmarking method is in two parts.
-
A link with a "#" symbol followed by the value of an "a" tag name attribute. The href contains the #value.
-
The #value can be by itself as the href value (for same-page bookmark).
-
Alternatively, the #value can be appended to a URL (for bookmarking a location within a different web page).
Examples:
<a href="#value">Link text</a> <a href="page.php#value">Link text</a> <a href="http://example.com/#value">Link text</a> <a href="http://example.com/page.php#value">Link text</a>
-
-
A link with a name value. In this one case, the href tag is optional. Link text is also optional. Examples:
<a name="value"></a> <a href="." name="value">Home page</a>
The named anchor method for in-page bookmarks will continue to work in browsers for a while. Perhaps for years. The HTML5 specification has not yet been finalized.
Although the named anchor method may be workable for many years, it can't be counted on. For new projects, use the new method, an id attribute instead of a name attribute.
The New In-page Bookmarking Method
The new method is to use the id attribute instead of the name attribute. The id attribute can be in an "a" tag or any other HTML tag that can have an id attribute – div, span, td, pre, etc.
The new method also works in HTML4. So you can start using it now and have it work just fine.
-
The first part of the in-page bookmarking method is the same for the new method as it is for the named link method (the link at the place to click).
The first part is an "a" tag with a "#" symbol followed by the value of an id attribute as the a tag's href value. The #value can be by itself or the #value can be appended to a URL. Examples:
<a href="#value">Link text</a> <a href="page.php#value">Link text</a> <a href="http://example.com/#value">Link text</a> <a href="http://example.com/page.php#value">Link text</a>
-
But the second part is different than the first method. Instead of name="value", use id="value". Examples:
<div id="value1">content</div> <span id="value2">content</span> <a href="sale.html" id="value3">Link text</a> <td id="value4">content</td>
The id can be the attribute of any HTML tag that can have an id.
Note that id values must be unique on a web page. There can be no two id="here" on the page, for example.
Example Scroll-To Location
The live example "Scroll to bottom of article" link near the beginning of the article scrolls the page to the next paragraph.
The above link can be used to scroll back up.
With the a tag name attribute on the way out, it may be prudent to use the id value, instead, for new websites or when redesigning websites. The id value method does work with the current HTML version, HTML4.
Will Bontrager