W3C home > Mailing lists > Public > public-html@w3.org > February 2009

Re: HTML is a declarative mark-up language

From: Boris Zbarsky <bzbarsky@MIT.EDU>
Date: Sat, 31 Jan 2009 22:21:24 -0500
Message-ID: <49851534.50704@mit.edu>
To: Leif Halvard Silli <lhs@malform.no>
CC: HTML WG <public-html@w3.org>

Leif Halvard Silli wrote:
>> I guess I'm at a bit of a loss to think of a situation where something 
>> is solely an anchor destination without having any other semantics.
> 
> In Wikipedia (e.g. see http://en.wikipedia.org/wiki/Anchor ) you find 
> things like this:
> 
> <p><a name="Anchoring_gear" id="Anchoring_gear"></a></p>

To be more precise, what the markup looks like is this:

   <p><a name="Anchoring_gear" id="Anchoring_gear"></a></p>
   <h2>
     <span class="editsection">[<a
     href="/w/index.php?title=Anchor&amp;action=edit&amp;section=13"
     title="Edit section: Anchoring gear">edit</a>]</span>
    <span class="mw-headline">Anchoring gear</span>
   </h2>

I would argue that more correct markup here would be:

   <h2 id="Anchoring_gear">
     <span class="editsection">[<a
     href="/w/index.php?title=Anchor&amp;action=edit&amp;section=13"
     title="Edit section: Anchoring gear">edit</a>]</span>
    <span class="mw-headline">Anchoring gear</span>
   </h2>

and that in fact the Wikipedia article is EXACTLY the kind of poor 
authoring practice that the restrictions on the content model of <a> and 
the belief that the anchor target must be an <a> has spawned.

> When you look at the code, you are in no doubt of the purpose of that 
> element there: it is solely there for the purpose of linking to it.

Indeed, and in this case that's actually wrong from a semantic point of 
view.  What's being linked to is not the empty inline inside the 
otherwise-empty paragraph, but the section heading.  Things happen to 
work with the page's default style because of the spatial proximity of 
the two, but if a stylesheet positioned the section header and following 
section, the link would go to the wrong place.  If the article were 
paginated (e.g. in a projection medium) and the page break came between 
the <p> and the <h2>, the link would go to the wrong place.

I do appreciate you finding such an excellent example in the wild, on a 
quite popular site run by people who generally know their HTML, of the 
exact problem I described.

> May be - I speculate - it is more easy to add an empty anchor element 
> rather than manipulating the id of a container element? After all, in 
> Wikipedia, the id-refs, and hence the links, will change very very often.

That link has to change any time the section title changes.  Right now, 
such a change updates the text in the <h2>, the table of contents text, 
and both attributes of the <a>.  With the use of id directly on the 
header, it would need to update the text in the <h2>, the id of the 
<h2>, and the table of contents text.

In either case, the change is handled entirely by the wiki software 
involved.  The table of contents is auto-generated based on the <hn> 
that are in the document; the <hn> and the <a>s before them are 
automatically generated based on the section headings entered.

> Also, if I want a place to be a destination anchor, without having  to 
> investigate or find out (it may be impossible to know the content of the 
> A element if it is generated via DOM etc) the *further* semantics of the 
> anchored resource, then I can use <a id="ref">resource</a> and be 
> certain that I have at least not lied plus that I solved a practical 
> problem.

I'm not sure I follow this use case.  Would you be able to give a 
concrete example?

> At least copy-paste is not the reason in Wikipedia.

Probably true, yes.

>> spec gives <a> a privileged status as an anchor destination that 
>> obscures the fact that any element can be an anchor destination if 
>> that's what you're really meaning to link to.
> 
> I cannot really agree that HTML 4 gives a privileged status to the A 
> element. Except for the way that name="" allows the full unicode 
> "alphabet" to be used as name content.

Sure it does.  It explicitly calls out the <a> element as a way to 
target links.  It does so before it mentions that you can also use IDs 
for the same purpose.

The result is that far too many people end up with the impression that 
the <a> element is the only way to create a link target.

> That is a element that is singled out for one purpose has nothing to do 
> with "privileged status".

Sure it does.  It implies that any time that purpose needs to be 
addressed you should be using that element.

> However, if I have gotten it right, in HTML 5 it will be non-conforming 
> to e.g. write
> 
> <body><inline-elemetn></inline-element></body>
> 
> (or has that idea been left?)

I have no idea, honestly.  What does that question have to do with the 
discussion at hand?

> How would you take away the special status, I wonder ... After all, it 
> only has two purposes - anchored link or link anchor.

You could say that an <a> with an href is a link, while an <a> with no 
href is semantically equivalent to a <span>, for example.

-Boris
Received on Sunday, 1 February 2009 03:22:10 UTC

This archive was generated by hypermail 2.3.1 : Monday, 29 September 2014 09:39:01 UTC