Wikipedia makes heavy use of this feature like this:
<a href="#History">[...]</a>
<span class="mw-headline" id="History">History</span>
And Wikipedia is working for everybody, so I would feel safe sticking with this form.
Also don't forget, you can use this not only with spans but with divs or even table cells, and then you have access to the :target pseudo-class on the element. Just watch out not to change the width, like with bold text, cause that moves content around, which is disturbing.
Named anchors - my vote is to avoid:
- "Names and ids are in the same namespace..." - Two attributes with the same namespace is just crazy. Let's just say deprecated already.
- "Anchors elements without href atribute" - Yet again, the nature of an element (hyperlink or not) is defined by having an atribute?! Double crazy. Common sense says to avoid it altogether.
- If you ever style an anchor without a pseudo-class, the styling applies to each. In CSS3 you can get around this with attribute selectors (or same styling for each pseudoclass), but still it's a workaround. This usually doesn't come up because you choose colors per pseudo-class, and the underline being present by default it only makes sense to remove, which makes it the same as other text. But you ever decide to make your links bold, it'll cause trouble.
- Netscape 4 might not support the id feature, but still an unknown attribute won't cause any trouble. That's what called compatibility for me.
http://example.com#foo
(so without the / before #) – Tramwayhttp://example.com#foo
andhttp://example.com/#foo
are equivalent as defined in one of the RFCs on URIs. – Evangel<h1 id="foo"></h1>
can be referenced fromwindow.foo
in Javascript, which may not be what you are expecting, see https://mcmap.net/q/46718/-should-i-make-html-anchors-with-39-name-39-or-39-id-39 – Tarpan