36 CSS Search Bars
19 / 36

All 36 in 36 CSS Search Bars

  1. 01Command Palette Cmd+K Search Bar
  2. 02Algolia-Style Instant Search with Highlighted Results Dropdown
  3. 03E-Commerce Product Search Bar with Category Scope Dropdown
  4. 04Header Navbar Integrated Sticky Search Bar
  5. 05SaaS Dashboard Command Search with Recent and Suggested
  6. 06Minimal CSS Search Bar with Animated Underline
  7. 07CSS Rounded Pill Search Bar with Submit Button
  8. 08Glassmorphism CSS Search Bar (Backdrop Blur)
  9. 09Neon Glow CSS Search Bar (Cyberpunk)
  10. 10CSS Search Bar with Animated Caret Highlight
  11. 11CSS Search Bar with Voice Input Microphone Button
  12. 12CSS Search Bar with Loading Spinner Indicator
  13. 13CSS Search Bar with Clear Button (X on Type)
  14. 14Animated Expanding CSS Search Bar on Focus
  15. 15CSS Search Bar with Autocomplete Suggestions Dropdown
  16. 16CSS Search Bar with Keyboard Shortcut Hint (Cmd K / Ctrl K)
  17. 17CSS Search Bar with Filter Chip Tags
  18. 18CSS Search Bar with Recent Searches Dropdown
  19. 19CSS Search Bar with Rotating Placeholder Text
  20. 20CSS People Search Bar with Avatar Chips
  21. 21Neo-Brutalist CSS Search Bar with Offset Stamp
  22. 22Compact Toolbar CSS Search Bar (Docs / Wiki)
  23. 23Hero Section CSS Search Bar with CTA
  24. 24CSS Search Bar with Side Category Indicator
  25. 25Floating CSS Search Bar with Drop Shadow (Elevated)
  26. 26CSS Search + Filter Sidebar Combo Bar
  27. 27CSS Search Bar with Inline Loading Progress Bar
  28. 28CSS Search Bar with Dual-Tone Border Outline
  29. 29CSS Glitch Search Bar with RGB Split Effect
  30. 30Mobile-First Compact CSS Search Bar
  31. 31CSS Search Bar with Focus Ring Bloom Animation
  32. 32CSS Search Bar Combo with Scope Selector
  33. 33CSS Search Bar with Inset Pressed 3D Effect
  34. 34CSS Search Bar with Animated Border Trace
  35. 35Floating Card CSS Search Bar (Modal Style)
  36. 36Aurora Gradient CSS Search Bar
Pure CSSMIT licensed

CSS Search Bar with Rotating Placeholder Text

The placeholder cycles through four real example queries — wireless headphones, invoice template, Q3 revenue, team photo — on a stacked-keyframe rotator with a blinking type cursor. It disappears the instant you type, and it is 100% CSS: the real placeholder attribute stays empty-but-present so :placeholder-shown still works.

Live Demo
Try it

Nucleo: 44,000+ SVG icons in five families · All Icons Bundle $149

Nucleo · Affiliate link

Get the Nucleo bundle

The code

<div class="sb-19">
  <button class="sb-19__theme" type="button" aria-pressed="false" aria-label="Switch to dark theme">
    <svg class="sb-19__moon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M20 14.2A8.2 8.2 0 0 1 9.8 4 8.4 8.4 0 1 0 20 14.2"/></svg>
    <svg class="sb-19__sun" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><circle cx="12" cy="12" r="4"/><path d="M12 3.4v2M12 18.6v2M3.4 12h2M18.6 12h2M6 6l1.4 1.4M16.6 16.6 18 18M18 6l-1.4 1.4M7.4 16.6 6 18"/></svg>
  </button>
  <div class="sb-19__stage">
    <div class="sb-19__bar" role="search">
      <svg class="sb-19__ico" viewBox="0 0 24 24" fill="none" aria-hidden="true" focusable="false"><circle cx="11" cy="11" r="6.4" stroke="currentColor" stroke-width="1.8"/><path d="m16 16 4.2 4.2" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/></svg>
      <span class="sb-19__box">
        <label class="sb-19__vh" for="sb-19-input">Search products, documents and people</label>
        <input class="sb-19__input" id="sb-19-input" type="search" placeholder=" " autocomplete="off">
        <span class="sb-19__rot" aria-hidden="true">
          <span>Search &ldquo;wireless headphones&rdquo;</span>
          <span>Search &ldquo;invoice template&rdquo;</span>
          <span>Search &ldquo;Q3 revenue&rdquo;</span>
          <span>Search &ldquo;team photo&rdquo;</span>
          <i class="sb-19__caret"></i>
        </span>
      </span>
      <kbd class="sb-19__kbd">/</kbd>
    </div>
  </div>
