A line of code whose string value flicks through options, each change flashing a faint highlight behind the token like an editor marking an edit. Same-length values keep the closing quote still.
Also known as: code syntax text rotator, rotating prop value, developer headline animation.
<div class="txt-code-token-rotating-text">variant=<span class="txt-code-token-rotating-text-token">"<span class="txt-code-token-rotating-text-window"><span class="txt-code-token-rotating-text-track"><span>primary</span><span>outline</span><span>neutral</span><span>success</span><span aria-hidden="true">primary</span></span></span>"</span></div>
.txt-code-token-rotating-text {
--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;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-weight: 600;
white-space: nowrap;
color: color-mix(in srgb, currentColor 55%, transparent);}
.txt-code-token-rotating-text-token {
display: inline-flex;
align-items: center;
padding: 0 0.12em;
border-radius: 0.12em;
color: var(--c);
animation: txt-code-token-rotating-text-flash 1.8s ease-out infinite;
}
.txt-code-token-rotating-text-window {
display: block;
height: 1.2em;
overflow: hidden;
}
.txt-code-token-rotating-text-track {
display: flex;
flex-direction: column;
/* 4 values x 1.8s = 7.2s; the 5th repeats the 1st */
animation: txt-code-token-rotating-text-flick 7.2s cubic-bezier(0.8, 0, 0.2, 1) infinite;
}
.txt-code-token-rotating-text-track span {
height: 1.2em;
}
@keyframes txt-code-token-rotating-text-flick {
0%, 20.83% { transform: translateY(0); }
25%, 45.83% { transform: translateY(-1.2em); }
50%, 70.83% { transform: translateY(-2.4em); }
75%, 95.83% { transform: translateY(-3.6em); }
100% { transform: translateY(-4.8em); }
}
@keyframes txt-code-token-rotating-text-flash {
0%, 82% { background: transparent; }
92% { background: color-mix(in srgb, var(--c) 22%, transparent); }
100% { background: transparent; }
}
@media (prefers-reduced-motion: reduce) {
.txt-code-token-rotating-text, .txt-code-token-rotating-text *, .txt-code-token-rotating-text::before, .txt-code-token-rotating-text::after, .txt-code-token-rotating-text *::before, .txt-code-token-rotating-text *::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.