English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSS Reference Manual

CSS @rule (RULES)

Comprehensive List of CSS Properties

CSS :hover Selector

:hover CSS pseudo-class is applicable to the situation where the user uses a pointer device to virtually point to an element (without activating it). This style will be overwritten by any pseudo-class related to the link, such as :link, :visited, and :active, etc. To ensure its effectiveness, the :hover rules need to be declared after the :link and :visited rules, but before the :active rule, following the LVHA order: :link - :visited - :hover - :active. The :hover pseudo-class can be used on any pseudo-element.

Complete CSS Selector Reference Manual

Online Example

Selector sets the style when the mouse is over the link:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>Basic Tutorial(oldtoolbag.com)</title> 
<style> 
a:active
{
background-color:lightgreen;
}
</style>
</head>
<body>
<a href="//www.oldtoolbag.com">oldtoolbag.com</a>
<a href="//www.pcjson.com" target="_top">pcjson.com</a>
<p><b>Notice:</b> When the mouse moves over the connection  :hover selector style links to the hyperlink.</p>
</body>
</html>
Test and see ‹/›

Definition and Usage

Special styles added when the mouse is over the link.

Hint: :hover selector can be used for all elements, not just links.

Hint: :link Selector sets the style of the unvisited page link :visited Selector sets the style of the link on the visited page:activeSelector sets the style when you click on a link.

Note: To produce the expected effect, in CSS definitions, :hover must be placed after :link and :visited!!

Browser Compatibility

The numbers in the table indicate the first browser version that supports the attribute.

Selector




:hover4.07.02.03.19.6

Note:Must be declared in IE <!DOCTYPE> to ensure that the :hover selector works effectively.

Related Pages

CSS Tutorial: CSS Links

CSS Tutorial: CSS Pseudo-classes

Online Example

Active, visited, unvisited links or when the mouse is hovering over them:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>Basic Tutorial(oldtoolbag.com)</title> 
<style>
a:link {color:green;}
a:visited {color:green;}
a:hover {color:red;}
a:active {color:yellow;}
</style>
</head>
<body>
<p>Move the mouse over and click this link: <a href="//www.oldtoolbag.com/">oldtoolbag.com</a></p>
</body>
</html>
Test and see ‹/›

Online Example

Link styles with different styles:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>Basic Tutorial(oldtoolbag.com)</title> 
<style>
a.ex1:hover,a.ex1:active {color:red;}
a.ex2:hover,a.ex2:active {font-size:150%;}
a.ex3:hover,a.ex3:active {background:red;}
a.ex4:hover,a.ex4:active {font-family:monospace;}
a.ex5:visited,a.ex5:link {text-decoration:none;}
a.ex5:hover,a.ex5:active {text-decoration:underline;}
</style>
</head>
<body>
<p>Move the mouse over the link to see the style change./p>
<p><a class="ex1" href="/css/">This link changes the color</a></p>
<p><a class="ex2" href="/css/">This link changes the font size</a></p>
<p><a class="ex3" href="/css/">This link changes the background color</a></p>
<p><a class="ex4" href="/css/">This link changes the font type</a></p>
<p><a class="ex5" href="/css/">This link changes the text decoration</a></p>
</body>
</html>
Test and see ‹/›

Complete CSS Selector Reference Manual