[whatwg] Proposal for a link attribute to replace <a href>

With the capabilities of modern browsers it seems to me that a specific 
tag for hyperlinks is no longer required or useful and could be 
depreciated with a more versatile global "link" attribute. I believe 
that hyperlinks now have more in common with attributes such as ONCLICK 
than they do with tags since in web applications links often define 
actions rather than simply being a part of the document structure. The 
<A> tag would continue its role as an anchor but the HREF attribute 
would be phased out making <A> a more consistent element (since links 
and anchors are really quite separate concepts). Below is an example of 
the proposed link attribute in action:

<li><a href="foo.html">Foo</a></li>

could be written as:

<li link="foo.html">Foo</li>

No useful semantic information is lost however the markup is cleaner and 
the DOM drops an unnecessary node (which could speed up certain 
applications).

---LINK with block-level or interactive content---
This proposal would circumvent <A>'s main limitation which is its 
requirement to not wrap block-level elements or 'interactive' content. 
The HTML5 draft requires it wrap 'phrasing content' (essentially 
paragraphs) and not wrap 'interactive' content (such as other 
hyperlinks) however I see no reason why a link attribute should require 
these limits. Links would simply cascade as in the following example:

<table link="alphabet.html" title="Alphabetical List">
    <tr>
       <td>A</td>
       <td>B</td>
       <td link="c.html" title="More about C">C</td>
       <td>D</td>
    </tr>
</table>

In the example above clicking anywhere on the table except 'C' brings up 
a generic page, whereas 'C' has dedicated content. The following nested 
links would also be valid:

<span link="foo.html">click anywhere on this line except <b 
link="bar.html" title="Go to bar instead">here</b> to visit foo.</span>

---LINK and TITLE attribute---
The link attribute could coexist with the the TITLE attribute for 
describing links on non-textual objects. This is consistent with TITLE 
on <A>:

<img alt="Picture of rhesus monkey" src="monkey.png" link="monkies.html" 
title="See more monkies">

---LINK and ONCLICK---
This attribute can easily coexist with ONCLICK. The behaviour would be 
identical to ONCLICK on <A>
With scripts enabled: The onclick handler runs first and the link is 
followed if onclick returns true.
With scripts disabled: The link is followed. This also makes the link 
attribute a useful fallback when scripts are disabled. Example:

<span link="foo.html" onclick="return ask('Go to foo?');">Foo</span>

---LINK and Scripting---
The link attribute would make adding hyperlinks to DOM nodes easy:

node.link = 'http://foo.bar.baz'; /* Create a hyperlink on an element */
nodes_with_a_link = document.getElementsByAttribute('link'); /* Get all 
links. This method doesn't exist in the draft but can be written in 
javascript using iterators */

---LINK and Forms---
To avoid confusion the use of link on a form widget would either have no 
effect or be invalid.

---LINK and DOCTYPE---
The link attribute currently has meaning in pre-HTML4 documents as an 
attribute of the body tag (to define link color). Since this use has 
been long depreciated it should be alright for HTML5 to redefine it. To 
prevent issues with legacy pages browsers should only respect the link 
attribute when the DOCTYPE supports it or if no doctype is present 
browsers should allow link on all elements except <body>.

---LINK and CSS---
Elements with hyperlinks would be styled using CSS attribute selectors 
(by the time HTML5 is ready all HTML5-capable browsers should handle 
these). The syntax would be standard CSS2:

*[link] {color:blue;} /*All links are blue*/
*[link]:visited {color:purple;} /* visited links are purple */
table[link] {background-color: #FFDDDD;} /* hyperlinked tables have a 
pale red background */

I believe a link attribute would be a significant improvement to HTML. 
The only reasons I can think of not to add this would be the added 
complexity for browsers and authors during the transition period. The 
advantages include less markup, simpler DOM structure, nested 
hyperlinks, onclick fallbacks and better consistency in the spec. Being 
such a common element web authors will probably keep using <a href> for 
many years to come regardless of the standard but that should not be a 
problem since <a href> and link should coexist quite easily in valid 
HTML. Once awareness has spread then future drafts could depreciate the 
href attribute on anchors.


Shannon

Received on Wednesday, 27 February 2008 04:25:19 UTC