AI CSS Animations

Stock Ticker Animation

A market ticker tape: symbols, prices and green or red changes with arrows glide past on a thin band. The tape is a two-copy marquee, so it can hold any number of quotes without a seam.

Also known as: stock ticker css, crypto price ticker, market ticker tape.

ACME 182.40 1.2% NOVA 64.18 0.8% ORBT 23.05 3.4% KITE 412.90 0.3% ZETA 9.72 0.6%

HTML

<div class="txt-stock-ticker">
  <div class="txt-stock-ticker-track">
    <span><b>ACME</b> 182.40 <i class="txt-stock-ticker-up">1.2%</i></span>
    <span><b>NOVA</b> 64.18 <i class="txt-stock-ticker-down">0.8%</i></span>
    <span><b>ORBT</b> 23.05 <i class="txt-stock-ticker-up">3.4%</i></span>
    <span><b>KITE</b> 412.90 <i class="txt-stock-ticker-down">0.3%</i></span>
    <span><b>ZETA</b> 9.72 <i class="txt-stock-ticker-up">0.6%</i></span>
  </div>
  <div class="txt-stock-ticker-track" aria-hidden="true">
    <span><b>ACME</b> 182.40 <i class="txt-stock-ticker-up">1.2%</i></span>
    <span><b>NOVA</b> 64.18 <i class="txt-stock-ticker-down">0.8%</i></span>
    <span><b>ORBT</b> 23.05 <i class="txt-stock-ticker-up">3.4%</i></span>
    <span><b>KITE</b> 412.90 <i class="txt-stock-ticker-down">0.3%</i></span>
    <span><b>ZETA</b> 9.72 <i class="txt-stock-ticker-up">0.6%</i></span>
  </div>
</div>

CSS

.txt-stock-ticker {
  --c: var(--txt-color, #3b82f6);
  font-size: calc(var(--txt-size, 32px) * 0.72);
  font-family: system-ui, sans-serif;
  font-weight: 700;
  line-height: 1.2;
  display: flex;
  width: 19em;
  padding: 0.5em 0;
  overflow: hidden;
  white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  border-block: 1px solid color-mix(in srgb, var(--c) 35%, transparent);
  background: color-mix(in srgb, var(--c) 7%, transparent);
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 12%, #000 88%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 12%, #000 88%, transparent);}
.txt-stock-ticker-track {
  display: flex;
  flex-shrink: 0;
  animation: txt-stock-ticker-scroll 18s linear infinite;
}
.txt-stock-ticker-track span {
  padding: 0 0.9em;
  border-right: 1px solid color-mix(in srgb, var(--c) 30%, transparent);
}
.txt-stock-ticker-track b {
  color: var(--c);
  font-weight: 800;
}
.txt-stock-ticker-track i {
  font-style: normal;
  font-weight: 700;
}
.txt-stock-ticker-up { color: #16a34a; }
.txt-stock-ticker-down { color: #e5484d; }
.txt-stock-ticker-up::before { content: "▲ "; font-size: 0.7em; }
.txt-stock-ticker-down::before { content: "▼ "; font-size: 0.7em; }
@keyframes txt-stock-ticker-scroll {
  to { transform: translateX(-100%); }
}

@media (prefers-reduced-motion: reduce) {
  .txt-stock-ticker, .txt-stock-ticker *, .txt-stock-ticker::before, .txt-stock-ticker::after, .txt-stock-ticker *::before, .txt-stock-ticker *::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