AI CSS Animations

Highlighter Link

A translucent highlighter stroke fills in behind the text from left to right, like someone running a marker across it. Done with an animated background size.

Also known as: marker highlight hover, background fill link.

HTML

<a class="hfx-link-highlight" href="#">Why we built this</a>

CSS

.hfx-link-highlight {
  --c: var(--hfx-color, #3b82f6);
  font-size: var(--hfx-size, 16px);
  position: relative;
  display: inline-block;
  color: var(--c);
  font: 600 1em system-ui, sans-serif;
  text-decoration: none;
  color: inherit;
  background: linear-gradient(color-mix(in srgb, var(--c) 40%, transparent), color-mix(in srgb, var(--c) 40%, transparent)) no-repeat 0 100%;
  background-size: 0% 45%;
  transition: background-size 0.35s ease;}
.hfx-link-highlight:hover { background-size: 100% 45%; }

@media (prefers-reduced-motion: reduce) {
  .hfx-link-highlight, .hfx-link-highlight *, .hfx-link-highlight::before, .hfx-link-highlight::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
Slide Up Text Link
Arrow Link