AI CSS Animations

Scrolling Marquee

Text scrolls endlessly from right to left with no seam. The trick is two copies of the content moving together by exactly one copy's width, so the loop point is invisible.

Also known as: css marquee, ticker text, scrolling text banner.

Now shipping worldwide · Free returns · New colors every month · 

HTML

<div class="txt-marquee">
  <span>Now shipping worldwide · Free returns · New colors every month ·&nbsp;</span>
  <span aria-hidden="true">Now shipping worldwide · Free returns · New colors every month ·&nbsp;</span>
</div>

CSS

.txt-marquee {
  --c: var(--txt-color, #3b82f6);
  font-size: var(--txt-size, 32px);
  font-family: system-ui, sans-serif;
  font-weight: 700;
  line-height: 1.2;
  display: flex;
  width: 20em;
  overflow: hidden;
  white-space: nowrap;
  font-weight: 600;
  color: var(--c);
  mask-image: linear-gradient(90deg, transparent, #000 10%, #000 90%, transparent);
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 10%, #000 90%, transparent);}
.txt-marquee span {
  flex-shrink: 0;
  animation: txt-marquee-scroll 12s linear infinite;
}
@keyframes txt-marquee-scroll {
  to { transform: translateX(-100%); }
}

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

Customizing this snippet

  • Color: set --txt-color on the element or a parent. Currently previewing #3b82f6.
  • Font size: set --txt-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 40px.
  • 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 text animations