0

It is possible to define an anchor without text? I. e. without inline text.

<p>some text <a name="anchor47"></a> and further text</p>

I don't find any information in the standard. Usually I would write my HTML as

<p>some <a name="anchor47">text</a> and further text</p>

I just wanted to be sure that my code is accepted by all browsers and check programs...

One check program I used successfully (that means it does not complain if "empty" anchors are there) is that of w3

Peter
  • 97
  • 13
  • 1
    You're asking a bit of an [xy question](http://xyproblem.info), I think. If all you want is an in-page anchor, just put an ID on the paragraph or a span element. It doesn't have to be an anchor element. – isherwood Jan 14 '22 at 16:58
  • See https://stackoverflow.com/questions/32631180/link-contain-no-text-showing-error-in-wave-accessibility-evaluation-tool. Such links are accessibility issues. – isherwood Jan 14 '22 at 17:04
  • At least wave accessibility evaluation tool will complain - that is a good point to disallow the use of an anchar definition without text. And I'm going to improve my content checker to detect those anchors. – Peter Jan 16 '22 at 18:10

1 Answers1

0

It's valid, but you could also add a blank space like:

<p>some text <a name="anchor47">&nbsp;</a> and further text</p>

or you can add text and set the font-size to 0

<p>some text <a name="anchor47" style="font-size:0">anchors away!</a> and further text</p>

I believe there is a benefit to adding some descriptive text in there and hiding it for screen readers. See here for info on accessibility + anchor links.

However, I believe you should be using an alternative method like adding an ID to a span, h3 tag, etc.

<h3 id="anchor">Do you know how to tie an anchor knot?</h3>

And your link:

<a href="#anchor">Tie an Anchor Knot</a>
James
  • 26
  • 4
  • The only thing which I want to avoid is the risk to get in the future the work to change potentially 60.000+ anchors in my documentation. – Peter Jan 16 '22 at 18:12
  • 1
    Thanks to all sharing their knowledge! It helped a lot. – Peter Jan 16 '22 at 18:13