Why do you need an anchor tag that is not a link? (no href attribute?)

Problem

I read a couple of older SO posts exploring information about anchor pseudo-classes, and continue to run into confusion between "a" and "a: link", and when and why you will use it. In the most common reason I've seen, it is often said that "a" will create links like

<a name="something"> 

My questions

  • I'm just wondering if anyone can explain WHY do you want to do something like this?
  • I read that maybe it has something with JavaScript targeting, but with HTML5 / CSS3 and libraries like jQuery, is this even a useful method to use more?
  • In what cases should the use of an anchor tag that is not a link (ie does not have the "href" attribute) be #BestPractice , or is this method completely deprecated?
+6
source share
2 answers

This can be used for in-page targeting of elements (for example, for scrolling to a certain point):

 <a name="table-of-contents"></a> <h1>Table of Contents</h1> ... <a href="#table-of-contents">Table of Contents</a> 

Although, this is often redundant (and may also take up empty space), because elements with identifiers can be directly targeted:

 <h1 id="table-of-contents">Table of Contents</h1> ... <a href="#table-of-contents">Table of Contents</a> 
+5
source

The <a> name attribute is technically no longer supported in HTML5, although browsers still support it for backward compatibility.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#Obsolete

I recommend you stick with <a id="something"> from here. If you've seen examples that use name , then they apparently still remain in HTML for 4 days.

+1
source

All Articles