Re: Possible too easy treatment of <a> tag

Wojtek Tylkowski [TAB Studio] (wojtek@tab-studio.com) wrote:

In my view <a> without href shoud be a <span>


Someone might wish to use <a> instead of <span> for brevity. Many people
would say that it’s not appropriate, but that’s not a validity issue. None
of the attributes of <a> is required, or ever was in any HTML version


> apart from html historians disputes, what is a use case?


That’s a different question. An HTML construct can be perfectly valid and
totally useless at the same time.

But in fact, there is a use case in the spec:
“ If the a
<https://html.spec.whatwg.org/multipage/text-level-semantics.html#the-a-element>
element
has no href
<https://html.spec.whatwg.org/multipage/links.html#attr-hyperlink-href>
attribute,
then the element represents
<https://html.spec.whatwg.org/multipage/dom.html#represents> a placeholder
for where a link might otherwise have been placed, if it had been relevant,
consisting of just the element's contents.”
https://html.spec.whatwg.org/multipage/text-level-semantics.html#the-a-element
This sounds complicated, but the example that follows there has a list of
links, with one list item as
<li> <a>Examples</a> </li>
indicating a menu item that would be a link to the current page, This makes
sense, since it keeps the list the same as on other pages of the site, just
with a link to the page itself avoided. It could be written without <a>
markup, but styling might be easier if the item is an <a> element like
others.


> Pity w3
> org validator does not warn about such obvious mistakes.
>

In the case of a student writing an <a> element with a URL inside it as
text content, it is probably a mistake: the student assumed this would make
the URL a link. Well, it could be that way, if HTML had been designed
differently. Anyway, a clever student might actually know that it’s a not
link, but he can write a short piece of JavaScript that processes all <a>
elements without an href attribute and adds such an attribute, with its
value taken from the element content. You might object that this would
prevent search engines from following such links, and (s)he might respond:
Exactly, that’s what I want!

Jukka, https://jkorpela.fi

Received on Wednesday, 28 December 2022 11:32:37 UTC