AI CSS Animations

Underline from Center Link

The same drawn underline, but it grows outward from the middle. Only the transform origin changes, which makes it a good companion to the left-to-right version.

Also known as: center out underline, expanding underline.

HTML

<a class="hfx-link-underline-center" href="#">Our story</a>

CSS

.hfx-link-underline-center {
  --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;
}
.hfx-link-underline-center::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -0.15em;
  width: 100%;
  height: 2px;
  background: var(--c);
  transform: scaleX(0);
  transform-origin: center;
  transition: transform 0.3s ease;
}
.hfx-link-underline-center:hover::after { transform: scaleX(1); }

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