Skip to: content, navigation

by Tommy Olsson and Paul O’Brien

:hover (CSS selector)

Browser support full matrix
IE7+ FF1+ Saf1.3+ Op9.2+
Full Full Full Full
Spec
Version
CSS2

Example

This rule will apply a border to any img element over which the cursor is hovered:

img:hover {
  border: 5px solid #F2F2F2;
}

Try it yourself!View all demos

Description

The :hover pseudo-class matches any element that’s being designated by a pointing device. The term designated refers to the process during which the cursor is hovered over the box generated by the element.

Compatibility

IE5.5Buggy
6.0Buggy
7.0Full
Firefox1.0Full
1.5Full
2.0Full
Safari1.3Full
2.0Full
3.0Full
Opera9.2Full
9.5Full

In Internet Explorer versions up to and including 6:

  • :hover is applied only to HTML a elements that have an href attribute.
  • :hover is counted as two classes/pseudo-classes in the specificity calculation.
  • :hover is ignored if it’s not in the last simple selector.

Neither Internet Explorer 5.5 nor 6 supports the chaining of pseudo-classes; only the last pseudo-class is honored in these browsers.

In Internet Explorer 7:

  • The element sometimes remains in the hover state if the cursor is moved from the element while the mouse button is pressed; the hover state sometimes doesn’t apply when it should.
  • :hover doesn’t match elements with negative z-index property values.

User-contributed notes

ID:
#2
Date:
Thu, 07 Feb 2008 06:32:23 GMT
Contributed by:
dbolton
Status:
This note has not yet been confirmed for accuracy and relevance.

col:hover and colgroup:hover not supported

Add a note

To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.

Related Products

The Principles of Beautiful Web Design

Best Seller!

You don’t need to go to Art School to design great looking web sites!

Book Cover: The Principles of Beautiful Web Design

Download the FREE sample chapters