AI CSS Animations

Underline to Strikethrough Hover

A thick underline slides up through the word and becomes a strikethrough while the text fades, like ticking off a to-do. One pseudo-element moves on translateY; nothing is redrawn.

Also known as: strikethrough on hover, underline moves to line through, cross out text hover.

Buy milk

HTML

<div class="hfx-text-underline-strike">Buy milk</div>

CSS

.hfx-text-underline-strike {
  --c: var(--hfx-color, #3b82f6);
  font-size: calc(var(--hfx-size, 16px) * 2.5);
  font-family: system-ui, sans-serif;
  font-weight: 800;
  line-height: 1.15;
  cursor: default;
  position: relative;
  display: inline-block;
  transition: color 0.45s ease;}
.hfx-text-underline-strike::after {
  content: "";
  position: absolute;
  left: -0.05em;
  right: -0.05em;
  bottom: 0.04em;
  height: 0.08em;
  border-radius: 0.04em;
  background: var(--c);
  transition: transform 0.45s cubic-bezier(0.65, 0, 0.35, 1);
}
.hfx-text-underline-strike:hover { color: color-mix(in srgb, currentColor 40%, transparent); }
.hfx-text-underline-strike:hover::after { transform: translateY(-0.44em); }

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

Tailwind CSS version

The same effect using Tailwind utility classes. No custom CSS or config needed.

<span class="relative inline-block text-5xl font-extrabold transition-colors duration-500 after:absolute after:inset-x-0 after:bottom-0 after:h-1 after:rounded after:bg-blue-500 after:transition-transform after:duration-500 after:content-[''] hover:text-gray-400 hover:after:-translate-y-5">
  Buy milk
</span>

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