AI CSS Animations

Mention Chip Typing Effect

Typing @maya opens a small suggestion menu, then the name snaps into an accent-colored chip and typing carries on. The chip is a background plus a spread shadow, so the text never shifts.

Also known as: @mention animation css, tag a user typing animation, mention autocomplete effect.

HTML

<div class="txt-mention-chip-typing" aria-label="Nice work @maya!">
  <span class="txt-mention-chip-typing-t" aria-hidden="true"><span style="--i: 0">N</span><span style="--i: 1">i</span><span style="--i: 2">c</span><span style="--i: 3">e</span><span style="--i: 4">&nbsp;</span><span style="--i: 5">w</span><span style="--i: 6">o</span><span style="--i: 7">r</span><span style="--i: 8">k</span><span style="--i: 9">&nbsp;</span><span class="txt-mention-chip-typing-at"><span style="--i: 10">@</span><span style="--i: 11">m</span><span style="--i: 12">a</span><span style="--i: 13">y</span><span style="--i: 14">a</span><span class="txt-mention-chip-typing-menu"><i></i>Maya Chen</span></span><span style="--i: 15; --x: 0.65s">!</span></span>
</div>

CSS

.txt-mention-chip-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;
  font-size: calc(var(--txt-size, 32px) * 0.85);
  font-weight: 600;
  white-space: nowrap;}
.txt-mention-chip-typing-t span:not([class]) {
  position: relative;
  opacity: 0;
  animation: txt-mention-chip-typing-key 0s calc(0.3s + var(--i) * 80ms + var(--x, 0s)) forwards;
}
.txt-mention-chip-typing-t span:not([class])::after {
  content: "";
  position: absolute;
  top: 0.12em;
  bottom: 0.05em;
  right: -0.05em;
  width: 0.07em;
  background: var(--c);
  opacity: 0;
  animation: txt-mention-chip-typing-caret 80ms step-end calc(0.3s + var(--i) * 80ms + var(--x, 0s));
}
/* the caret waits on the last letter of the name while the menu is open */
.txt-mention-chip-typing-at span:nth-child(5)::after {
  animation-duration: 0.73s;
}
.txt-mention-chip-typing-t > span:last-child::after {
  animation: txt-mention-chip-typing-blink 1s step-end calc(0.3s + var(--i) * 80ms + var(--x, 0s)) infinite;
}
.txt-mention-chip-typing-at {
  position: relative;
  border-radius: 0.3em;
  animation: txt-mention-chip-typing-chip 0.25s ease-out 1.93s forwards;
}
.txt-mention-chip-typing-menu {
  position: absolute;
  top: 130%;
  left: -0.2em;
  display: flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.35em 0.7em 0.35em 0.4em;
  border-radius: 0.5em;
  font-size: 0.6em;
  font-weight: 500;
  color: currentColor;
  background: color-mix(in srgb, currentColor 7%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, currentColor 15%, transparent);
  opacity: 0;
  transform-origin: 0 0;
  animation: txt-mention-chip-typing-menu 0.9s ease-out 1.15s both;
}
.txt-mention-chip-typing-menu i {
  width: 1.2em;
  height: 1.2em;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--c), color-mix(in srgb, var(--c) 40%, transparent));
}
@keyframes txt-mention-chip-typing-key {
  to { opacity: 1; }
}
@keyframes txt-mention-chip-typing-caret {
  0%, 100% { opacity: 1; }
}
@keyframes txt-mention-chip-typing-blink {
  0% { opacity: 1; }
  50% { opacity: 0; }
}
@keyframes txt-mention-chip-typing-menu {
  0% { opacity: 0; transform: translateY(-0.3em) scale(0.95); }
  15%, 70% { opacity: 1; transform: none; background: color-mix(in srgb, currentColor 7%, transparent); }
  80%, 88% { opacity: 1; transform: none; background: color-mix(in srgb, var(--c) 22%, transparent); }
  100% { opacity: 0; transform: none; }
}
@keyframes txt-mention-chip-typing-chip {
  to {
    color: var(--c);
    background: color-mix(in srgb, var(--c) 15%, transparent);
    box-shadow: 0 0 0 0.12em color-mix(in srgb, var(--c) 15%, transparent);
  }
}

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