21 CSS Button Hover Effects

Magnetic Border

A conic-gradient border spins into view on hover and the button lifts with a coloured glow.

Pure CSS MIT licensed

Magnetic Border the 2nd of 21 designs in the 21 CSS Button Hover Effects collection. The design is implemented in pure CSS — no JavaScript required. Copy the HTML and CSS panels below into your project. Because the demo is pure CSS, it works in any framework or templating engine you happen to use. The design honours prefers-reduced-motion and uses real semantic markup, so it ships accessibility-ready out of the box.

Live preview

Open in playground

The code

<button class="bhe-02__wrap">
  <span class="bhe-02__inner">Magnetic Border</span>
</button>
.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;
  }
}

Search CodeFronts

Loading…