HTML Anchors with name or id?

Place to talk about website HTM elements, CSS style and design, and get help with HTML, CSS codes.
Marius
Posts: 107

HTML Anchors with name or id?

When I want to refer to some part of a webpage with the "example.com/page#Mark"-method, should I use:

Code: Select all

<h3><a name="foo"/>Mark Title</h3>
Or:

Code: Select all

<h3 id="Mark">Mark Title</h3>
I know that both work, but are they equal, or do they have semantic differences?

Admin Posts: 805
Hi
In HTML5 the <a> element has no name attribute.
My vote is for ID.

Code: Select all

<a href="#Mark">Link Text</a>
... Content ...
<span id="Mark">Mark Title</span>
You can use this not only with spans but with divs or even table cells, and then you have access in CSS to the :target pseudo-class on the element.