Using a:focus in CSS – quick tip
Posted December 22nd, 2008 by David HamillIn web design, we often automatically think of blind users when we talk about web accessibility. But a lot of disabled users are not blind. Some people will use a keyboard to navigate your site despite being able to see the screen. Unfortunately browsers aren’t that great at highlighting the link that is in focus.
Helping keyboard only users
You can help your keyboard only users by applying a clear visual property for a:focus within your stylesheet. When your users tab through the links on your website, they will then be able to see which ones are in focus.
Tab through the links on this page with your keyboard to see what I mean. Here’s the CSS I use:
a:focus{ color:#fff; background: #C40064; }
Form fields
You can also use this effect on your form fields. Just don’t expect it to work in Internet Explorer. The Focus pseudo class only works on the <a> tag in Internet Explorer.
What are quick tips?
My quick tips are bits of advice I’ve given lots of times, but they’re not really worth writing a big article about.
Tags: navigation, quick tips



4 Responses to “Using a:focus in CSS – quick tip”
December 31st, 2008 at 11:16 pm
The “quick tips” link at the end of the article points to a 404. I was excited to read the other quick tips.
January 1st, 2009 at 8:53 pm
Doh! Thanks Dan sorted that now. Lazy copying and pasting on my part.
February 1st, 2009 at 4:35 am
Great tip, unfortunately I am guilty of not using the focus property consistently.
Great site, and I appreciate the resource!
February 6th, 2009 at 11:15 am
David, providing visible keyboard focus is now a AA success criteria in WCAG 2.0.
Comment on this article