Removing the Dotted Outline from Focused Links

June 16th, 2006

Have you ever noticed the dotted outline that appears around links as you click on them? That is an accessibility feature for people who can't use the mouse for whatever reason. It is supposed to show where the current focus is when you use the TAB key to move through a document, and does a fantastic job.

the Dotted Focus Outline

But why does it appear when you are using the mouse to click on a link?

This naturally subtle visual cue has become a convention across all browsers, gently reassuring the user when they have successfully clicked on a link. Without it, users will try again to click a link thinking they missed it—and if the server isn't immediately responsive they assume the browser is frozen and contemplate closing it.

But for a designer this happens to be particularly annoying on image links, when the dotted focus remains even after you have clicked the link and moved your mouse away from it.

While I am an advocate of using JavaScript to remove the dotted focus from links onMouseDown or onMouseOut, but I would not recommend removing the dotted focus entirely. You still need it to be there when people are using the keyboard.

Remember: This is an accessibility feature, and people who can't use the mouse for whatever reason depend on it. You know, people who eat and surf the web, like me.

Enough banter, show me the code:

<script type="text/javascript">//<!-- var runOnLoad = new Array(); // for queuing multiple onLoad event functions window.onload = function() { for(var i=0; i<runOnLoad.length; i++) runOnLoad[i]() } // hide dotted :focus outlines when mouse is used // but NOT when tab key is used if(document.getElementsByTagName) for(var i in a = document.getElementsByTagName('A')) {   a[i].onmousedown = function() {     this.blur(); // most browsers     this.hideFocus = true; // ie     this.style.outline = 'none'; // mozilla   }   a[i].onmouseout = a[i].onmouseup = function() {     this.blur(); // most browsers     this.hideFocus = false; // ie     this.style.outline = null; // mozilla   } } //--></script>

Alternatively, you could remove the dotted outline entirely in favor of a different visual cue. Maybe even one that matches your design. I've experimented with color, backgroundColor, and font-size and they were all pretty cool.

Posted in:

17 Responses to “Removing the Dotted Outline from Focused Links”

  1. Fathed (not verified) Says:

    Nice tip.

  2. Crispy Lettuce (not verified) Says:

    Sweet.

  3. Dragan (not verified) Says:

    I was just writting about this other day... and with jQuery! $("div.navigation a").each(function(){this.onmouseup = this.blur();});

  4. doug (not verified) Says:

    nice

  5. Heythere (not verified) Says:

    That's awesome. I love little features such as this. Thank you

  6. Ehsan (not verified) Says:

    i wonder if this can be changed from my browser if yes it will be great coz its annoying ever since i converted to Firefox i have seen it

  7. David (not verified) Says:

    This seems to do a good job: http://sonspring.com/journal/removing-dotted-links

  8. Praveen (not verified) Says:

    Great!!! Nice effort to make it out with out compromising accessibility.

  9. nirmit (not verified) Says:

    cool tip man.. make this blog more informative.. :)

  10. john (not verified) Says:

    cool !

  11. Jimin Park (not verified) Says:

    thanks!

  12. Jordan (not verified) Says:

    Nice code dude, may uses it sometime. LD

  13. Lucia (not verified) Says:

    I also can not mmake it work, any idea what can go wrong? i copied and pasted the code above inside my html head but gives no result...

  14. dave (not verified) Says:

    Great post! Will be sure to share with everyone at my Florida web design....thanks

  15. Ronald (not verified) Says:

    check this out:

    a {
    noFocusLine:expression(this.onFocus=this.blur())
    outline:none;
    }

  16. ben (not verified) Says:

    Without JavaScript the best way to disable the dotted outline is tu enter following tags in CSS:

    *:focus { outline: none; }

    *::-moz-focus-inner { border: none; }

    and then change every

    *:hover { ... }

    into

    *:hover, *:focus { ... }

    and you will be able to browse through links by tab key.

  17. Sameer (not verified) Says:

    Great job!

    you can simply remove the outline form your button ,
    you can use onfocus="this.blur();"

  18. Post new comment

    Please type the letters you see in the picture below.

    Image CAPTCHA