Open In App

How to Change the Border Color on Hover in CSS ?

Last Updated : 16 Oct, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Border color in CSS defines the color of an element’s border. You can change the border color on hover using the :hover pseudo-class, allowing you to modify the border’s appearance when a user hovers over the element.

Using CSS hover Pseudo Class

The hover pseudo-class in CSS is a powerful tool that allows you to change the style of an element when a user hovers over it with their mouse. This can enhance interactivity and improve user experience by providing visual feedback.

Example: In this example, we use a CSS pseudo selector to change the border color on mouse hover.

HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content=
        "width=device-width, initial-scale=1.0">
    <title>Change Border Color on Hover</title>

    <style>
        body {
            text-align: center;
        }

        .borderColor {
            display: inline-block;
            padding: 30px 50px;
            border: 5px solid black;
        }

        .borderColor:hover {
            border: 5px solid green;
        }
    </style>
</head>

<body>
    <div class="borderColor">
        Code World
    </div>
</body>

</html>

Output:


Next Article

Similar Reads