Sat Jul 23 2022

Animated Button Border

CSS4907 views

File Name: Button-Border-Animation.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Button Border Effect</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        body {
            background-color: #292929;
        }

        section {
            display: flex;
            justify-content: center;
            align-items: center;
            width: 100%;
            height: 100vh;
        }

        button {
            font-size: 20px;
            padding: 10px 20px;
            border: none;
            position: relative;
            background-color: transparent;
            color: #fff;
            transition: 0.3s all ease-in-out;
            cursor: pointer;
        }
        
        button::before {
            position: absolute;
            content: '';
            border-top: #fff solid 3px;
            border-left: #fff solid 3px;
            width: 10%;
            height: 30%;
            top: -3px;
            left: -3px;
            transition: 0.3s all ease-in-out;
        }

        button::after {
            position: absolute;
            content: '';
            border-bottom: #fff solid 3px;
            border-right: #fff solid 3px;
            width: 10%;
            height: 30%;
            bottom: -3px;
            right: -3px;
            transition: 0.3s all ease-in-out;
        }

        button:hover {
            color: #d84400;
        }

        button:hover::before,
        button:hover::after {
            width: 100%;
            height: 105%;
            border-color: #d84400;
        }
        
    </style>
</head>
<body>
    <section>
        <button>Hi! Geek</button>
    </section>
</body>
</html>

Result Screenshot(s)

Animated Button BorderWorking Sample0

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.