AI CSS Animations

Glass Search Bar

A frosted pill search field that widens on hover or focus, hides its shortcut hint and drops a glass list of suggestions with a stagger. Real input, :focus-within, no script.

Also known as: glassmorphism search bar css, frosted search input css, expanding search bar.

HTML

<div class="gls-glass-search-bar">
  <span class="gls-glass-search-bar-orb gls-glass-search-bar-orb-a" aria-hidden="true"></span>
  <span class="gls-glass-search-bar-orb gls-glass-search-bar-orb-b" aria-hidden="true"></span>
  <p class="gls-glass-search-bar-hint" aria-hidden="true">Find a<br>component</p>
  <div class="gls-glass-search-bar-box">
    <label class="gls-glass-search-bar-field">
      <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" aria-hidden="true"><circle cx="11" cy="11" r="6.5"/><path d="M16 16l4.5 4.5"/></svg>
      <input type="search" placeholder="Search components" aria-label="Search components">
      <kbd>⌘K</kbd>
    </label>
    <ul class="gls-glass-search-bar-list">
      <li><span>#</span>Glass navbar</li>
      <li><span>#</span>Liquid glass button</li>
      <li><span>#</span>Frosted login form</li>
    </ul>
  </div>
</div>

CSS

.gls-glass-search-bar {
  --c: var(--gls-color, #3b82f6);
  font-size: var(--gls-size, 16px);
  position: relative;
  display: grid;
  justify-items: center;
  align-content: start;
  width: 22em;
  height: 12em;
  border-radius: 1.25em;
  overflow: hidden;
  isolation: isolate;
  background: linear-gradient(150deg, color-mix(in srgb, var(--c) 45%, #0f172a), color-mix(in srgb, var(--c) 25%, #4c1d95));
  color: #fff;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.3;
}
.gls-glass-search-bar-orb {
  position: absolute;
  z-index: -1;
  border-radius: 50%;
}
.gls-glass-search-bar-orb-a {
  left: 2.5em;
  top: 3em;
  width: 6.5em;
  height: 6.5em;
  background: linear-gradient(135deg, color-mix(in srgb, var(--c) 40%, #fff), var(--c));
  animation: gls-glass-search-bar-orb 7s ease-in-out infinite alternate;
}
.gls-glass-search-bar-orb-b {
  right: 1.5em;
  top: 3.8em;
  width: 5em;
  height: 5em;
  background: linear-gradient(135deg, #fde68a, #f472b6);
  animation: gls-glass-search-bar-orb 8s ease-in-out -4s infinite alternate-reverse;
}
.gls-glass-search-bar-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 1.1em;
  margin: 0;
  font-size: 1.9em;
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.03em;
  text-align: center;
  color: rgb(255 255 255 / 0.9);
}
.gls-glass-search-bar-box {
  position: relative;
  display: grid;
  justify-items: center;
  margin-top: 1.3em;
}
.gls-glass-search-bar-field {
  display: flex;
  align-items: center;
  gap: 0.55em;
  width: 13.5em;
  height: 2.5em;
  padding: 0 0.5em 0 0.9em;
  border-radius: 99em;
  background: color-mix(in srgb, #fff 16%, transparent);
  -webkit-backdrop-filter: blur(0.9em) saturate(1.5);
  backdrop-filter: blur(0.9em) saturate(1.5);
  border: 1px solid color-mix(in srgb, #fff 45%, transparent);
  box-shadow: 0 0.5em 1.5em -0.5em rgb(0 0 0 / 0.35), inset 0 1px 0 color-mix(in srgb, #fff 55%, transparent);
  cursor: text;
  transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1), background-color 0.3s ease, box-shadow 0.3s ease;
}
.gls-glass-search-bar-field svg { flex: none; width: 0.95em; height: 0.95em; }
.gls-glass-search-bar-field input {
  flex: 1;
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: #fff;
  font: inherit;
  font-size: 0.8em;
}
.gls-glass-search-bar-field input::placeholder { color: rgb(255 255 255 / 0.72); }
.gls-glass-search-bar-field input::-webkit-search-cancel-button { display: none; }
.gls-glass-search-bar-field kbd {
  flex: none;
  padding: 0.3em 0.5em;
  border-radius: 99em;
  background: rgb(255 255 255 / 0.18);
  font: 600 0.6em/1 system-ui, sans-serif;
  transition: opacity 0.25s ease;
}
.gls-glass-search-bar-box:is(:hover, :focus-within) .gls-glass-search-bar-field {
  width: 17em;
  background-color: rgb(255 255 255 / 0.24);
  box-shadow: 0 0 0 0.2em rgb(255 255 255 / 0.18), 0 0.8em 1.8em -0.6em rgb(0 0 0 / 0.45), inset 0 1px 0 rgb(255 255 255 / 0.6);
}
.gls-glass-search-bar-box:focus-within kbd { opacity: 0; }
.gls-glass-search-bar-list {
  position: absolute;
  top: calc(100% + 0.45em);
  display: grid;
  width: 17em;
  margin: 0;
  padding: 0.35em;
  border-radius: 1em;
  list-style: none;
  background: color-mix(in srgb, #fff 16%, transparent);
  -webkit-backdrop-filter: blur(0.9em) saturate(1.5);
  backdrop-filter: blur(0.9em) saturate(1.5);
  border: 1px solid color-mix(in srgb, #fff 45%, transparent);
  box-shadow: 0 0.5em 1.5em -0.5em rgb(0 0 0 / 0.35), inset 0 1px 0 color-mix(in srgb, #fff 55%, transparent);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-0.4em) scale(0.97);
  transform-origin: top;
  transition: opacity 0.3s ease, transform 0.4s cubic-bezier(0.22, 1, 0.36, 1), visibility 0s 0.3s;
}
.gls-glass-search-bar-box:is(:hover, :focus-within) .gls-glass-search-bar-list {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition-delay: 0.1s, 0.1s, 0s;
}
.gls-glass-search-bar-list li {
  display: flex;
  align-items: center;
  gap: 0.6em;
  padding: 0.55em 0.6em;
  border-radius: 0.65em;
  font-size: 0.72em;
  opacity: 0;
  transform: translateY(-0.3em);
  transition: opacity 0.3s ease, transform 0.3s ease, background-color 0.2s ease;
}
.gls-glass-search-bar-box:is(:hover, :focus-within) .gls-glass-search-bar-list li { opacity: 1; transform: none; }
.gls-glass-search-bar-box:is(:hover, :focus-within) .gls-glass-search-bar-list li:nth-child(1) { transition-delay: 0.15s; }
.gls-glass-search-bar-box:is(:hover, :focus-within) .gls-glass-search-bar-list li:nth-child(2) { transition-delay: 0.22s; }
.gls-glass-search-bar-box:is(:hover, :focus-within) .gls-glass-search-bar-list li:nth-child(3) { transition-delay: 0.29s; }
.gls-glass-search-bar-list li:hover { background: rgb(255 255 255 / 0.18); }
.gls-glass-search-bar-list span {
  display: grid;
  place-items: center;
  width: 1.6em;
  height: 1.6em;
  border-radius: 0.45em;
  background: rgb(255 255 255 / 0.2);
  font-weight: 700;
}
@keyframes gls-glass-search-bar-orb {
  to { transform: translate(2.5em, 1em) scale(1.1); }
}

@media (prefers-reduced-motion: reduce) {
  .gls-glass-search-bar, .gls-glass-search-bar *, .gls-glass-search-bar::before, .gls-glass-search-bar::after, .gls-glass-search-bar *::before, .gls-glass-search-bar *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Customizing this snippet

  • Color: set --gls-color on the element or a parent. Currently previewing #3b82f6.
  • Base size: set --gls-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 16px.
  • 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 glass effects