Full of lovely web standards information and a large helping of PHP

Do links on your site make sense out of context?

1 year, 2 months ago

If they don't, then they should. It's far to easy to create links labeled "click here" or "read more" but these are next to useless when not supported by the context of their surrounding text. Imagine how you'd decide which of these links to visit if they were displayed listed as a simple list of links. An unrealistic situation you might say, but you'd be wrong - this is exactly the situation faced by blind and partially sighted users every day. Popular screen reader software like JAWS and Window Eyes provide mechanisms for browsing through all links found in a page, the aim being to allow users to more quickly find the information they're after. Similar mechanisms exist for headings and other page elements but these are next to useless if you haven't labeled things correctly. Some argue that one can expand the meaning of a link through it's title attribute but this unfortunately proves to be a bit hit and miss - many screen readers don't read text in title attributes by default.

To add more salt to the wound let's turn to search engine crawlers. These place high importance on the text you assign to links so you're missing a trick if you continue to mislabel links in this way. Ever wanted to know the biggest culprits of the "click here" link? Simply search for this text in Google.

A Script To Highlight The Problem

In my own posts I try reasonably hard to ensure links make sense out of context but sometimes I slip up. I can think of several instances of really poorly labelled links in previous posts and I really need to go back and correct them. In an attempt to highlight these failings going forward and because it seems like a useful additional navigation aid I've developed a simple script which extracts all links from a post and adds them to a new section in the side bar on the fly.

Note: It's not on my site yet as I need to do a little CSS restructuring to accomodate it first.

  1. var oExtractedLinks = {
  2. iHeadingLevel : 3,
  3. sHeadingText : 'Links in Post',
  4. sParentId : 'post',
  5. Init : function() {
  6. // check for DOM support and valid parent id
  7. if (!document.getElementById || !document.getElementById(this.sParentId)) {
  8. return false;
  9. }
  10. this.Process();
  11. },
  12. Process : function() {
  13. // get links contained in parent
  14. aLinks = document.getElementById( this.sParentId ).getElementsByTagName('a');
  15. // get number of links
  16. iNumLinks = aLinks.length;
  17. // does the parent actually contain any links
  18. if (iNumLinks) {
  19. // get script node, we'll insert everything relative of this to remove need for extra markup
  20. var oParent = document.getElementById('extracted-links');
  21. // create heading and list
  22. var oHeading = document.createElement('h' + this.iHeadingLevel);
  23. var oList = document.createElement('ul');
  24. // add specified text to heading
  25. oHeading.appendChild( document.createTextNode(this.sHeadingText) );
  26. // insert into document
  27. oParent.parentNode.insertBefore(oHeading, oParent);
  28. for (var i = 0; i < iNumLinks; i++) {
  29. // add link to list
  30. this.AddLink(oList, aLinks[i]);
  31. }
  32. // insert list into document
  33. oParent.parentNode.insertBefore(oList, oParent);
  34. }
  35. },
  36. AddLink : function(oList, oLink) {
  37. // make sure the first node of the link isn't an image
  38. if (oLink.firstChild.nodeName.toLowerCase() != 'img') {
  39. // create list item and anchor
  40. var oListItem = document.createElement('li');
  41. var oItemLink = document.createElement('a');
  42. // get attributes from source link
  43. oItemLink.setAttribute('href', oLink.getAttribute('href'));
  44. oItemLink.setAttribute('title', oLink.getAttribute('title'));
  45. oItemLink.appendChild( document.createTextNode(oLink.firstChild.nodeValue) );
  46. // append anchor to list item
  47. oListItem.appendChild(oItemLink);
  48. // append list item to list
  49. oList.appendChild(oListItem);
  50. }
  51. }
  52. }
  53. // run the script, we're not using onload or DOM ready so the script won't pick up links appearing after the script reference
  54. oExtractedLinks.Init();

View a live demo of the script

Having downloaded the script, to use in your own site simply add the following line into your page at the point at which you'd like the links to appear. Also make sure you update sParentId with the ID of the element containing the links you'd like to extract.

Screen Readers

If you're new to the way screen readers work I'd highly recommend heading over to the YUI Blog and watching Yahoo!'s Accesibility Project Manager demonstrate how they're used.

A demo version of JAWS is available which can be used for up to 1/2 hour at a time. After this you'll have to reboot your computer before continuing to use it.

Further Reading

