Glassmorphic Card
Home
Snippets
Glassmorphic Card
HTML
CSS
JS
<div class="card-container"> <div class="card"> <h2>Web Design</h2> <p>Interactive, modern and responsive websites.</p> <div class="glow"></div> </div> </div>
body { margin: 0; height: 100vh; display: flex; justify-content: center; align-items: center; font-family: 'Poppins', sans-serif; background: linear-gradient(135deg, #1b1b1b 0%, #0e0e0e 100%); position: relative; overflow: hidden; } body::before, body::after { content: ''; position: absolute; width: 400px; height: 400px; border-radius: 50%; filter: blur(120px); opacity: 0.2; z-index: 0; } body::before { background: #00ffc3; top: 10%; left: 10%; } body::after { background: #ff00f7; bottom: 10%; right: 10%; } .card-container { perspective: 1000px; z-index: 1; } .card::after { content: ''; position: absolute; inset: 0; opacity: 0.05; pointer-events: none; z-index: 1; } .card { position: relative; width: 320px; padding: 2em; color: white; border-radius: 20px; backdrop-filter: blur(14px); background: rgba(255, 255, 255, 0.05); box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4); overflow: hidden; transform-style: preserve-3d; transition: transform 0.1s ease; font-family: 'Poppins', sans-serif; z-index: 1; } .card::before { content: ''; position: absolute; inset: 0; border-radius: 20px; padding: 2px; background: linear-gradient(var(--angle, 135deg), rgba(255,255,255,0.1), rgba(255,255,255,0)); -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0); -webkit-mask-composite: xor; mask-composite: exclude; pointer-events: none; z-index: 2; transition: background 0.2s ease; } .glow { position: absolute; top: var(--y, 50%); left: var(--x, 50%); width: 200px; height: 200px; background: radial-gradient(circle at center, rgba(0, 255, 200, 0.2), transparent 80%); transform: translate(-50%, -50%); pointer-events: none; opacity: 0; transition: top 0.1s, left 0.1s, opacity 0.3s ease; z-index: 0; } .card:hover .glow { opacity: 1; }
const card = document.querySelector('.card'); const glow = card.querySelector('.glow'); card.addEventListener('mousemove', (e) => { const rect = card.getBoundingClientRect(); const x = e.clientX - rect.left; const y = e.clientY - rect.top; card.style.setProperty('--x', `${x}px`); card.style.setProperty('--y', `${y}px`); const centerX = rect.width / 2; const centerY = rect.height / 2; const rotateX = ((y - centerY) / centerY) * 10; const rotateY = ((x - centerX) / centerX) * -10; card.style.transform = `rotateX(${rotateX}deg) rotateY(${rotateY}deg)`; const angle = 135 + rotateX - rotateY; card.style.setProperty('--angle', `${angle}deg`); }); card.addEventListener('mouseleave', () => { card.style.transform = `rotateX(0deg) rotateY(0deg)`; card.style.setProperty('--angle', `135deg`); });
Ad #1
Ad #2
Scroll to Top