CSS Border Effect Animation
How to Create an Animated Radial Border Effect on Buttons with CSS
Watch the full tutorial here:
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./style.css">
<title>Button border gradient effect</title>
</head>
<body>
<button id="button">Suscribe</button>
</body>
</html>
css
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
width: 100%;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background-color: #111;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
@property --angle {
syntax: "<angle>";
initial-value: 0deg;
inherits: false;
}
#button {
padding: 15px 50px;
font-size: 25px;
border: none;
border-radius: 100px;
background-color: #112C55;
color: #FFF;
font-weight: 500;
text-transform: uppercase;
position: relative;
&::after,
&::before {
content: '';
position: absolute;
width: 100%;
height: 100%;
border-radius: 100px;
background-image: conic-gradient(from var(--angle), red, blue, yellow, red);
top: 50%;
left: 50%;
translate: -50% -50%;
z-index: -10;
padding: 3px;
animation: 3s spin linear infinite;
}
&::before {
filter: blur(1.5rem);
opacity: 0.5;
}
}
@keyframes spin {
from {
--angle: 0deg;
}
to {
--angle: 360deg;
}
}