CSS Selector :hover








The :hover selector matches any mouse-hover-over elements.

:hover is a Pseudo-class and it applies to an element that is in a hovered state.

:hover applies to an element during the period in which it is being hovered.

The most common example is moving the mouse pointer inside the boundaries of a hyperlink.

Examples:

a[href]:hover {text-decoration:  underline;}
p:hover {background: yellow;}

Summary

CSS Version
1

CSS Syntax

:hover {
   style properties 
}




Browser compatibility

:hover Yes 7.0 Yes Yes Yes

Example

An example showing how to use :hover CSS selector.

<!DOCTYPE HTML> 
<html> 
    <head> 
        <title>Example</title> 
        <style type="text/css"> 
        :hover { <!-- ww w .j  a va  2 s  .c om-->
            border: thin black solid; 
            padding: 4px; 
        } 
        </style> 
    </head> 
    <body> 
        <a href="http://java2s.com">Visit the java2s.com</a> 
        <p>I like <span>HTML</span> and CSS.</p> 
        <a href="http://w3c.org">Visit the W3C website</a> 
    </body> 
</html>

Click to view the demo