A query types into a command palette and the results re-rank as you watch: the match slides to the top, lights up and shows its highlighted term, the rest dim. Rows move with transforms only.
Also known as: cmd k search animation, command menu animation css, spotlight search typing.
<div class="txt-command-palette-typing">
<div class="txt-command-palette-typing-input">
<svg class="txt-command-palette-typing-icon" viewBox="0 0 24 24" aria-hidden="true"><circle cx="11" cy="11" r="6.5"/><path d="m16 16 4.5 4.5"/></svg>
<span class="txt-command-palette-typing-q" aria-label="theme"><span aria-hidden="true"><span style="--i: 0">t</span><span style="--i: 1">h</span><span style="--i: 2">e</span><span style="--i: 3">m</span><span style="--i: 4">e</span></span></span>
<kbd class="txt-command-palette-typing-kbd">⌘K</kbd>
</div>
<ul class="txt-command-palette-typing-list">
<li class="txt-command-palette-typing-row">New file</li>
<li class="txt-command-palette-typing-row txt-command-palette-typing-hit">Toggle <mark>theme</mark><span class="txt-command-palette-typing-enter" aria-hidden="true">↵</span></li>
<li class="txt-command-palette-typing-row">Share link</li>
</ul>
</div>.txt-command-palette-typing {
--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-block;
width: 13em;
overflow: hidden;
border-radius: 0.7em;
font-size: calc(var(--txt-size, 32px) * 0.56);
font-weight: 500;
line-height: 1.2;
text-align: left;
background: color-mix(in srgb, currentColor 4%, transparent);
box-shadow: inset 0 0 0 1px color-mix(in srgb, currentColor 16%, transparent), 0 0.6em 1.2em -0.8em rgb(0 0 0 / 0.3);}
.txt-command-palette-typing-input {
display: flex;
align-items: center;
gap: 0.5em;
padding: 0.7em 0.8em;
box-shadow: inset 0 -1px 0 color-mix(in srgb, currentColor 12%, transparent);
}
.txt-command-palette-typing-icon {
display: block;
width: 1.1em;
height: 1.1em;
fill: none;
stroke: color-mix(in srgb, currentColor 50%, transparent);
stroke-width: 2.2;
stroke-linecap: round;
}
.txt-command-palette-typing-q {
flex: 1;
white-space: nowrap;
}
.txt-command-palette-typing-q span span {
position: relative;
opacity: 0;
animation: txt-command-palette-typing-key 0s calc(0.4s + var(--i) * 0.15s) forwards;
}
.txt-command-palette-typing-q span span::after {
content: "";
position: absolute;
top: 0.05em;
bottom: 0;
right: -0.07em;
width: 0.08em;
background: var(--c);
opacity: 0;
animation: txt-command-palette-typing-caret 0.15s step-end calc(0.4s + var(--i) * 0.15s);
}
.txt-command-palette-typing-q span span:last-child::after {
animation: txt-command-palette-typing-blink 1s step-end calc(0.4s + var(--i) * 0.15s) infinite;
}
.txt-command-palette-typing-kbd {
padding: 0.15em 0.4em;
border-radius: 0.3em;
font: inherit;
font-size: 0.75em;
color: color-mix(in srgb, currentColor 55%, transparent);
box-shadow: inset 0 0 0 1px color-mix(in srgb, currentColor 22%, transparent);
}
.txt-command-palette-typing-list {
margin: 0;
padding: 0.35em;
list-style: none;
}
.txt-command-palette-typing-row {
display: flex;
align-items: center;
height: 2em;
padding: 0 0.6em;
border-radius: 0.4em;
animation: txt-command-palette-typing-dim 0.4s cubic-bezier(0.3, 0.9, 0.3, 1) 0.75s forwards;
}
.txt-command-palette-typing-row:first-child { --to: translateY(100%); }
.txt-command-palette-typing-hit {
animation: txt-command-palette-typing-rise 0.4s cubic-bezier(0.3, 0.9, 0.3, 1) 0.75s forwards;
}
.txt-command-palette-typing mark {
margin-left: 0.3em;
color: inherit;
background: none;
animation: txt-command-palette-typing-match 0.3s ease-out 1.15s forwards;
}
.txt-command-palette-typing-enter {
margin-left: auto;
opacity: 0;
color: var(--c);
animation: txt-command-palette-typing-key 0.3s ease-out 1.3s forwards;
}
@keyframes txt-command-palette-typing-key {
to { opacity: 1; }
}
@keyframes txt-command-palette-typing-caret {
0%, 100% { opacity: 1; }
}
@keyframes txt-command-palette-typing-blink {
0% { opacity: 1; }
50% { opacity: 0; }
}
@keyframes txt-command-palette-typing-dim {
to { opacity: 0.45; transform: var(--to, none); }
}
@keyframes txt-command-palette-typing-rise {
to { transform: translateY(-100%); background: color-mix(in srgb, var(--c) 14%, transparent); }
}
@keyframes txt-command-palette-typing-match {
to { color: var(--c); font-weight: 700; }
}
@media (prefers-reduced-motion: reduce) {
.txt-command-palette-typing, .txt-command-palette-typing *, .txt-command-palette-typing::before, .txt-command-palette-typing::after, .txt-command-palette-typing *::before, .txt-command-palette-typing *::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.