Prevent dotted border from appearing when clicking links in Firefox
Posted September 12th, 2009 in HTML and CSS
The other day I wrote about how to do an animated information box with jQuery and in doing so was reminded of an annoying habit Firefox has of putting a dotted outline around links when they're clicked. This post shows the simple solution to this problem.
Screenshot of the problem
The following screenshot shows what I'm talking about after clicking the Example 3 link in Firefox. For the purposes of the example I switched off the border on the links so it's easier to see the dotted outline. Because clicking the link does not navigate away from the page, the link remains dotted and is, in my opinion, a bit ugly.

The solution
To prevent this behavior for all <a> tags, add the following to your style sheet:
a:focus {
outline: 0;
}
You can alternatively just apply it to a particular div etc like so, where #example is the element that contains <a> tags that should not have the outline.
#example a:focus {
outline: 0;
}
Related posts:
- HTML5: Wrap Block-Level Elements with anchor tags (Tuesday, July 27th 2010)
- Allowing div layers to float over Flash/Vimeo/YouTube etc (Saturday, August 22nd 2009)
- Always show a vertical scrollbar in Firefox, Chrome, Safari and Opera (Saturday, June 20th 2009)
- Absolutely position an element within another element with CSS (Saturday, May 30th 2009)
- Valid characters for the HTML ID attribute (Saturday, April 4th 2009)
- Add an offsite link icon after external links with CSS (Friday, March 27th 2009)

Comments
blog comments powered by Disqus