AI CSS Animations

Marquee Text Hover Effect

A title too long for its pill fades out at the edge, then scrolls like a ticker while hovered. Two copies on one track loop at translateX(-50%), the pattern music apps use for song titles.

Also known as: scroll text on hover, ticker text hover, overflowing title scroll.

Late Night Drive · Side B

HTML

<div class="hfx-text-marquee">
  <span class="hfx-text-marquee-icon" aria-hidden="true">&#9834;</span>
  <div class="hfx-text-marquee-view">
    <div class="hfx-text-marquee-track">
      <span>Late Night Drive &middot; Side B</span>
      <span aria-hidden="true">Late Night Drive &middot; Side B</span>
    </div>
  </div>
</div>

CSS

.hfx-text-marquee {
  --c: var(--hfx-color, #3b82f6);
  font-size: calc(var(--hfx-size, 16px) * 1.4);
  font-family: system-ui, sans-serif;
  font-weight: 800;
  line-height: 1.15;
  cursor: default;
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.35em 0.5em 0.35em 0.4em;
  border-radius: 2em;
  background: color-mix(in srgb, var(--c) 12%, transparent);
  font-weight: 700;}
.hfx-text-marquee-icon {
  display: grid;
  place-items: center;
  width: 1.5em;
  height: 1.5em;
  border-radius: 50%;
  background: var(--c);
  color: #fff;
  font-size: 0.9em;
}
.hfx-text-marquee-view {
  width: 8.5em;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 0.4em, #000 calc(100% - 2em), transparent);
  mask-image: linear-gradient(90deg, transparent, #000 0.4em, #000 calc(100% - 2em), transparent);
}
.hfx-text-marquee-track {
  display: flex;
  width: max-content;
}
.hfx-text-marquee-track span {
  padding: 0 1.2em 0 0.4em;
  white-space: nowrap;
}
.hfx-text-marquee:hover .hfx-text-marquee-track {
  animation: hfx-text-marquee-scroll 5s linear infinite;
}
@keyframes hfx-text-marquee-scroll {
  to { transform: translateX(-50%); }
}

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