A live quote that ticks every second, flashing green when the price rises and red when it falls, with a matching arrow. The six prices, colors and arrows all come from generated keyframes.
Also known as: live price animation, price change flash, crypto price ticker css.
<div class="txt-live-price-ticker" aria-label="ACME live price"> <span class="txt-live-price-ticker-sym">ACME</span> <b class="txt-live-price-ticker-price" aria-hidden="true"></b> </div>
@property --txt-live-price-ticker-v {
syntax: "<integer>";
initial-value: 218;
inherits: false;
}
.txt-live-price-ticker {
--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: inline-flex;
align-items: center;
gap: 0.4em;
font-variant-numeric: tabular-nums;
--beat: 1s;}
.txt-live-price-ticker-sym {
padding: 0.2em 0.4em;
border-radius: 0.25em;
font-size: 0.6em;
font-weight: 800;
letter-spacing: 0.08em;
color: #fff;
background: var(--c);
}
.txt-live-price-ticker-price {
display: inline-flex;
align-items: center;
gap: 0.3em;
padding: 0.1em 0.3em;
border-radius: 0.2em;
counter-reset: txt-live-price-ticker-n var(--txt-live-price-ticker-v);
animation:
txt-live-price-ticker-tick calc(var(--beat) * 6) step-end infinite,
txt-live-price-ticker-flash calc(var(--beat) * 6) linear infinite;
}
.txt-live-price-ticker-price::before {
content: "$64," counter(txt-live-price-ticker-n);
}
.txt-live-price-ticker-price::after {
content: "▼";
font-size: 0.55em;
animation: txt-live-price-ticker-arrow calc(var(--beat) * 6) step-end infinite;
}
@keyframes txt-live-price-ticker-tick {
0% { --txt-live-price-ticker-v: 218; }
16.67% { --txt-live-price-ticker-v: 231; }
33.33% { --txt-live-price-ticker-v: 227; }
50% { --txt-live-price-ticker-v: 240; }
66.67% { --txt-live-price-ticker-v: 236; }
83.33% { --txt-live-price-ticker-v: 229; }
100% { --txt-live-price-ticker-v: 218; }
}
@keyframes txt-live-price-ticker-arrow {
0% { content: "▼"; color: #e5484d; }
16.67% { content: "▲"; color: #16a34a; }
33.33% { content: "▼"; color: #e5484d; }
50% { content: "▲"; color: #16a34a; }
66.67% { content: "▼"; color: #e5484d; }
83.33% { content: "▼"; color: #e5484d; }
100% { content: "▼"; color: #e5484d; }
}
@keyframes txt-live-price-ticker-flash {
0% { background-color: color-mix(in srgb, #e5484d 28%, transparent); animation-timing-function: ease-out; }
8.33% { background-color: transparent; animation-timing-function: step-end; }
16.67% { background-color: color-mix(in srgb, #16a34a 28%, transparent); animation-timing-function: ease-out; }
25% { background-color: transparent; animation-timing-function: step-end; }
33.33% { background-color: color-mix(in srgb, #e5484d 28%, transparent); animation-timing-function: ease-out; }
41.67% { background-color: transparent; animation-timing-function: step-end; }
50% { background-color: color-mix(in srgb, #16a34a 28%, transparent); animation-timing-function: ease-out; }
58.33% { background-color: transparent; animation-timing-function: step-end; }
66.67% { background-color: color-mix(in srgb, #e5484d 28%, transparent); animation-timing-function: ease-out; }
75% { background-color: transparent; animation-timing-function: step-end; }
83.33% { background-color: color-mix(in srgb, #e5484d 28%, transparent); animation-timing-function: ease-out; }
91.67% { background-color: transparent; animation-timing-function: step-end; }
100% { background-color: color-mix(in srgb, #e5484d 28%, transparent); }
}
@media (prefers-reduced-motion: reduce) {
.txt-live-price-ticker, .txt-live-price-ticker *, .txt-live-price-ticker::before, .txt-live-price-ticker::after, .txt-live-price-ticker *::before, .txt-live-price-ticker *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}--txt-color on the element or a parent.
Currently previewing #3b82f6.--txt-size. Every other dimension is in
em, so the whole thing scales together. Currently previewing 40px.transition or animation
shorthand. Staggered delays are relative, so they keep their rhythm.