Just to finish this off, here’s how it’s all connected.
The HTML 4.01 spec has several sections that bring this all together.
Target Anchor? Anchor Element?
The fragment identifer section gives a brief example of how the URI is used to refer to a certain location. Even though it says that it’s pointing to an anchor, that doesn’t mean to say that it’s pointing to an anchor element. Keep in mind that by “anchor element” they don’t mean the <a> element. Instead, a much broader meaning is meant.
The section on the id attribute helps to clarify this, as the spec says that id is used for several tasks, including: "As a target anchor for [url=“http://www.w3.org/TR/html401/struct/links.html#anchors”]hypertext links" which links to the introduction page.
It’s called a “target anchor” not because the id attribute is on hypertext links, it can be on virtually any HTML element at all. The target anchor allows some other page to use a hypertext link to link directly to an element within the target page. The id attribute serves as a target anchor.
The introduction to links and anchors section provides much fuller details on how fragment identifiers work. It also links through to the [url=“http://www.w3.org/TR/html401/struct/links.html#adef-name-A”]name section which includes a link to the [url=“http://www.w3.org/TR/html401/struct/links.html#anchors-with-id”]Anchors with the id attribute section.
How is the Name attribute affected?
At the time of the HTML 4.01 spec in 1999, they were transitioning over from using the name attribute on a limited number of HTML elements, to using the id attribute on virtually everything. 12 years ago they still had to provide consideration for web browsers that didn’t support HTML4. Unthinkable now, but that was back in the day.
As time moved on and they developed the spec for XHTML (there’s only one year between HTML 4.01 and XHTML 1.0), they had formally deprecated the use of name attribute on all elements except for those used to provide form data. In the XHTML [url=“http://www.w3.org/TR/xhtml1/#C_8”]fragment identifiers section they talk about completely removing the name attribute from all other elements.
Why would they do that? Because if we look back at the HTML 4.01 specs for forms, we find that in the form controls section that the name attribute has a special task to perform within forms themself, that has nothing to do with fragment identifiers.
In effect, the purpose of the name attribute is now solely meant for data fields within forms. And in fact, with the HTML5 spec we now find that the [url=“http://www.w3.org/TR/html5/association-of-controls-and-forms.html#attr-fe-name”]name is exclusively used only for forms now.
Summary
Now more than 10 years on from HTML 4.01 and XHTML 1.0, the id attribute remains as the favored method by which to uniquely identify different parts of a web page.