Dark CSS

How to Make Border Color Animation using Html CSS

Facebook
Twitter
WhatsApp

Project Demo

html code

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

<head>
    <meta charset="UTF-8">
    <title>Animated Gradient Border on Focus</title>
    <link rel="stylesheet" href="style.css">
</head>

<body> 

    <div class="input-container">
        <div class="border-effect"></div>
        <input type="email" class="email-input" placeholder="Enter your email">
    </div>

</body>

</html>
				
			

css code

				
					body {
    background: #111;
    display: grid;
    place-items: center;
    height: 100vh;
    margin: 0;
    font-family: Arial, sans-serif;
}

.input-container {
    position: relative;
    width: 300px;
    padding: 3px;
    /* Space for border effect */
    border-radius: 10px; 
    background: #222;
    overflow: hidden;
}

.border-effect {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    opacity: 0;
    z-index: 1;
    background: linear-gradient(270deg, #f22e2e, #ff00ff, #00ffff, #0033ff);
    background-size: 600% 600%;
    border-radius: 10px;
    transition: opacity 0.4s ease;
    animation-play-state: paused;
    animation: gradientShift 6s ease infinite;
}

.email-input {
    position: relative;
    z-index: 2;
    width: 90%;
    padding: 15px;
    font-size: 16px;
    border: none;
    border-radius: 8px;
    background: #222;
    color: white;
    outline: none;
}

.email-input::placeholder {
    color: #777;
}

.input-container:focus-within .border-effect {
    opacity: 1;
    animation-play-state: running;
    /* Start animation on focus */
}

@keyframes gradientShift {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}