AI CSS Animations

Slide Up Text Link

The link text rolls up and out while an identical copy rolls in from below in the accent color. The copy comes from a data attribute, so the markup stays a single word.

Also known as: text roll link, duplicate text hover.

HTML

<a class="hfx-link-slide-text" href="#" data-text="About us"><span>About us</span></a>

CSS

.hfx-link-slide-text {
  --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;
  overflow: hidden;
  color: inherit;
  line-height: 1.2;}
.hfx-link-slide-text span {
  display: block;
  transition: transform 0.3s ease;
}
.hfx-link-slide-text::after {
  content: attr(data-text);
  position: absolute;
  left: 0;
  top: 100%;
  color: var(--c);
  transition: transform 0.3s ease;
}
.hfx-link-slide-text:hover span,
.hfx-link-slide-text:hover::after { transform: translateY(-100%); }

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