Style links on mouse over with CSS

To style links on mouse over with CSS, use the :hover pseudo-selector. This selector allows you to apply styles when a user hovers their mouse cursor over an element.

Syntax

a:hover {
    property: value;
}

Example: Basic Link Hover Effect

The following example changes the background color of a link when you hover over it −

<!DOCTYPE html>
<html>
<head>
<style>
    a {
        text-decoration: none;
        padding: 10px 15px;
        background-color: #2196F3;
        color: white;
        border-radius: 4px;
    }
    
    a:hover {
        background-color: orange;
        color: black;
    }
</style>
</head>
<body>
    <a href="https://www.google.com">Visit Google</a>
    <p>Hover over the link above to see the color change effect.</p>
</body>
</html>
A blue button-style link appears. When you hover over it, the background changes to orange and text becomes black.

Example: Multiple Hover Effects

You can combine multiple CSS properties for more sophisticated hover effects −

<!DOCTYPE html>
<html>
<head>
<style>
    .nav-link {
        display: inline-block;
        padding: 12px 20px;
        margin: 10px;
        background-color: #f8f9fa;
        color: #333;
        text-decoration: none;
        border: 2px solid transparent;
        transition: all 0.3s ease;
    }
    
    .nav-link:hover {
        background-color: #007bff;
        color: white;
        border-color: #0056b3;
        transform: translateY(-2px);
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    }
</style>
</head>
<body>
    <a href="/home" class="nav-link">Home</a>
    <a href="/about" class="nav-link">About</a>
    <a href="/contact" class="nav-link">Contact</a>
</body>
</html>
Three navigation-style links appear. On hover, each link smoothly transitions to blue background, white text, moves up slightly, and gains a shadow effect.

Conclusion

The :hover pseudo-selector is essential for creating interactive link effects. Combine it with CSS transitions for smooth, professional-looking hover animations that enhance user experience.

Updated on: 2026-03-15T12:19:37+05:30

310 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements