HTML A Attributes: What People Use

(A semi-scientific study)

Bob DuCharme, October 23, 2002

What I Did

While thinking about linking, I was curious about real-world use of attributes of the A element in web pages. After considering various ways to gather sample data to churn through, I found the Google programming contest, which links to a tar.gz file with 162 megs of sample web pages. After John Cowan told me about Yahoo's random link (http://random.yahoo.com/bin/ryl) and curl I also wrote a script to have curl pull down about 7000 random pages from Yahoo for a total of about 62 megs. I then wrote some scripts to analyze the use of A attributes in the Google and Yahoo sample data and the results are below. (I also saved much smaller data files, strictly concerned with the use of A attributes, in case anyone else would like to analyze them.)

How I Did It

After writing a script to remove the Ctrl-Z characters scattered in the data files, I wrote another that looks through them for all the A element attributes allowable by the xhtml1-transitional DTD. The script wrote out a file showing the attribute use (107K zipped Google data file here, and 29K Yahoo zipped data file here). The script maps all names to lower-case for consistency and puts all the attributes for a given A element on a single line. For example,

 href 
 href 
 name href 

represents three A elements, two of which only have href attributes and one of which has a name and href attribute. Each line begins and ends with a single space so that you can, for example, count all the lines with " href " (a count I've already done, as you'll see below). Hopefully the format of these files will make it easy for others to play with it.

Of course, a properly scientific study would use larger input samples and maybe take into account the fact that pages on Yahoo are more likely to be more professionally designed portal pages than completely randomly selected web pages. I still thought it was interesting to see how the numbers came out, especially after all the assertions lately on various mailing lists about which attributes of which elements People Use or People Don't Use in their web pages.

The Results

total number of A elements:

Google: 301,371
Yahoo: 136,482

Google A Attribute Count

This table and the Yahoo table that follow show the number of elements using each attribute, whether alone or in combination with other attributes. For example, 78% of Google sample A elements only have an href attribute, while 14% have href and at least one other attribute for a total of 92% that have an href attribute. Some numbers on exclusive use follow the Yahoo table.

href278,539(92%)
name26,929(9%)
onmouseover16,720(6%)
onmouseout15,815(5%)
target14,321(5%)
class7,105(2%)
onclick2,439(0.8%)
style1,945(0.6%)
title1,259(0.4%)
onfocus166(0.1%)
id118(<.1%)
accesskey115
onmousedown67
tabindex66
onblur15
onmouseup11
(no others used)

Yahoo A Attribute Count

href131849(97%)
class14848(12%)
target12310(9%)
onmouseover8500(6%)
onmouseout8067(6%)
name4850(4%)
onclick3181(2%)
style1675(1%)
title1655(1%)
id577(0.4%)
onfocus198(0.2%)
tabindex63(0.1%)
onmousedown29(< .1%)
onkeypress16
accesskey15
onmouseup11
shape1
onblur1
coords1
(no others used)

More Fun Facts to Know and Tell

rel and rev never appeared in any A elements.

Out of 79,626 img elements in the Yahoo data, 8 (.01%) had the longdesc attribute, and 4 of those were URIs. Of the 124,484 img elements in in the Google data, 6 (.005%) had longdesc attributes. 5 of those were URIs, but 4, which I assume were from the same document, were relative URIs.

href and name in same element

Google: 4,172 (1.4%)
Yahoo: 354 (0.3%)

href by itself

Google: 235,947 (78%)
Yahoo: 94,458 (69%)

name by itself

Google: 22,722 (10%)
Yahoo: 4,490 (14%)

Only one attribute

Google: 258,696 (86%)
Yahoo: 99,064 (73%)