Wandering Thoughts archives

2008-02-12

A small annoyance with HTML

One of the things I don't like about HTML is its peculiar restrictions on anchors (<a> elements), specifically named anchors. Named anchors are what you use to specify the target of '#fragment' URL fragments, and the restrictions matter because they constrain where you can point such fragment URLs.

There are two annoying restrictions: anchors cannot be nested, and anchors must include something inside them; they cannot be empty. That anchors cannot nest constrains your ability to make a fragment target wrap arbitrary content, for example a sentence, since the sentence might contain links.

(If you want to wrap an anchor around just a link, you can merge the two by putting the 'name=...' on the link <a>. But this doesn't work if the link is only part of the text you want to anchor to.)

That anchors must contain something clashes with the fact that often anchors are logically attached to positions, not things. Attaching them to a thing related to the position works, sort of, but it is an annoying hack. I do not want to anchor to the first word or letter of a paragraph; I want to anchor to the start of the paragraph itself.

(Technically you can make arbitrary elements into named anchors by giving them a suitable id attribute, except that this may have other side effects. And it only works at the start of elements.)

I will freely admit that both of these are more of a problem for systems that automatically generate HTML (like mine) than for people who are authoring it by hand.

web/HTMLAnchorGripe written at 22:50:04; Add Comment


Page tools: See As Normal.
Search:
Login: Password:
Atom Syndication: Recent Pages, Recent Comments.

This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.