Back to CSS Button Hover Effects Magnetic Border Pure CSS
Share
HTML
<button class="bhe-02__wrap">
  <span class="bhe-02__inner">Magnetic Border</span>
</button>
CSS
.bhe-02__wrap {
  font-family: inherit;
  letter-spacing: 0.02em;
  background: transparent;
  color: inherit;
}

.bhe-02__wrap {
  position: relative;
  padding: 2px;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 8px;
  display: inline-block;
}
.bhe-02__wrap::before {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 10px;
  background: conic-gradient(#7c6cff, #ff6c8a, #3de8f5, #1ed98a, #7c6cff);
  opacity: 0;
  transition: opacity 0.3s;
  animation: border-spin 3s linear infinite paused;
}
.bhe-02__wrap:hover::before {
  opacity: 1;
  animation-play-state: running;
}
@keyframes border-spin {
  to {
    transform: rotate(360deg);
  }
}
.bhe-02__inner {
  display: block;
  padding: 12px 32px;
  border-radius: 7px;
  background: #111118;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  transition:
    transform 0.3s,
    box-shadow 0.3s;
}
.bhe-02__wrap:hover .bhe-02__inner {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(124, 108, 255, 0.3);
}

@media (prefers-reduced-motion: reduce) {
  .bhe-02__wrap,
  .bhe-02__wrap * {
    animation: none !important;
  }
}