Magnetic Button

A button with magnetic hover effect that follows cursor movement.

button
magnetic
hover
interactive

Preview

Loading preview...

HTML

<button class="magnetic-button">Magnetic Button</button>

CSS

.magnetic-button {
  position: relative;
  padding: 16px 32px;
  background: linear-gradient(45deg, #667eea, #764ba2);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.23, 1, 0.320, 1);
  overflow: hidden;
  z-index: 1;
}
.magnetic-button::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(45deg, #764ba2, #667eea);
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: -1;
}
.magnetic-button:hover::before {
  opacity: 1;
}
.magnetic-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
}

© 2025 AnyCSS. All rights reserved.