Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
Change the Color of Link when a Mouse Hovers
To change the color of a link when a mouse pointer hovers over it, use the CSS :hover pseudo-class. This creates an interactive effect that provides visual feedback to users.
Syntax
a:hover {
color: desired-color;
}
Basic Example
Here's how to change a link's color on hover:
<html>
<head>
<style>
a {
color: blue;
text-decoration: none;
}
a:hover {
color: #FFCC00;
}
</style>
</head>
<body>
<a href="#">Hover over this link</a>
</body>
</html>
Multiple Link States
You can style different link states for a complete user experience:
<html>
<head>
<style>
a:link {
color: #0066CC;
}
a:visited {
color: #800080;
}
a:hover {
color: #FF6600;
text-decoration: underline;
}
a:active {
color: #FF0000;
}
</style>
</head>
<body>
<a href="#">Link with all states</a>
</body>
</html>
Advanced Hover Effects
You can combine color changes with other CSS properties:
<html>
<head>
<style>
.fancy-link {
color: #333;
text-decoration: none;
padding: 5px 10px;
border-radius: 3px;
transition: all 0.3s ease;
}
.fancy-link:hover {
color: white;
background-color: #007bff;
text-decoration: none;
}
</style>
</head>
<body>
<a href="#" class="fancy-link">Fancy hover effect</a>
</body>
</html>
Key Points
- Use
a:hoverto target links on mouse hover - The
:hoverpseudo-class works with any HTML element - Combine with
transitionproperty for smooth color changes - Order matters:
:link,:visited,:hover,:active
Conclusion
The :hover pseudo-class is essential for creating interactive links. It improves user experience by providing immediate visual feedback when users interact with your links.
Advertisements
