AI CSS Animations

Ripple In Hover Effect

Two rings close in from outside the button, one after the other, and fade as they land on its edge while the button takes a light tint. The reverse of a ripple: it pulls the eye in.

Also known as: hvr-ripple-in, converging ring hover, ring closes in on hover.

HTML

<button class="hfx-ripple-in">Take the tour</button>

CSS

.hfx-ripple-in {
  --c: var(--hfx-color, #3b82f6);
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  padding: 0.7em 1.6em;
  border-radius: 0.5em;
  font: 600 var(--hfx-size, 16px) system-ui, sans-serif;
  cursor: pointer;
  position: relative;
  border: 2px solid var(--c);
  background: transparent;
  color: var(--c);
  transition: background-color 0.3s ease;}
.hfx-ripple-in::before,
.hfx-ripple-in::after {
  content: "";
  position: absolute;
  inset: -2px;
  border: 2px solid var(--c);
  border-radius: 0.5em;
  opacity: 0;
  pointer-events: none;
}
.hfx-ripple-in:is(:hover, :focus-visible) {
  background: color-mix(in srgb, var(--c) 12%, transparent);
}
.hfx-ripple-in:is(:hover, :focus-visible)::before {
  animation: hfx-ripple-in-close 0.6s cubic-bezier(0.3, 0, 0.3, 1);
}
.hfx-ripple-in:is(:hover, :focus-visible)::after {
  animation: hfx-ripple-in-close 0.6s cubic-bezier(0.3, 0, 0.3, 1) 0.18s backwards;
}
@keyframes hfx-ripple-in-close {
  from { inset: -1em; border-radius: 1.5em; opacity: 0; }
  60%  { opacity: 1; }
  to   { inset: -2px; border-radius: 0.5em; opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .hfx-ripple-in, .hfx-ripple-in *, .hfx-ripple-in::before, .hfx-ripple-in::after, .hfx-ripple-in *::before, .hfx-ripple-in *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Customizing this snippet

  • Color: set --hfx-color on the element or a parent. Currently previewing #3b82f6.
  • Base size: set --hfx-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 16px.
  • Speed: change the duration on the transition or animation shorthand. Staggered delays are relative, so they keep their rhythm.
  • Reduced motion: the rule at the end of the CSS turns the motion off for people who asked their OS for less of it. Keep it.

Similar hover effects