Copy link to clipboard
Copied
What's the latest on how naughty (or not) it is to use empty <a> tags?
I like using <a> for almost everything cosmetically interactive; keeping all my formatting is in the CSS. And the visual is often a background image. As such, my HTML has various instances that look like <a class="name"></a> with nothing else, not even the usual space (or nbsp) we used to have to put to make it work.
Is this bad practice in 2019, or is it relatively safe to use empty <a> tags nowadays?
(I just find the code looks better without it if it doesn't need it.)
I don't know what you mean by safe. What are your concerns exactly? Safe to use security-wise, browser-wise or search engine-wise? All could be impacted.
Named anchors were supported in HTML4 doc types and dropped from the HTML5 specs. So the type of document you use matters.
You can read all about anchor tags on the MDN site. Security issues are covered about half way down the page. The browser compatibility chart is shown towards the end.
<a>: The Anchor element - HTML: Hypertext Markup Language | MDN
...Copy link to clipboard
Copied
I don't know what you mean by safe. What are your concerns exactly? Safe to use security-wise, browser-wise or search engine-wise? All could be impacted.
Named anchors were supported in HTML4 doc types and dropped from the HTML5 specs. So the type of document you use matters.
You can read all about anchor tags on the MDN site. Security issues are covered about half way down the page. The browser compatibility chart is shown towards the end.
<a>: The Anchor element - HTML: Hypertext Markup Language | MDN
SEO MOZ What Are Internal Links
Copy link to clipboard
Copied
In HTML5, the <a> tag is always a hyperlink, but if it has no href attribute, it is only a placeholder for a hyperlink. If you want to use it for other purposes, you must assign an Aria role as per MDN document that Nancy has pointed to.