Magnetic Hover Button
Preview
Edit
Download
Run
Download Options
HTML File
Download as .html file
CSS File
Download as .css file
JavaScript File
Download as .js file
Combined HTML
All code in one HTML file
Project ZIP
All files in a ZIP archive
Cancel
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title> Buttons </title> </head> <body> <div class="container"> <div class="buttons-grid"> <div class="button-card"> <div class="button-title"> Magnetic Hover</div> <button class="btn-magnetic">Magnetic Pull</button> </div> </div> </div> </body> </html>
CSS
* { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2rem; } .container { max-width: 1200px; width: 100%; } .button-title { color: white; font-size: 1.1rem; margin-bottom: 1rem; font-weight: 600; } /* Button 8: Magnetic */ .btn-magnetic { background: #e74c3c; color: white; border: none; padding: 15px 30px; border-radius: 15px; font-size: 16px; font-weight: 600; cursor: pointer; transition: all 0.3s cubic-bezier(0.23, 1, 0.320, 1); position: relative; } .btn-magnetic:hover { transform: scale(1.1); box-shadow: 0 15px 30px rgba(231, 76, 60, 0.4); } @media (max-width: 768px) { .buttons-grid { grid-template-columns: 1fr; } h1 { font-size: 2rem; } }
JavaScript
// Add click feedback for all buttons document.querySelectorAll('button').forEach(button => { button.addEventListener('click', function() { // Create a temporary scale effect on click this.style.transform = 'scale(0.95)'; setTimeout(() => { this.style.transform = ''; }, 150); }); }); // Add extra interactivity to the magnetic button const magneticBtn = document.querySelector('.btn-magnetic'); magneticBtn.addEventListener('mousemove', function(e) { const rect = this.getBoundingClientRect(); const x = e.clientX - rect.left - rect.width / 2; const y = e.clientY - rect.top - rect.height / 2; this.style.transform = `translate(${x * 0.1}px, ${y * 0.1}px) scale(1.1)`; }); magneticBtn.addEventListener('mouseleave', function() { this.style.transform = ''; });
Output Preview
Desktop
Mobile
Fullscreen