A Revised Method of Defining Link Pseudo-classes

This article first appeared on evolt.org on 2002-08-21.  (Evolt.org is a world community for web developers.)

Defining link pseudo-classes in CSS

In the classic case of defining your link pseudo-class styles, this has been the traditional way to do it:

 a:link { /*styles*/ }
 a:visited { /*styles*/ }
 a:hover { /*styles*/ }
 a:active { /*styles*/ }

As the CSS2 specification observes, the order of the pseudo-classes is important so that the cascading rules present the correct styles to the browser.

Recently, I began using another method derived from some notes by David Baron. The rules are as follows:

 :link:focus, :visited:focus { /*styles*/ }
 :link { /*styles*/ }
 :visited { /*styles*/ }
 :link:hover, :visited:hover { /*styles*/ }
 :link:active, :visited:active { /*styles*/ }

I like this style for several reasons:

Does the browser display styles correctly using the new pseudo-class rule method?
Browser (platform) :link :visited :focus :hover :active
IE4+ (PC) Yes Yes No; treated like :active Yes Yes
IE 5.x (Mac) Yes Yes Yes Yes Yes
IE 4.x (Mac) Yes Yes No; treated like :active Yes Yes
IE 3.x (PC and Mac) 1 No No No No No
Mozilla 1.x (PC) Yes Yes Yes Yes Yes
Netscape 6+ (PC) Yes Yes Yes Yes Yes
Netscape 4.x (PC and Mac) Yes Yes No No No
Opera 7.x (PC) Yes Yes No Yes Yes
Opera 4-6 (PC/Mac) Yes Yes No No No
Opera 3.62 (PC) 2 No No No No No
iCab (Mac) Yes Yes No No No
MSN TV (formerly WebTV) 3 Yes Yes No No No

Table notes:

  1. The links work, but the body of the text will take the styles of the :focus definition.
  2. This version only tries to support :link and :visited in any event, but suffers from bugs where a link's text-decoration or border changes color but the link text does not.
  3. These results are based on testing with their emulator software, version 2.8 (and below). In the MSN TV CSS documentation, it claims that :link, :visited, :active, and :hover are supported. I have never seen the emulator support anything but :link and :visited. The Style Checker function of the TopStyle CSS editor agrees that only :link and :visited are supported.

Wrapup

As the table shows, only Opera 5/6 actually lose functionality that they otherwise have using the traditional link pseudo-class style. In the new system, they no longer understand :active and :hover. In other browsers, any functionality that doesn't work is something that didn't work under the traditional system anyway. Given that I can live with the Opera problem, I personally have begun using this system on various sites.

Anyone with corrections or additions, please feel free to comment. Just offhand, I would be interested in hearing first-hand how this system works in Konqueror/Safari and an actual MSN TV setup. David Baron maintains a test page that you can use.

Thank you to David Baron for permission to use his original work as the basis for this article.

[back to top]