Page 1 of 1

HTML Anchors with name or id?

Posted: 14 Nov 2014, 08:32
by Marius
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?

HTML Anchors with name or id?

Posted: 14 Nov 2014, 08:41
by Admin
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.