• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Safe to use empty <a> tags in 2019?

Engaged ,
May 13, 2019 May 13, 2019

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

Views

434

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 13, 2019 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

...

Votes

Translate

Translate
Community Expert ,
May 13, 2019 May 13, 2019

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

Nancy O'Shea— Product User, Community Expert & Moderator
Alt-Web Design & Publishing ~ Web : Print : Graphics : Media

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 13, 2019 May 13, 2019

Copy link to clipboard

Copied

LATEST

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, the only real Dreamweaver alternative.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines