AI CSS Animations

URL Bar Typing Animation

Three letters type into a browser address bar, the rest of the address appears as a highlighted inline suggestion, then Enter accepts it and a thin loading bar runs along the bottom.

Also known as: address bar autocomplete animation, browser url typing css, inline autocomplete effect.

HTML

<div class="txt-url-bar-typing" aria-label="example.com">
  <svg class="txt-url-bar-typing-lock" viewBox="0 0 24 24" aria-hidden="true"><rect x="5" y="10.5" width="14" height="10" rx="2.5"/><path d="M8.5 10.5V8a3.5 3.5 0 0 1 7 0v2.5"/></svg>
  <span class="txt-url-bar-typing-field" aria-hidden="true">
    <span class="txt-url-bar-typing-ph">Search or type URL</span>
    <span class="txt-url-bar-typing-t"><span style="--i: 0">e</span><span style="--i: 1">x</span><span style="--i: 2">a</span><span class="txt-url-bar-typing-sel">mple.com</span></span>
  </span>
  <span class="txt-url-bar-typing-load" aria-hidden="true"></span>
</div>

CSS

.txt-url-bar-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;
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.6em;
  box-sizing: border-box;
  width: 15em;
  overflow: hidden;
  padding: 0.6em 1em;
  border-radius: 99em;
  font-size: calc(var(--txt-size, 32px) * 0.62);
  font-weight: 500;
  text-align: left;
  background: color-mix(in srgb, currentColor 5%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, currentColor 16%, transparent);}
.txt-url-bar-typing-lock {
  display: block;
  flex: none;
  width: 1em;
  height: 1em;
  fill: none;
  stroke: var(--c);
  stroke-width: 2.2;
  stroke-linecap: round;
}
.txt-url-bar-typing-field {
  display: grid;
  white-space: nowrap;
}
.txt-url-bar-typing-ph,
.txt-url-bar-typing-t {
  grid-area: 1 / 1;
}
.txt-url-bar-typing-ph {
  color: color-mix(in srgb, currentColor 45%, transparent);
  animation: txt-url-bar-typing-gone 0s 0.4s forwards;
}
.txt-url-bar-typing-t > span:not(.txt-url-bar-typing-sel) {
  position: relative;
  opacity: 0;
  animation: txt-url-bar-typing-key 0s calc(0.45s + var(--i) * 0.16s) forwards;
}
.txt-url-bar-typing-t > span:not(.txt-url-bar-typing-sel)::after {
  content: "";
  position: absolute;
  top: 0.1em;
  bottom: 0.05em;
  right: -0.06em;
  width: 0.08em;
  background: var(--c);
  opacity: 0;
  animation: txt-url-bar-typing-caret 0.16s step-end calc(0.45s + var(--i) * 0.16s);
}
/* the browser's suggestion: selected text, accepted on Enter */
.txt-url-bar-typing-sel {
  visibility: hidden;
  border-radius: 0.15em;
  animation:
    txt-url-bar-typing-show 0s 0.95s forwards,
    txt-url-bar-typing-accept 1.2s ease-out 0.95s both;
}
.txt-url-bar-typing-load {
  position: absolute;
  left: 1.2em;
  right: 1.2em;
  bottom: 0;
  height: 0.14em;
  border-radius: 0.1em;
  background: var(--c);
  transform: scaleX(0);
  transform-origin: left;
  animation: txt-url-bar-typing-load 1.1s cubic-bezier(0.3, 0.6, 0.3, 1) 2.2s forwards;
}
@keyframes txt-url-bar-typing-gone {
  to { visibility: hidden; }
}
@keyframes txt-url-bar-typing-key {
  to { opacity: 1; }
}
@keyframes txt-url-bar-typing-caret {
  0%, 100% { opacity: 1; }
}
@keyframes txt-url-bar-typing-show {
  to { visibility: visible; }
}
@keyframes txt-url-bar-typing-accept {
  0%, 85% { color: #fff; background: var(--c); }
}
@keyframes txt-url-bar-typing-load {
  0% { transform: scaleX(0); opacity: 1; }
  80% { transform: scaleX(1); opacity: 1; }
  100% { transform: scaleX(1); opacity: 0; }
}

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