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.


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


CSS Version

CSS Syntax

:hover {
   style properties 

Browser compatibility

:hover Yes 7.0 Yes Yes Yes


An example showing how to use :hover CSS selector.

        <style type="text/css"> 
        :hover { <!-- ww w .j  a va  2 s  .c om-->
            border: thin black solid; 
            padding: 4px; 
        <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> 

Click to view the demo