</div>
.sb-19 {
  --bg: #f7f7f9;
  --card: #ffffff;
  --ink: #16181d;
  --muted: #71767f;
  --line: #e5e6ea;
  --acc: #111318;
  --ring: #4f46e5;
  --shadow: rgba(22,24,29,.14);
  width: 100%;
  min-height: 100vh;
  min-height: 100svh;
  display: block;
  box-sizing: border-box;
  font-family: system-ui,-apple-system,"Segoe UI",sans-serif;
  color: var(--ink);
  background: radial-gradient(36rem 20rem at 50% 10%, #fff, var(--bg) 76%);
  -webkit-font-smoothing: antialiased;
}

.sb-19 *,
.sb-19 *::before,
.sb-19 *::after {
  box-sizing: border-box;
}

.sb-19__stage {
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: clamp(1rem,4vw,3rem);
}

.sb-19__vh {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.sb-19__bar {
  display: flex;
  align-items: center;
  gap: .75rem;
  inline-size: min(30rem,100%);
  min-block-size: 56px;
  padding-inline: 1.05rem .5rem;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--card);
  box-shadow: 0 1px 2px rgba(22,24,29,.05);
  transition: border-color .2s, box-shadow .2s;
}

.sb-19__bar:focus-within {
  border-color: var(--acc);
  box-shadow: 0 0 0 4px rgba(17,19,24,.08);
}

.sb-19__ico {
  inline-size: 19px;
  block-size: 19px;
  flex: none;
  color: var(--muted);
}

.sb-19__box {
  position: relative;
  flex: 1;
  min-inline-size: 0;
  display: flex;
  align-items: center;
}

.sb-19__input {
  position: relative;
  z-index: 2;
  inline-size: 100%;
  border: 0;
  background: none;
  color: var(--ink);
  font: 400 .97rem/1.2 inherit;
}

.sb-19__input:focus {
  outline: none;
}

.sb-19__input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

.sb-19__rot {
  position: absolute;
  inset-block: 0;
  inset-inline: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  pointer-events: none;
  color: var(--muted);
  font: 400 .97rem/1.2 inherit;
  overflow: hidden;
  transition: opacity .18s;
}

.sb-19__rot span {
  position: absolute;
  inset-inline-start: 0;
  white-space: nowrap;
  opacity: 0;
  animation: sb-19-cycle 12s cubic-bezier(.2,.9,.25,1) infinite;
}

.sb-19__rot span:nth-child(2) {
  animation-delay: 3s;
}

.sb-19__rot span:nth-child(3) {
  animation-delay: 6s;
}

.sb-19__rot span:nth-child(4) {
  animation-delay: 9s;
}

@keyframes sb-19-cycle {
  0%,
    2% {
    opacity: 0;
    -webkit-transform: translateY(6px);
    transform: translateY(6px);
    translate: 0 6px;
  }

  6%,
    22% {
    opacity: 1;
    -webkit-transform: none;
    transform: none;
    translate: 0 0;
  }

  27%,
    100% {
    opacity: 0;
    -webkit-transform: translateY(-6px);
    transform: translateY(-6px);
    translate: 0 -6px;
  }
}

.sb-19__caret {
  position: absolute;
  inset-inline-start: 0;
  inline-size: 1.5px;
  block-size: 1.15em;
  background: var(--acc);
  opacity: .55;
  animation: sb-19-blink 1s steps(1,end) infinite;
  margin-inline-start: -.35rem;
}

@keyframes sb-19-blink {
  0%,
    49% {
    opacity: .55;
  }

  50%,
    100% {
    opacity: 0;
  }
}

.sb-19__input:not(:placeholder-shown) ~ .sb-19__rot {
  opacity: 0;
}

.sb-19__kbd {
  display: inline-grid;
  place-items: center;
  inline-size: 1.9rem;
  block-size: 1.9rem;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbfc;
  color: var(--muted);
  font: 500 .82rem/1 ui-monospace,Menlo,monospace;
}

.sb-19 :focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

.sb-19__input:focus-visible {
  outline: none;
}

.sb-19[data-theme="dark"] {
  --bg: #0b0c10;
  --card: #141720;
  --ink: #eceef4;
  --muted: #878d99;
  --line: #232833;
  --acc: #eceef4;
  --ring: #8b83ff;
  --shadow: rgba(0,0,0,.7);
  background: radial-gradient(36rem 20rem at 50% 10%, #171b26, var(--bg) 76%);
}

.sb-19[data-theme="dark"] .sb-19__kbd {
  background: #1a1f2a;
}

.sb-19[data-theme="dark"] .sb-19__bar:focus-within {
  box-shadow: 0 0 0 4px rgba(236,238,244,.09);
}

@media (prefers-color-scheme: dark) {
  .sb-19:not([data-theme="light"]) {
    --bg: #0b0c10;
    --card: #141720;
    --ink: #eceef4;
    --muted: #878d99;
    --line: #232833;
    --acc: #eceef4;
    --ring: #8b83ff;
    --shadow: rgba(0,0,0,.7);
    background: radial-gradient(36rem 20rem at 50% 10%, #171b26, var(--bg) 76%);
  }

  .sb-19:not([data-theme="light"]) .sb-19__kbd {
    background: #1a1f2a;
  }

  .sb-19:not([data-theme="light"]) .sb-19__bar:focus-within {
    box-shadow: 0 0 0 4px rgba(236,238,244,.09);
  }
}

@media (prefers-reduced-motion: reduce) {
  .sb-19 *,
    .sb-19 *::before,
    .sb-19 *::after {
    animation: none !important;
    transition: none !important;
  }

  .sb-19__rot span {
    opacity: 0;
  }

  .sb-19__rot span:first-child {
    opacity: 1;
  }
}

@media (forced-colors: active) {
  .sb-19__bar,
    .sb-19__kbd {
    border: 1px solid CanvasText;
  }
}

.sb-19__theme {
  position: absolute;
  inset-block-start: clamp(.75rem,2vw,1.25rem);
  inset-inline-end: clamp(.75rem,2vw,1.25rem);
  z-index: 50;
  inline-size: 2.5rem;
  block-size: 2.5rem;
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
  border-radius: 999px;
  border: 1px solid rgba(0,0,0,.12);
  color: currentColor;
  background: rgba(255,255,255,.72);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transition: background .25s ease, transform .25s cubic-bezier(.16,1,.3,1), border-color .25s ease;
}

.sb-19[data-theme="dark"] .sb-19__theme {
  background: rgba(20,20,28,.72);
  border-color: rgba(255,255,255,.15);
  color: #fff;
}

@media (prefers-color-scheme: dark) {
  .sb-19:not([data-theme="light"]) .sb-19__theme {
    background: rgba(20,20,28,.72);
    border-color: rgba(255,255,255,.15);
    color: #fff;
  }
}

.sb-19__theme:hover {
  transform: translateY(-1px);
  border-color: rgba(0,0,0,.24);
}

.sb-19[data-theme="dark"] .sb-19__theme:hover,
.sb-19:not([data-theme="light"]) .sb-19__theme:hover {
  border-color: rgba(255,255,255,.3);
}

.sb-19__theme:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 3px;
}

.sb-19__theme svg {
  grid-area: 1/1;
  inline-size: 1.1rem;
  block-size: 1.1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sb-19__sun {
  display: none;
}

.sb-19__theme[aria-pressed="true"] .sb-19__sun {
  display: block;
}

.sb-19__theme[aria-pressed="true"] .sb-19__moon {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .sb-19__theme {
    transition: none;
  }

  .sb-19__theme:hover {
    transform: none;
  }
}
(()=>{const r=document.querySelector('.sb-19');if(!r)return;const t=r.querySelector('.sb-19__theme');if(!t)return;const dark=()=>(r.dataset.theme||(matchMedia('(prefers-color-scheme: dark)').matches?'dark':'light'))==='dark';const sync=()=>{t.setAttribute('aria-pressed',String(dark()));t.setAttribute('aria-label',dark()?'Switch to light theme':'Switch to dark theme');};t.addEventListener('click',()=>{r.dataset.theme=dark()?'light':'dark';sync();});matchMedia('(prefers-color-scheme: dark)').addEventListener('change',()=>{if(!r.dataset.theme)sync();});sync();})();
Paste this into ChatGPT, Claude, Cursor, or any coding assistant. The block below is pre-framed with everything the AI needs to integrate this demo into your project — markup, styles, scoping notes, and the source URL. Hit Copy and paste straight into your chat.
Here's a working CSS Search Bar from CodeFronts. Use it as-is or adapt to your framework. All classes are scoped under a unique prefix so the code won't collide with your existing styles. MIT licensed.
Demo: CSS Search Bar with Rotating Placeholder Text
Source: https://codefronts.com/components/css-search-boxes/animated-placeholder/

The placeholder cycles through four real example queries — wireless headphones, invoice template, Q3 revenue, team photo — on a stacked-keyframe rotator with a blinking type cursor. It disappears the instant you type, and it is 100% CSS: the real placeholder attribute stays empty-but-present so :placeholder-shown still works.
## HTML
```html
<div class="sb-19">
  <button class="sb-19__theme" type="button" aria-pressed="false" aria-label="Switch to dark theme">
    <svg class="sb-19__moon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M20 14.2A8.2 8.2 0 0 1 9.8 4 8.4 8.4 0 1 0 20 14.2"/></svg>
    <svg class="sb-19__sun" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><circle cx="12" cy="12" r="4"/><path d="M12 3.4v2M12 18.6v2M3.4 12h2M18.6 12h2M6 6l1.4 1.4M16.6 16.6 18 18M18 6l-1.4 1.4M7.4 16.6 6 18"/></svg>
  </button>
  <div class="sb-19__stage">
    <div class="sb-19__bar" role="search">
      <svg class="sb-19__ico" viewBox="0 0 24 24" fill="none" aria-hidden="true" focusable="false"><circle cx="11" cy="11" r="6.4" stroke="currentColor" stroke-width="1.8"/><path d="m16 16 4.2 4.2" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/></svg>
      <span class="sb-19__box">
        <label class="sb-19__vh" for="sb-19-input">Search products, documents and people</label>
        <input class="sb-19__input" id="sb-19-input" type="search" placeholder=" " autocomplete="off">
        <span class="sb-19__rot" aria-hidden="true">
          <span>Search &ldquo;wireless headphones&rdquo;</span>
          <span>Search &ldquo;invoice template&rdquo;</span>
          <span>Search &ldquo;Q3 revenue&rdquo;</span>
          <span>Search &ldquo;team photo&rdquo;</span>
          <i class="sb-19__caret"></i>
        </span>
      </span>
      <kbd class="sb-19__kbd">/</kbd>
    </div>
  </div>
</div>
```
## CSS
```css
.sb-19 {
  --bg: #f7f7f9;
  --card: #ffffff;
  --ink: #16181d;
  --muted: #71767f;
  --line: #e5e6ea;
  --acc: #111318;
  --ring: #4f46e5;
  --shadow: rgba(22,24,29,.14);
  width: 100%;
  min-height: 100vh;
  min-height: 100svh;
  display: block;
  box-sizing: border-box;
  font-family: system-ui,-apple-system,"Segoe UI",sans-serif;
  color: var(--ink);
  background: radial-gradient(36rem 20rem at 50% 10%, #fff, var(--bg) 76%);
  -webkit-font-smoothing: antialiased;
}

.sb-19 *,
.sb-19 *::before,
.sb-19 *::after {
  box-sizing: border-box;
}

.sb-19__stage {
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: clamp(1rem,4vw,3rem);
}

.sb-19__vh {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.sb-19__bar {
  display: flex;
  align-items: center;
  gap: .75rem;
  inline-size: min(30rem,100%);
  min-block-size: 56px;
  padding-inline: 1.05rem .5rem;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--card);
  box-shadow: 0 1px 2px rgba(22,24,29,.05);
  transition: border-color .2s, box-shadow .2s;
}

.sb-19__bar:focus-within {
  border-color: var(--acc);
  box-shadow: 0 0 0 4px rgba(17,19,24,.08);
}

.sb-19__ico {
  inline-size: 19px;
  block-size: 19px;
  flex: none;
  color: var(--muted);
}

.sb-19__box {
  position: relative;
  flex: 1;
  min-inline-size: 0;
  display: flex;
  align-items: center;
}

.sb-19__input {
  position: relative;
  z-index: 2;
  inline-size: 100%;
  border: 0;
  background: none;
  color: var(--ink);
  font: 400 .97rem/1.2 inherit;
}

.sb-19__input:focus {
  outline: none;
}

.sb-19__input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

.sb-19__rot {
  position: absolute;
  inset-block: 0;
  inset-inline: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  pointer-events: none;
  color: var(--muted);
  font: 400 .97rem/1.2 inherit;
  overflow: hidden;
  transition: opacity .18s;
}

.sb-19__rot span {
  position: absolute;
  inset-inline-start: 0;
  white-space: nowrap;
  opacity: 0;
  animation: sb-19-cycle 12s cubic-bezier(.2,.9,.25,1) infinite;
}

.sb-19__rot span:nth-child(2) {
  animation-delay: 3s;
}

.sb-19__rot span:nth-child(3) {
  animation-delay: 6s;
}

.sb-19__rot span:nth-child(4) {
  animation-delay: 9s;
}

@keyframes sb-19-cycle {
  0%,
    2% {
    opacity: 0;
    -webkit-transform: translateY(6px);
    transform: translateY(6px);
    translate: 0 6px;
  }

  6%,
    22% {
    opacity: 1;
    -webkit-transform: none;
    transform: none;
    translate: 0 0;
  }

  27%,
    100% {
    opacity: 0;
    -webkit-transform: translateY(-6px);
    transform: translateY(-6px);
    translate: 0 -6px;
  }
}

.sb-19__caret {
  position: absolute;
  inset-inline-start: 0;
  inline-size: 1.5px;
  block-size: 1.15em;
  background: var(--acc);
  opacity: .55;
  animation: sb-19-blink 1s steps(1,end) infinite;
  margin-inline-start: -.35rem;
}

@keyframes sb-19-blink {
  0%,
    49% {
    opacity: .55;
  }

  50%,
    100% {
    opacity: 0;
  }
}

.sb-19__input:not(:placeholder-shown) ~ .sb-19__rot {
  opacity: 0;
}

.sb-19__kbd {
  display: inline-grid;
  place-items: center;
  inline-size: 1.9rem;
  block-size: 1.9rem;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbfc;
  color: var(--muted);
  font: 500 .82rem/1 ui-monospace,Menlo,monospace;
}

.sb-19 :focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

.sb-19__input:focus-visible {
  outline: none;
}

.sb-19[data-theme="dark"] {
  --bg: #0b0c10;
  --card: #141720;
  --ink: #eceef4;
  --muted: #878d99;
  --line: #232833;
  --acc: #eceef4;
  --ring: #8b83ff;
  --shadow: rgba(0,0,0,.7);
  background: radial-gradient(36rem 20rem at 50% 10%, #171b26, var(--bg) 76%);
}

.sb-19[data-theme="dark"] .sb-19__kbd {
  background: #1a1f2a;
}

.sb-19[data-theme="dark"] .sb-19__bar:focus-within {
  box-shadow: 0 0 0 4px rgba(236,238,244,.09);
}

@media (prefers-color-scheme: dark) {
  .sb-19:not([data-theme="light"]) {
    --bg: #0b0c10;
    --card: #141720;
    --ink: #eceef4;
    --muted: #878d99;
    --line: #232833;
    --acc: #eceef4;
    --ring: #8b83ff;
    --shadow: rgba(0,0,0,.7);
    background: radial-gradient(36rem 20rem at 50% 10%, #171b26, var(--bg) 76%);
  }

  .sb-19:not([data-theme="light"]) .sb-19__kbd {
    background: #1a1f2a;
  }

  .sb-19:not([data-theme="light"]) .sb-19__bar:focus-within {
    box-shadow: 0 0 0 4px rgba(236,238,244,.09);
  }
}

@media (prefers-reduced-motion: reduce) {
  .sb-19 *,
    .sb-19 *::before,
    .sb-19 *::after {
    animation: none !important;
    transition: none !important;
  }

  .sb-19__rot span {
    opacity: 0;
  }

  .sb-19__rot span:first-child {
    opacity: 1;
  }
}

@media (forced-colors: active) {
  .sb-19__bar,
    .sb-19__kbd {
    border: 1px solid CanvasText;
  }
}

.sb-19__theme {
  position: absolute;
  inset-block-start: clamp(.75rem,2vw,1.25rem);
  inset-inline-end: clamp(.75rem,2vw,1.25rem);
  z-index: 50;
  inline-size: 2.5rem;
  block-size: 2.5rem;
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
  border-radius: 999px;
  border: 1px solid rgba(0,0,0,.12);
  color: currentColor;
  background: rgba(255,255,255,.72);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transition: background .25s ease, transform .25s cubic-bezier(.16,1,.3,1), border-color .25s ease;
}

.sb-19[data-theme="dark"] .sb-19__theme {
  background: rgba(20,20,28,.72);
  border-color: rgba(255,255,255,.15);
  color: #fff;
}

@media (prefers-color-scheme: dark) {
  .sb-19:not([data-theme="light"]) .sb-19__theme {
    background: rgba(20,20,28,.72);
    border-color: rgba(255,255,255,.15);
    color: #fff;
  }
}

.sb-19__theme:hover {
  transform: translateY(-1px);
  border-color: rgba(0,0,0,.24);
}

.sb-19[data-theme="dark"] .sb-19__theme:hover,
.sb-19:not([data-theme="light"]) .sb-19__theme:hover {
  border-color: rgba(255,255,255,.3);
}

.sb-19__theme:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 3px;
}

.sb-19__theme svg {
  grid-area: 1/1;
  inline-size: 1.1rem;
  block-size: 1.1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sb-19__sun {
  display: none;
}

.sb-19__theme[aria-pressed="true"] .sb-19__sun {
  display: block;
}

.sb-19__theme[aria-pressed="true"] .sb-19__moon {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .sb-19__theme {
    transition: none;
  }

  .sb-19__theme:hover {
    transform: none;
  }
}
```

## JavaScript
```js
(()=>{const r=document.querySelector('.sb-19');if(!r)return;const t=r.querySelector('.sb-19__theme');if(!t)return;const dark=()=>(r.dataset.theme||(matchMedia('(prefers-color-scheme: dark)').matches?'dark':'light'))==='dark';const sync=()=>{t.setAttribute('aria-pressed',String(dark()));t.setAttribute('aria-label',dark()?'Switch to light theme':'Switch to dark theme');};t.addEventListener('click',()=>{r.dataset.theme=dark()?'light':'dark';sync();});matchMedia('(prefers-color-scheme: dark)').addEventListener('change',()=>{if(!r.dataset.theme)sync();});sync();})();
```

How this works

Why not animate the real placeholder? You cannot: ::placeholder can be styled, but its content comes from an attribute and CSS cannot rewrite it. So the real placeholder is a single space (keeping :placeholder-shown truthful) and the visible text is a stack of spans:

.sb-19__rot span{
  position:absolute; inset-inline-start:0; opacity:0;
  animation:sb-19-cycle 12s infinite;         /* 4 items x 3s each */
}
.sb-19__rot span:nth-child(2){animation-delay:3s;}
.sb-19__rot span:nth-child(3){animation-delay:6s;}
.sb-19__rot span:nth-child(4){animation-delay:9s;}
@keyframes sb-19-cycle{
  0%,2%{opacity:0; translate:0 6px;}
  6%,22%{opacity:1; translate:0 0;}          /* visible slice */
  27%,100%{opacity:0; translate:0 -6px;}
}

Each item is on screen for 25% of a 12s loop with a short cross-fade — the percentages are the entire technique.

Hiding on input. .sb-19__input:not(:placeholder-shown) ~ .sb-19__rot{opacity:0}. Because the input's own placeholder is a space, the pseudo-class flips exactly when the user types.

The caret bar after the text is a 1px span on a 1s square-wave blink, which sells the "someone is typing this" illusion without a typewriter keyframe per string.

Make it yours

  • Add or remove queries by editing the spans and the delay stops: delay = index × (duration &divide; count), and each item's visible slice is 100 &divide; count percent.
  • Slow it down for long queries — under 2.5s per item people cannot finish reading.
  • For a true typewriter, swap the fade for a clip-path: inset(0 100% 0 0) reveal per item (still no JS, but four keyframe blocks).
  • Match your product's real top searches; rotating fake queries is a missed conversion opportunity.

Gotchas — read before shipping

  • Never put required information in a rotating placeholder — it is invisible to anyone who arrives mid-cycle, and a placeholder is not a label.
  • Keep placeholder=" " (a space) rather than removing it, or :placeholder-shown stops matching and the rotator never hides.
  • The fake text must be aria-hidden and pointer-events:none; otherwise screen readers read four overlapping strings and clicks miss the field.
  • Motion in a text field is genuinely distracting for some users — the reduced-motion block here freezes it on the first item, which is the accessible default.

Browser support

ChromeSafariFirefoxEdge
104+14.1+72+104+

Everything is baseline CSS animation; individual translate property (Chrome 104 / Safari 14.1 / Firefox 72) has a transform fallback declared first. :placeholder-shown is universal in modern browsers.

Techniques used in this demo

Search CodeFronts

Loading…