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:hover to target links on mouse hover
  • The :hover pseudo-class works with any HTML element
  • Combine with transition property 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.

Updated on: 2026-03-15T23:18:59+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements