AI CSS Animations

Block Swipe Link Hover

A solid block sweeps across the link from the left, covers it for a beat and leaves to the right, and the text underneath has changed color. One keyframe with a mid-way origin flip.

Also known as: block reveal link, color block wipe link, swipe through highlight.

HTML

<a class="hfx-link-block-swipe" href="#">Selected work</a>

CSS

.hfx-link-block-swipe {
  --c: var(--hfx-color, #3b82f6);
  position: relative;
  display: inline-block;
  color: var(--c);
  font: 600 calc(var(--hfx-size, 16px) * 1.25)/1.3 system-ui, sans-serif;
  text-decoration: none;
  color: inherit;
  transition: color 0.3s ease;}
.hfx-link-block-swipe::before {
  content: "";
  position: absolute;
  inset: -0.05em -0.15em;
  background: var(--c);
  transform: scaleX(0);
  transform-origin: left;
}
.hfx-link-block-swipe:is(:hover, :focus-visible) {
  color: var(--c);
  transition: color 0s 0.3s;
}
.hfx-link-block-swipe:is(:hover, :focus-visible)::before {
  animation: hfx-link-block-swipe-pass 0.65s cubic-bezier(0.7, 0, 0.3, 1);
}
@keyframes hfx-link-block-swipe-pass {
  0%   { transform: scaleX(0); transform-origin: left; }
  45%  { transform: scaleX(1); transform-origin: left; }
  55%  { transform: scaleX(1); transform-origin: right; }
  100% { transform: scaleX(0); transform-origin: right; }
}

@media (prefers-reduced-motion: reduce) {
  .hfx-link-block-swipe, .hfx-link-block-swipe *, .hfx-link-block-swipe::before, .hfx-link-block-swipe::after, .hfx-link-block-swipe *::before, .hfx-link-block-swipe *::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

Underline Grow Link
Underline from Center Link
Highlighter Link
Slide Up Text Link