CSS :hover selector
Complete CSS Selector Reference Manual
Example
Select the style when the mouse moves over a link:
a
:hover
{
background-color:
yellow
;
}
Try it »
Definition and Usage
:hover adds a special style when the mouse moves over a link.
Tip: The :hover selector can be used on all elements, not just links.
Tip: :link The selector sets the style of unvisited page links, :visited The selector sets the style of visited page links :activeThe selector sets the style when you click a link.
Note: For the effect to appear as expected, in the CSS definition :hover must come after :link and :visited!!
Browser support
The numbers in the table indicate the first browser version that supports this property.
| Selector | |||||
|---|---|---|---|---|---|
| :hover | 4.0 | 7.0 | 2.0 | 3.1 | 9.6 |
**Note:** In IE a DOCTYPE must be declared to ensure the :hover selector works effectively.
Related pages
CSS Tutorial: CSS Links
CSS Tutorial: CSS pseudo-classes
Try it Yourself - Examples
Example
Active, visited, unvisited, or links with the mouse hovering over them:
a:link {color:green;}
a:visited {color:green;}
a:hover {color:red;}
a:active {color:yellow;}
Try it »
Example
Links with different styles:
a.ex1:hover,a.ex1:active {color:red;}
a.ex2:hover,a.ex2:active {font-size:150%;}
Try it »