Comments

  • An interesting piece. I'm not quite sure I see the value of separately listing an article's link text, but I would love a tool that could do this for an entire site at once, broken out by page. That would be cool. (The Firefox plugin

    Michael Barrish - 26th May 2007

  • My previous comment got cut off. Trying again:

    An interesting piece. I'm not quite sure I see the value of separately listing an article's link text, but I would love a tool that could do this for an entire site at once, broken out by page. That would be cool. (The Firefox plugin Fangs can do this on a per-page basis.)

    Unrelated: As I'm sure you know, descriptive link text helps everyone, not just screen reader users, because it aids scannability. Just another reason to do it right.

    Michael Barrish - 26th May 2007

  • Michael - re descriptive links helping everyone - I totally agree. Most guidance given for improving accessibility also improves overall site usability.

    Ed Eliot - 26th May 2007

  • One of the things I've been looking at with Victor Tsaran is having extra sections to 'more' links which get hidden.

    For example If you have a news piece on The Crown Jewels you might have a visual link "More" which is visually situated in context with the story. However it would read "More on the Crown Jewels". This can easily be done by hiding adding the additional text in a span and hiding screen it off screen using CSS.

    Tom Hughes-Croucher - 27th May 2007

  • This is something I keep meaning to address on my own site but have yet to get round to.

    But to help me quickly see all links minus their surrounding text I put together a quick bookmarklet to extract all links from a page.

    You can get the bookmarklet from my post about it: View links without context

    Aaron Bassett - 27th May 2007

  • Tom - a nice idea. For the benefit of other readers I've put together a quick example of replacing text in this way.

    Aaron - nice bookmarklet, thanks for sharing. I've added a quick link to your article. I've also updated my code to include checking for images in links (I should have done that to begin with ;-))

    Ed Eliot - 27th May 2007

  • It get's even better, these links are better for SEO too ;)

    Joost de Valk - 30th May 2007

  • I wrote a related piece a while ago called Improper Link Text.

    I like your approach and I will continue to check out your blog in the future.

    Jules - 5th June 2007

  • Sorry, didn't notice the BBCode requirement below.

    The link above should have been Improper Link Text

    Jules - 5th June 2007

  • I think naming the link something relevant to what is on the click thru page is the best way to link to content.

    wendy - 6th June 2007

  • Anyone know of a PHP version? It would be very useful to set a bot that can scan an entire site, log all of the link texts along with their respective urls so that a mass revision of a site can take place.

    Abu - 16th July 2007

  • Naming your links in such a fashion "Click Here" or "Read More" is atrocious for click through rate as well. You really need to lead your reader into the next step.

    Did you know those screen readers pick up information in DIV with the display:none class? There was big talk of that a few months back as well.

    Lynne - 28th October 2007

  • I don't know how many times of heard of the Google link bomb "Click Here" ranking Adobe Acrobat for that phrase, but it has to be a million or more.

    Blue underlined links (yes, they should always be blue if you want your reader to click them), need to be descriptive and engaging for all users. That's just a best practice when it comes to web design and copy writing in general.

    Mary - 29th October 2007

  • I've found naming your link to whats relevant on your page not only helps your click through ratios but also helps your seo rankings for that term.

    Bobby - 13th November 2007

  • I got a minute to watch the yahoo video with victor Tsaran and actually realized some key concepts that I have been overlooking with the development of my sites. I really never took the time to watch a screen reader work and now realize I have a little bit to go back on and update.

    It wasn't clear to me but it does appear that title tags in links do help seo. However, in this video he pulls up a link list on his screen reader that has ordered the links by a rank/rating. Do the screen readers rank links better if they have titles? I could have been mistaken but it appeared that the screen reader was ordering them by some measure.

    lynne - 18th March 2008

  • "click here" is obsolete since it just wastes a net surfers time to figure out why they'd have to click. It is true that a link must command and intrigue a person enough to go ahead and click it, but the phrase has been used for so long as tactic to disrupt your search. A specified link which really should be in the context of what is written saves a surfer time and makes them happy enough to go back to the same page and click on the links that strike their curiosity. Regarding SEO, links that are in context and that are working matter along with valuable content. These go hand in hand to keep a person in your page since its interesting and very surfer friendly.

    Susan Shepherd - 9th April 2008

Help make this post better

Notes: Standard BBCode for links, bold, italic and code are supported. rel="nofollow" is added to all links. Your email address will never be displayed on the site.

Back to index