Dynamic Gradient Border Animation
Home
Snippets
Dynamic Gradient Border Animation
HTML
CSS
JS
<div class="card"> <div class="content"> Dynamic Gradient Border </div> </div>
* { box-sizing: border-box; } body { margin: 0; height: 100vh; display: flex; justify-content: center; align-items: center; background: #0e0e16; font-family: 'Poppins', sans-serif; } .card { position: relative; width: 300px; height: 200px; background: #111; color: #fff; display: flex; align-items: center; justify-content: center; border-radius: 20px; overflow: hidden; font-size: 1.2rem; text-align: center; } .card::before { content: ""; position: absolute; inset: 0; border-radius: 20px; padding: 3px; background: linear-gradient(120deg, #ff0077, #ff7b00, #ffd300, #00ff88, #00aaff, #a000ff, #ff0077); background-size: 400% 400%; -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0); -webkit-mask-composite: xor; mask-composite: exclude; animation: borderMove 6s linear infinite; } @keyframes borderMove { 0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; } } .content { position: relative; z-index: 1; padding: 20px; }
const card = document.querySelector('.card'); card.addEventListener('click', () => { const speed = Math.random() * 5 + 3; card.style.setProperty('--speed', `${speed}s`); });
Ad #1
Ad #2
Scroll to Top