Dark CSS

Create Button with Border Animation

Facebook
Twitter
WhatsApp

Code Preview

HTML Code

				
					<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Rotating Border Animation</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <button class="real-button"></button>
    <div class="button-container">
        <div class="spin spin-blur"></div>
        <div class="spin spin-intense"></div>
        <div class="button-border">
            <div class="spin spin-inside"></div>
            <div class="button">Button</div>
        </div>
    </div>

</body>
</html>
				
			

css Code

				
					* {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}

html,
body {
    display: grid;
    height: 100%;
    place-items: center;
    background: #212121;
}

.button-container {
    position: relative;
    margin: 0 2em;
}

.button-border {
    padding: 3px;
    inset: 0;
    background: #0005;
    border-radius: inherit;
    clip-path: path("M 90 0 C 121 0 126 5 126 33 C 126 61 121 66 90 66 L 33 66 C 5 66 0 61 0 33 C 0 5 5 0 33 0 Z"
        );
}

.button {
    justify-content: center;
    align-items: center;
    border: none;
    border-radius: 0.875em;
    clip-path: path("M 90 0 C 115 0 120 5 120 30 C 120 55 115 60 90 60 L 30 60 C 5 60 0 55 0 30 C 0 5 5 0 30 0 Z"
        );
    width: 120px;
    height: 60px;
    background: #111215;
    display: flex;
    flex-direction: column;
    color: #fff;
    overflow: hidden;
}

.real-button {
    position: absolute;
    width: 120px;
    height: 60px;
    z-index: 1;
    outline: none;
    border: none;
    border-radius: 17px;
    cursor: pointer;
    opacity: 0;
}


.spin {
    position: absolute;
    inset: 0;
    z-index: -2;
    opacity: 0.5;
    overflow: hidden;
    transition: 0.3s;
}

.real-button:active~div .spin {
    opacity: 1;
}

.spin-inside {
    inset: -2px;
    border-radius: inherit;
    filter: blur(2px);
    z-index: 0;
}

.spin-inside::before {
    background: linear-gradient(180deg, rgb(251, 0, 176) 30%, #f0f8ee03 45% 55%, rgb(0, 213, 251) 70%);
}

.spin::before {
    content: "";
    position: absolute;
    inset: -150%;
    animation: animate 8s cubic-bezier(0.56,
            0.15, 0.28, 0.86) infinite;
    animation-play-state: paused;
}

.real-button:hover~div .spin::before {
    animation-play-state: running;
}

@keyframes animate {
    0% {
        rotate: 10deg;
    }

    50% {
        rotate: 190deg;
    }

    to {
        rotate: 370deg;
    }
}