CSS | :hover Selector
This selector is used to style elements when mouse hover over them. It can be used on every element.
Syntax:
element :hover{
CSS declarations;
}
Example-1: changing the background-color on hover over a element.
<!DOCTYPE html> <html> <head> <style> h1:hover { color: white; background-color: green; } </style> </head> <body> <h1 align="center"> hover it</h1> </body> </html> |
Output:
Initial:

On Hover:

Example-2: Showing a hidden block on hover over text.
<!DOCTYPE html> <html> <head> <style> ul { display: none; } div { background: green; width: 200px; height: 200px; padding: 20px; padding-left: 50px; font-size: 30px; color: white; display: none; } h3:hover + div { display: block; } </style> </head> <body> <h3 align="center"> Hover to see hidden GeeksforGeeks. </h3> <div> GeeksforGeeks </div> </body> </html> |
Output:
Initial:

On Hover:

Example-3: changing the font-color on hover over a element.
<!DOCTYPE html> <html> <head> <style> h1:hover { color: red; } </style> </head> <body> <h1 align="center"> hover it</h1> </body> </html> |
Output:
Initial:

On Hover:

Example 4: Changing the font-family of text on hover over it.
<!DOCTYPE html> <html> <head> <style> h1:hover { font-family: monospace; } </style> </head> <body> <h1 align="center"> hover it</h1> </body> </html> |
Output:
Initial:

On Hover:

Example-5: Changing the text-decoration to underline on hover over a element.
<!DOCTYPE html> <html> <head> <style> h1:hover { text-decoration: underline; } </style> </head> <body> <h1 align="center"> hover it</h1> </body> </html> |
Output:
Initial:

On Hover:

Browser Support
- Google Chrome 4.0
- Internet Explorer 7.0
- Mozila firefox 2.0
- Safari 3.1
- Opera 9.6
Recommended Posts:
- How to write a:hover in inline CSS?
- How to write :hover condition for a:before and a:after in CSS?
- CSS | ::before selector
- CSS | #id Selector
- CSS | * Selector
- CSS | ::after Selector
- CSS | :not Selector
- CSS | :nth-child() Selector
- CSS | Class Selector
- jQuery | :first Selector
- CSS | :indeterminate Selector
- jQuery | :even Selector
- CSS | ::first-line Selector
- CSS | ::first-letter Selector
- CSS | :link Selector
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



