Skip to main content
Inspiring
May 13, 2019
Answered

Safe to use empty <a> tags in 2019?

  • May 13, 2019
  • 2 replies
  • 606 views

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.)

This topic has been closed for replies.
Correct answer Nancy OShea

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

2 replies

BenPleysier
Community Expert
Community Expert
May 13, 2019

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.

Wappler is the DMXzone-made Dreamweaver replacement and includes the best of their powerful extensions, as well as much more!
Nancy OShea
Community Expert
Nancy OSheaCommunity ExpertCorrect answer
Community Expert
May 13, 2019

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

Nancy O'Shea— Product User & Community Expert