Skip to content

176 web animation techniques, each a live demo with plain settings and a ready-made prompt for your AI assistant. No dependencies, no build step.

feat: Expanding Search (04.37)

matinc681f0fed904
diff --git a/README.md b/README.md
index cfb2a241..b862b9fc 100644
--- a/README.md
+++ b/README.md
@@ -156,6 +156,7 @@ All 129 techniques, each linked to its live demo.
- **[Segmented Control](animations/04-micro-interactions/segmented-control/)** — A highlight slides to the option you pick. Best for switching views.
- **[Pull to Refresh](animations/04-micro-interactions/pull-to-refresh/)** — Pulling a list down shows a spinner, then new items. Best for feeds.
- **[Hold to Confirm](animations/04-micro-interactions/hold-to-confirm/)** — Fills up while you hold it and acts only once it is full. Best for delete buttons.
+- **[Expanding Search](animations/04-micro-interactions/expanding-search/)** — A search icon opens into a field you can type in, and closes when done. Best for toolbars.
</details>
diff --git a/animations/04-micro-interactions/README.md b/animations/04-micro-interactions/README.md
index 058a265d..3089fb52 100644
--- a/animations/04-micro-interactions/README.md
+++ b/animations/04-micro-interactions/README.md
@@ -36,6 +36,7 @@ Short, user-triggered animations that provide feedback, confirm actions, and com
| [Segmented Control](segmented-control/) | A highlight slides to the option you pick. Best for switching views. |
| [Pull to Refresh](pull-to-refresh/) | Pulling a list down shows a spinner, then new items. Best for feeds. |
| [Hold to Confirm](hold-to-confirm/) | Fills up while you hold it and acts only once it is full. Best for delete buttons. |
+| [Expanding Search](expanding-search/) | A search icon opens into a field you can type in, and closes when done. Best for toolbars. |
## Key concepts
diff --git a/animations/04-micro-interactions/expanding-search/README.md b/animations/04-micro-interactions/expanding-search/README.md
new file mode 100644
index 00000000..b1e644d3
--- /dev/null
+++ b/animations/04-micro-interactions/expanding-search/README.md
@@ -0,0 +1,66 @@
+# Expanding Search
+
+## What it is
+An expanding search shows only a search icon until it is needed. Pressing the icon opens a search field out of it, over the links beside it, and puts the cursor inside; Escape, the close button or clicking away closes it again. It saves room in a busy toolbar while keeping search one press away.
+
+## When to use it
+- Toolbars and headers that are short on room
+- Mobile headers, where a full search box would crowd the logo and the menu
+- Documentation and help sites, where search is used now and then
+- Dashboards and admin tools with many controls in one bar
+
+## How it works
+The field is laid out at its full size from the start and never changes size. A `clip-path` with rounded corners hides all of it except a 44px circle over the icon; opening animates the clip until the whole field shows, starting from the icon's side, so nothing beside it is laid out again. `visibility` follows the clip: it turns on at once when the field opens, and only after the closing clip has ended when it closes, so a closed field can be neither clicked nor reached with Tab.
+
+```css
+.sfield {
+ position: absolute; inset: 0; /* full size, over the links */
+ visibility: hidden;
+ clip-path: inset(0 0 0 calc(100% - 44px) round 22px); /* just the circle over the icon at the right end */
+ transition: clip-path 280ms cubic-bezier(.22, 1, .36, 1), visibility 0s linear 280ms;
+}
+.to-right .sfield { clip-path: inset(0 calc(100% - 44px) 0 0 round 22px); } /* the icon at the left end */
+.bar.open .sfield {
+ visibility: visible;
+ clip-path: inset(0 round 22px); /* all of it */
+ transition: clip-path 280ms cubic-bezier(.22, 1, .36, 1), visibility 0s;
+}
+```
+
+```js
+function open() { bar.classList.add('open'); icon.setAttribute('aria-expanded', 'true'); icon.inert = true; input.focus(); }
+function close(focusIcon) {
+ bar.classList.remove('open'); icon.setAttribute('aria-expanded', 'false'); icon.inert = false;
+ if (focusIcon) icon.focus(); // after Escape or the close button
+}
+icon.addEventListener('click', open);
+closeButton.addEventListener('click', () => close(true));
+field.addEventListener('keydown', e => { if (e.key === 'Escape') close(true); });
+field.addEventListener('focusout', e => { // leaving it: the focus went somewhere outside the field
+ if (closesOnLeave && !field.contains(e.relatedTarget)) close(false);
+});
+```
+
+The icon stays on top of the field. As the field opens, the icon's background turns see-through and its glass turns and fades away while the close button's cross turns in under it, so one seems to become the other; the links under the field fade out. While the field is open the icon lets presses through and is `inert`, so Tab cannot land on something hidden, and the field shows its focus with an inset ring while anything inside it has the focus. Show me opens the field and types into it without moving the real focus, so it never opens a phone's keyboard. Under reduced motion the transitions are switched off and the field opens and closes at once.
+
+## Key parameters
+| Parameter | Default | Effect |
+|-----------|---------|--------|
+| Opens toward | Left | Left puts the icon at the right end of the toolbar and grows the field leftward over the links; Right puts the icon beside the logo and grows the field rightward |
+| Speed | Normal | How long the field takes to open or close: slow is 450ms, normal 280ms and fast 160ms; much slower and typing has to wait for it |
+| Closes when you leave it | On | On closes the field as soon as the focus moves away, by a click elsewhere or Tab; off keeps it open until Escape or the close button |
+
+## Production notes
+- **Never animate the width**: a growing `width` makes the browser lay out the whole toolbar again on every frame, so the items beside it jitter and slower phones drop frames. A clip (or a `scaleX()` background layer with the text faded in after it) only repaints the field.
+- **Phones**: iOS Safari zooms the page in on a field whose text is smaller than 16px, so the demo uses 16px on touch screens. On very narrow screens, consider opening the search as a bar over the whole header instead.
+- **Keep the keyboard's place**: give the focus back to the icon after Escape or the close button, keep the closed field out of the Tab order (`visibility: hidden` after the closing clip, or `inert`), and make the covered icon `inert` while the field is open.
+- **Names for screen readers**: the icon button needs a name ("Search") and `aria-expanded`, the field needs a label (visually hidden is fine), and its container `role="search"` or a `<form role="search">`.
+- **Text left behind**: decide what leaving a field that holds text does. The demo closes it and keeps the text for next time; some sites keep a field with text open.
+- **GSAP**: `gsap.fromTo(field, { clipPath: "inset(0% 0% 0% 90% round 22px)" }, { clipPath: "inset(0% 0% 0% 0% round 22px)", duration: 0.28, ease: "power3.out" })`; keep the same units on both ends so the values can be blended.
+- **Framer Motion**: `<motion.div animate={{ clipPath: open ? "inset(0% 0% 0% 0% round 22px)" : "inset(0% 0% 0% 90% round 22px)" }} transition={{ duration: 0.28 }} />`.
+
+## See also
+- [Hamburger Menu Toggle](../hamburger-menu-toggle/) — an icon turns into an X as its menu opens
+- [Form Field Morph](../form-field-morph/) — a field's label moves out of the way as you type
+- [Focus Ring Animation](../focus-ring/) — a ring shows where the keyboard is
+- [Drawer / Panel Slide](../drawer-slide/) — a hidden panel slides in when it is needed
diff --git a/animations/04-micro-interactions/expanding-search/index.html b/animations/04-micro-interactions/expanding-search/index.html
new file mode 100644
index 00000000..5818231a
--- /dev/null
+++ b/animations/04-micro-interactions/expanding-search/index.html
@@ -0,0 +1,269 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>Expanding Search — Animation Handbook</title>
+ <meta name="description" content="A search icon opens into a field you can type in, and closes when done. Best for toolbars.">
+ <link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/expanding-search/">
+ <link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png">
+ <link rel="icon" type="image/svg+xml" href="../../../favicon.svg">
+ <link rel="apple-touch-icon" href="../../../apple-touch-icon.png">
+ <meta property="og:type" content="article">
+ <meta property="og:site_name" content="Animation Handbook">
+ <meta property="og:title" content="Expanding Search — Animation Handbook">
+ <meta property="og:description" content="A search icon opens into a field you can type in, and closes when done. Best for toolbars.">
+ <meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/expanding-search/">
+ <meta property="og:image" content="https://matinmonshizadeh.github.io/animation-handbook/og-image.png">
+ <meta name="twitter:card" content="summary_large_image">
+ <meta name="twitter:title" content="Expanding Search — Animation Handbook">
+ <meta name="twitter:description" content="A search icon opens into a field you can type in, and closes when done. Best for toolbars.">
+ <meta name="twitter:image" content="https://matinmonshizadeh.github.io/animation-handbook/og-image.png">
+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Expanding Search", "name": "Expanding Search", "description": "A search icon opens into a field you can type in, and closes when done. Best for toolbars.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/expanding-search/", "inLanguage": "en", "articleSection": "Micro-Interactions", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Micro-Interactions, Expanding Search"}</script>
+ <style>
+ :root{--ui-accent:#ff9d5c;--ui-bg:#111114;--ui-border:rgba(255,255,255,.09);--ui-text:#f4f4f2;--ui-dim:#adadb2;--ui-muted:#9a9aa2;--bar-bg:#16161b;--field:#232329;--dur:280ms;--ease:cubic-bezier(.22,1,.36,1)}
+ *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
+ .stage{display:flex;align-items:center;justify-content:center;padding:clamp(12px,3vw,24px);background:#0b0b0d}
+ /* A small app window: a toolbar with the search, and the page under it */
+ .app{width:100%;max-width:520px;border:1px solid var(--ui-border);border-radius:12px;background:var(--ui-bg);overflow:hidden}
+ .bar{display:flex;align-items:center;gap:12px;height:60px;padding:0 8px 0 16px;border-bottom:1px solid var(--ui-border);background:var(--bar-bg)}
+ .brand{flex:none;display:flex;align-items:center;gap:8px;font-size:16px;font-weight:800}
+ .brand i{width:18px;height:18px;border-radius:5px;background:var(--ui-accent)}
+ .tools{position:relative;flex:1;min-width:0;height:44px;display:flex;align-items:center}
+ .links{display:flex;min-width:0;overflow:hidden;transition:opacity var(--dur) var(--ease)}
+ .links span{padding:0 10px;font-size:14px;line-height:44px;color:var(--ui-dim);white-space:nowrap}
+ .bar.open .links{opacity:0}
+ /* The icon sits at the end the field grows from: the right end (Left), or first, beside the logo (Right) */
+ .sbtn{position:relative;z-index:1;order:2;margin-left:auto;flex:none;display:grid;place-items:center;width:44px;height:44px;border:0;border-radius:50%;background-color:var(--field);color:var(--ui-text);cursor:pointer;transition:background-color var(--dur) var(--ease)}
+ .to-right .sbtn{order:-1;margin:0 4px 0 0}
+ /* Open, the icon stays on top but turns see-through and lets presses through, while its glass turns away as the field's cross turns in */
+ .bar.open .sbtn{background-color:transparent;pointer-events:none}
+ .sbtn svg{transition:opacity var(--dur) var(--ease),transform var(--dur) var(--ease)}
+ .bar.open .sbtn svg{opacity:0;transform:rotate(90deg) scale(.6)}
+ .bar svg{width:18px;height:18px;fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}
+ /* The field is always full size. Closed, a clip shows only the 44px circle over the icon; open, the clip lets all of it
+ show. visibility waits for the closing clip to end, then takes the field out of reach of the mouse and the Tab key. */
+ .sfield{position:absolute;inset:0;display:flex;align-items:center;border-radius:22px;background:var(--field);visibility:hidden;
+ clip-path:inset(0 0 0 calc(100% - 44px) round 22px);transition:clip-path var(--dur) var(--ease),visibility 0s linear var(--dur)}
+ .to-right .sfield{clip-path:inset(0 calc(100% - 44px) 0 0 round 22px)}
+ .bar.open .sfield{visibility:visible;clip-path:inset(0 round 22px);transition:clip-path var(--dur) var(--ease),visibility 0s}
+ /* The field draws the focus ring for its text box, so the site ring (0,3,0 inside the stage) is switched off on the box */
+ .sfield:focus-within,.bar.is-demo .sfield{box-shadow:inset 0 0 0 2px var(--ui-accent)}
+ .hb-page .stage .sfield input:focus-visible{outline:none}
+ .glass{flex:none;display:grid;place-items:center;width:44px;color:var(--ui-muted)}
+ .sfield input{flex:1;min-width:0;height:100%;border:0;background:none;color:var(--ui-text);font:inherit;font-size:15px;outline:none;-webkit-appearance:none;appearance:none}
+ .sfield input::placeholder{color:var(--ui-muted);opacity:1}
+ .sfield input::-webkit-search-cancel-button{display:none}
+ .sclose{flex:none;display:grid;place-items:center;width:44px;height:44px;border:0;border-radius:50%;background:none;color:var(--ui-text);cursor:pointer;transition:background-color .15s}
+ .sclose svg{transition:opacity var(--dur) var(--ease),transform var(--dur) var(--ease)}
+ .bar:not(.open) .sclose svg{opacity:0;transform:rotate(-90deg) scale(.6)}
+ .sclose.hit{background:rgba(255,255,255,.12)}
+ @media(hover:hover){.sbtn:hover{background-color:#2c2c33}.sclose:hover{background:rgba(255,255,255,.08)}}
+ .page{display:flex;flex-direction:column;gap:10px;padding:22px 16px 26px}
+ .page b{width:45%;height:14px;border-radius:4px;background:#2a2a31}
+ .page i{height:9px;border-radius:3px;background:#1f1f25}
+ .sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
+ /* Phones: two links, and on the narrowest the logo without its name, so the open field has room for its text */
+ @media(max-width:420px){.links span:nth-child(3){display:none}}
+ @media(max-width:360px){.brand span{display:none}}
+ /* Phones zoom the page in on a field with type smaller than 16px */
+ @media(pointer:coarse){.sfield input{font-size:16px}}
+ @media(prefers-reduced-motion:reduce){.links,.sbtn,.sbtn svg,.sfield,.bar.open .sfield,.sclose,.sclose svg{transition:none!important}}
+ </style>
+ <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=6">
+ <script src="../../../assets/js/demo-page.js?v=6" defer></script>
+</head>
+<body class="hb" data-hb-kind="do" data-hb-autoplay>
+<nav class="hb-bar" aria-label="Animation Handbook">
+ <a class="hb-home" href="../../../"><svg class="hb-mark" viewBox="0 0 32 32" aria-hidden="true"><g class="g"><circle cx="11.16" cy="20.84" r="6.1"/><circle cx="15.12" cy="16.88" r="6.1"/><circle cx="18.51" cy="13.49" r="6.1"/></g><circle class="b" cx="21.2" cy="10.8" r="6.6"/></svg><span>Animation Handbook</span></a>
+ <span class="hb-pager"><a href="../hold-to-confirm/" rel="prev" aria-label="Previous: Hold to Confirm"><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m15 18-6-6 6-6"/></svg><span><span class="hb-dir">Previous: </span>Hold to Confirm</span></a></span>
+</nav>
+<main class="hb-page">
+ <header class="hb-head">
+ <p class="hb-cat">04.37 · Micro-Interactions</p>
+ <h1>Expanding Search</h1>
+ <p class="hb-lede">A search icon opens into a field you can type in, and closes when done. Best for toolbars.</p>
+ </header>
+
+ <section class="hb-step hb-watch" aria-labelledby="hb-watch-title">
+ <div class="hb-step-head">
+ <span class="hb-num" aria-hidden="true">1</span>
+ <div><h2 id="hb-watch-title">Click it</h2><p>Click or tap the search icon and type; press Escape, the close button or click away to close it. Or press Show me.</p></div>
+ </div>
+ <div class="stage hb-dots">
+ <div class="app">
+ <div class="bar" id="bar">
+ <span class="brand"><i aria-hidden="true"></i><span>Acme</span></span>
+ <div class="tools">
+ <div class="links" aria-hidden="true"><span>Docs</span><span>Blog</span><span>Pricing</span></div>
+ <button class="sbtn" id="sbtn" type="button" aria-label="Search" aria-expanded="false" aria-controls="sfield"><svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg></button>
+ <div class="sfield" id="sfield" role="search">
+ <span class="glass" aria-hidden="true"><svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg></span>
+ <label class="sr-only" for="q">Search the docs</label>
+ <input id="q" type="search" placeholder="Search docs…" autocomplete="off" spellcheck="false">
+ <button class="sclose" id="sclose" type="button" aria-label="Close search"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg></button>
+ </div>
+ </div>
+ </div>
+ <div class="page" aria-hidden="true"><b></b><i></i><i></i><i style="width:62%"></i></div>
+ </div>
+ </div>
+ <div class="hb-player">
+ <button class="hb-play" type="button" id="btn-demo" data-hb-demo><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M4.037 4.688a.495.495 0 0 1 .651-.651l16 6.5a.5.5 0 0 1-.063.947l-6.124 1.58a2 2 0 0 0-1.438 1.435l-1.579 6.126a.5.5 0 0 1-.947.063z"/></svg>Show me</button>
+ <button class="hb-play" type="button" id="btn-reset" data-hb-reset><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/></svg>Reset</button>
+ <label class="hb-toggle"><input class="hb-switch" type="checkbox" role="switch" id="slow-tog" data-hb-slowmo="css" autocomplete="off"><span>Slow motion</span></label>
+ </div>
+ </section>
+
+ <section class="hb-step hb-try" aria-labelledby="hb-try-title">
+ <div class="hb-step-head">
+ <span class="hb-num" aria-hidden="true">2</span>
+ <div><h2 id="hb-try-title">Try it</h2><p>Change a setting, then try it again or press Show me.</p></div>
+ </div>
+ <div class="hb-settings">
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="side-lbl">Opens toward</p>
+ <div class="seg" id="side-seg" role="group" aria-labelledby="side-lbl">
+ <button type="button" data-side="left" class="on" aria-pressed="true">Left</button>
+ <button type="button" data-side="right" aria-pressed="false">Right</button>
+ </div>
+ <p class="hb-hint">Which way the field grows out of the icon.</p>
+ </div>
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="speed-lbl">Speed</p>
+ <div class="seg" id="speed-seg" role="group" aria-labelledby="speed-lbl">
+ <button type="button" data-ms="450" aria-pressed="false">Slow</button>
+ <button type="button" data-ms="280" class="on" aria-pressed="true">Normal</button>
+ <button type="button" data-ms="160" aria-pressed="false">Fast</button>
+ </div>
+ <p class="hb-hint">How quickly the field opens and closes.</p>
+ </div>
+ <div class="hb-setting">
+ <label class="hb-switch-row"><span>Closes when you leave it</span><input class="hb-switch" type="checkbox" role="switch" id="leave-tog" checked autocomplete="off"></label>
+ <p class="hb-hint">Off keeps it open until Escape or the close button.</p>
+ </div>
+ </div>
+ </section>
+
+ <section class="hb-step hb-prompt-step" aria-labelledby="hb-prompt-title">
+ <div class="hb-step-head">
+ <span class="hb-num" aria-hidden="true">3</span>
+ <div><h2 id="hb-prompt-title">Copy the prompt</h2><p>Paste it into an AI assistant such as ChatGPT, Claude or Cursor to build this in your own project.</p></div>
+ </div>
+ <div class="hb-card">
+ <p class="hb-prompt">Add an expanding search to [the toolbar or header where search should sit]. Show only a search icon until it is pressed; then open a search field out of the icon, over the items beside it, and put the text cursor in it. Reveal the field with a clip or a scale from the icon's side, never by animating its width, so nothing around it moves. Escape or a close button closes it and gives the focus back to the icon, and a closed field stays out of the Tab order. Make the icon a real button with a label. If the visitor has reduced motion turned on, open and close it at once. Match the settings listed below.</p>
+ <div class="hb-chips-box" hidden>
+ <p class="hb-chips-title">Your settings</p>
+ <ul class="hb-chips"></ul>
+ </div>
+ <div class="hb-copy-row">
+ <button class="hb-copy" type="button"><svg class="hb-ic hb-i-copy" viewBox="0 0 24 24" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg><svg class="hb-ic hb-i-done" viewBox="0 0 24 24" aria-hidden="true"><path d="M20 6 9 17l-5-5"/></svg><span class="hb-copy-label" aria-live="polite">Copy prompt</span></button>
+ <p class="hb-hint">Replace the words in brackets with your own element. Your settings are added at the end.</p>
+ </div>
+ </div>
+ </section>
+
+ <section class="hb-about" aria-labelledby="hb-what-title">
+ <div class="hb-what">
+ <h2 id="hb-what-title">What it is</h2>
+ <div class="hb-what-text"><p>The full explanation is in <a href="README.md">README.md</a>.</p></div>
+ </div>
+ <div class="hb-fit">
+ <h2>Good for</h2>
+ <ul class="hb-tags hb-good"><li>Toolbars</li><li>Mobile headers</li><li>Docs sites</li><li>Dashboards</li></ul>
+ <h3>Avoid on</h3>
+ <ul class="hb-tags hb-avoid"><li>Sites where search comes first</li></ul>
+ </div>
+ </section>
+
+ <section class="hb-related" aria-labelledby="hb-related-title" hidden>
+ <h2 id="hb-related-title">Similar animations</h2>
+ <div class="hb-rel-list"></div>
+ </section>
+</main>
+<footer class="hb-foot"><span>Animation Handbook</span><a href="#top">Back to top ↑</a></footer>
+<script>
+ const $=id=>document.getElementById(id);
+ const stage=document.querySelector('.stage'),bar=$('bar'),sbtn=$('sbtn'),field=$('sfield'),input=$('q'),sclose=$('sclose'),leaveTog=$('leave-tog'),slowTog=$('slow-tog');
+ const vars=document.documentElement.style;
+ // Everything that eases between closed and open; toRest() switches these transitions off for a moment
+ const moving=[field,sbtn,...bar.querySelectorAll('.sbtn svg,.sclose,.sclose svg,.links')];
+ const word='pricing';
+ let dur=280,runTimers=[],downInField=false;
+
+ // Open: the field shows and, when the visitor opened it, takes the focus. The icon under it is out of reach (inert) while it is open.
+ function open(focus){
+ bar.classList.add('open');sbtn.setAttribute('aria-expanded','true');sbtn.inert=true;
+ if(focus)input.focus({preventScroll:true});
+ }
+ // Close: the clip closes the field over the icon again; with Escape or the close button the focus goes back to the icon.
+ function close(focusIcon){
+ bar.classList.remove('open','is-demo');sbtn.setAttribute('aria-expanded','false');sbtn.inert=false;
+ if(focusIcon)sbtn.focus({preventScroll:true});
+ }
+ sbtn.addEventListener('click',()=>open(true));
+ sclose.addEventListener('click',()=>close(true));
+ field.addEventListener('keydown',e=>{if(e.key==='Escape'){e.preventDefault();close(true)}});
+ // Leaving it: the focus moves to anything outside the field (a click elsewhere or Tab). Escape and the close button have
+ // already closed it by then.
+ field.addEventListener('focusout',e=>{
+ if(leaveTog.checked&&bar.classList.contains('open')&&!field.contains(e.relatedTarget))close(false);
+ });
+
+ // Show me: one run at a time. Every timer of the run goes through later(); stopRun() cancels the whole run.
+ // later(fn, move, hold) waits move*(slow?3:1) + hold ms: Slow motion triples the movement, never the hold.
+ function later(fn,move,hold){
+ const id=setTimeout(()=>{runTimers=runTimers.filter(t=>t!==id);fn()},move*(slowTog.checked?3:1)+(hold||0));
+ runTimers.push(id);
+ }
+ function running(){return runTimers.length>0}
+ function stopRun(){runTimers.forEach(clearTimeout);runTimers=[];sclose.classList.remove('hit')}
+ // A run starts closed and empty, put there without animating: the transitions are turned off, the state is set, a reflow
+ // makes it stick, and the transitions come back.
+ function toRest(){
+ moving.forEach(el=>{el.style.transition='none'});
+ close(false);sclose.classList.remove('hit');input.value='';
+ void bar.offsetWidth;
+ moving.forEach(el=>{el.style.transition=''});
+ }
+ // The field opens and looks focused (is-demo) without taking the real focus, "pricing" is typed a letter every 80ms, and after a
+ // pause it closes the way the settings say: the focus look leaves (Closes when you leave it) or the close button is pressed. At
+ // Normal speed it is closed again at 2.4 s. A real press on Show me lets go of a field that still has the focus (this also closes
+ // the phone keyboard); the press on arrival leaves a visitor who is already in the field alone.
+ $('btn-demo').addEventListener('click',e=>{
+ const inStage=stage.contains(document.activeElement);
+ if(!e.isTrusted&&(inStage||bar.classList.contains('open')))return;
+ stopRun();
+ if(inStage)document.activeElement.blur();
+ toRest();
+ later(()=>{bar.classList.add('is-demo');open(false)},0,150);
+ [...word].forEach((_,k)=>later(()=>{input.value=word.slice(0,k+1)},dur,350+80*k));
+ const t=350+80*word.length+700;
+ if(leaveTog.checked)later(()=>bar.classList.remove('is-demo'),dur,t);
+ else later(()=>sclose.classList.add('hit'),dur,t);
+ later(()=>{sclose.classList.remove('hit');close(false)},dur,t+200);
+ later(()=>{input.value=''},2*dur,t+250);
+ });
+ $('btn-reset').addEventListener('click',()=>{stopRun();toRest()});
+ // The visitor pressed, typed, scrolled or touched inside the stage: the run stops. A press on the field, open or still closing,
+ // takes it over (it stays open with the run's text, and the press puts the focus in it); any other input closes it and empties it.
+ stage.addEventListener('pointerdown',e=>{downInField=field.contains(e.target)},true);
+ document.addEventListener('hb:input',e=>{
+ if(!running())return;
+ stopRun();
+ if(e.detail.type==='pointerdown'&&downInField){bar.classList.remove('is-demo');open(false);return}
+ close(false);input.value='';
+ });
+
+ function choices(id,pick){
+ const buttons=document.querySelectorAll('#'+id+' button');
+ buttons.forEach(b=>b.addEventListener('click',()=>{
+ buttons.forEach(x=>{x.classList.toggle('on',x===b);x.setAttribute('aria-pressed',String(x===b))});
+ pick(b.dataset);
+ }));
+ }
+ choices('side-seg',d=>{bar.classList.toggle('to-right',d.side==='right')});
+ choices('speed-seg',d=>{dur=+d.ms;vars.setProperty('--dur',dur+'ms')});
+</script>
+</body>
+</html>
diff --git a/animations/04-micro-interactions/hold-to-confirm/index.html b/animations/04-micro-interactions/hold-to-confirm/index.html
index b94554dd..1210f301 100644
--- a/animations/04-micro-interactions/hold-to-confirm/index.html
+++ b/animations/04-micro-interactions/hold-to-confirm/index.html
@@ -68,7 +68,7 @@
<body class="hb" data-hb-kind="do" data-hb-autoplay>
<nav class="hb-bar" aria-label="Animation Handbook">
<a class="hb-home" href="../../../"><svg class="hb-mark" viewBox="0 0 32 32" aria-hidden="true"><g class="g"><circle cx="11.16" cy="20.84" r="6.1"/><circle cx="15.12" cy="16.88" r="6.1"/><circle cx="18.51" cy="13.49" r="6.1"/></g><circle class="b" cx="21.2" cy="10.8" r="6.6"/></svg><span>Animation Handbook</span></a>
- <span class="hb-pager"><a href="../pull-to-refresh/" rel="prev" aria-label="Previous: Pull to Refresh"><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m15 18-6-6 6-6"/></svg><span><span class="hb-dir">Previous: </span>Pull to Refresh</span></a></span>
+ <span class="hb-pager"><a href="../pull-to-refresh/" rel="prev" aria-label="Previous: Pull to Refresh"><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m15 18-6-6 6-6"/></svg><span><span class="hb-dir">Previous: </span>Pull to Refresh</span></a><a href="../expanding-search/" rel="next" aria-label="Next: Expanding Search"><span><span class="hb-dir">Next: </span>Expanding Search</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m9 18 6-6-6-6"/></svg></a></span>
</nav>
<main class="hb-page">
<header class="hb-head">
diff --git a/index.html b/index.html
index 4d8cc457..b1179ba0 100644
--- a/index.html
+++ b/index.html
@@ -685,6 +685,20 @@ button,input{font:inherit;color:inherit}
@keyframes hc-fill{0%,8%{transform:scaleX(0);opacity:1}58%,86%{transform:scaleX(1);opacity:1}96%{transform:scaleX(1);opacity:0}100%{transform:scaleX(0);opacity:0}}
@keyframes hc-t1{0%{opacity:1}58%{opacity:0}92%,100%{opacity:1}}
@keyframes hc-t2{0%{opacity:0}58%{opacity:1}92%,100%{opacity:0}}
+/* expanding search: the search icon at the end of a toolbar opens into a field over the links, a word is typed, it closes */
+.pv-xsearch{background:#08090c}
+.pv-xsearch .tb{position:absolute;left:9%;right:9%;top:34%;height:24%;display:flex;align-items:center;gap:7%;padding:0 4%;border-radius:8px;background:#16161b;border:1px solid #2a2a31}
+.pv-xsearch .br{flex:none;width:9px;height:9px;border-radius:3px;background:var(--accent)}
+.pv-xsearch .ln{display:flex;gap:8%;flex:1;animation:xs-ln 3.8s var(--ease) infinite}
+.pv-xsearch .ln i{width:22%;height:5px;border-radius:2px;background:#3a3a42}
+.pv-xsearch .fd{position:absolute;left:24%;right:2.5%;top:14%;bottom:14%;border-radius:999px;background:#2a2a31;box-shadow:inset 0 0 0 1.5px var(--accent);transform-origin:right;animation:xs-fd 3.8s var(--ease) infinite}
+.pv-xsearch .tx{position:absolute;left:9%;top:50%;width:46%;height:4px;margin-top:-2px;border-radius:2px;background:#d6d6da;transform-origin:left;animation:xs-tx 3.8s steps(7,end) infinite}
+.pv-xsearch .ic{position:absolute;right:2.5%;top:14%;bottom:14%;height:72%;aspect-ratio:1;padding:2.4%;border-radius:50%;background:#2a2a31;fill:none;stroke:#f4f4f2;stroke-width:2.4;stroke-linecap:round}
+.pv-xsearch .pg{position:absolute;left:13%;right:30%;top:68%;display:flex;flex-direction:column;gap:7px}
+.pv-xsearch .pg i{height:5px;border-radius:2px;background:#1f1f25}
+@keyframes xs-fd{0%,14%{transform:scaleX(.16);opacity:0}17%{opacity:1}26%,74%{transform:scaleX(1);opacity:1}83%{transform:scaleX(.16);opacity:1}86%,100%{transform:scaleX(.16);opacity:0}}
+@keyframes xs-ln{0%,14%{opacity:1}22%,78%{opacity:0}86%,100%{opacity:1}}
+@keyframes xs-tx{0%,30%{transform:scaleX(0)}48%,74%{transform:scaleX(1)}76%,100%{transform:scaleX(0)}}
/* ── bespoke: 05 Text & Typography ── */
.pv-kinetic{background:#0c0608;display:grid;place-items:center;overflow:hidden}
@@ -1018,7 +1032,7 @@ button,input{font:inherit;color:inherit}
<section class="wrap home-hero" aria-labelledby="hero-title">
<span class="float fl1" aria-hidden="true"></span><span class="float fl2" aria-hidden="true"></span><span class="float fl3" aria-hidden="true"></span>
<span class="float fl4" aria-hidden="true"></span><span class="float fl5" aria-hidden="true"></span><span class="float fl6" aria-hidden="true"></span>
- <p class="pill"><span class="pill-dot" aria-hidden="true"></span>130 free animations · no coding needed</p>
+ <p class="pill"><span class="pill-dot" aria-hidden="true"></span>131 free animations · no coding needed</p>
<h1 class="h1" id="hero-title">What do you want to animate?</h1>
<p class="sub">Pick a place, or describe it in your own words. Every animation plays live, and each one comes with a ready-made prompt for your AI assistant.</p>
<form class="search" id="search-form" role="search" action="./" method="get">
@@ -1075,8 +1089,8 @@ button,input{font:inherit;color:inherit}
<p class="empty-s">Try a simpler word, or pick one of these:</p>
<p class="pop"><button type="button" data-q="fade in">fade in</button><button type="button" data-q="typing text">typing text</button><button type="button" data-q="loading spinner">loading spinner</button><button type="button" data-q="parallax">parallax</button><button type="button" data-q="confetti">confetti</button></p>
</div>
- <div class="more" id="more"><button type="button" class="bigbtn" id="more-btn"><span id="more-label">Browse all 130 animations</span><svg class="i" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 5v14M6 13l6 6 6-6"/></svg></button></div>
- <noscript><p class="noscript">This page shows its animations with JavaScript. All 130 are still easy to reach: see the <a href="https://github.com/matinmonshizadeh/animation-handbook#categories">category list on GitHub</a> or the <a href="sitemap.xml">full sitemap</a>. Each demo is a page of its own under <code>/animations/&lt;category&gt;/&lt;name&gt;/</code>.</p></noscript>
+ <div class="more" id="more"><button type="button" class="bigbtn" id="more-btn"><span id="more-label">Browse all 131 animations</span><svg class="i" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 5v14M6 13l6 6 6-6"/></svg></button></div>
+ <noscript><p class="noscript">This page shows its animations with JavaScript. All 131 are still easy to reach: see the <a href="https://github.com/matinmonshizadeh/animation-handbook#categories">category list on GitHub</a> or the <a href="sitemap.xml">full sitemap</a>. Each demo is a page of its own under <code>/animations/&lt;category&gt;/&lt;name&gt;/</code>.</p></noscript>
</section>
<section class="how" id="how" aria-labelledby="how-title">
@@ -1094,7 +1108,7 @@ button,input{font:inherit;color:inherit}
<footer class="wrap foot">
<a class="brand" href="./"><svg class="mark" viewBox="0 0 32 32" aria-hidden="true"><circle class="ring" cx="11.16" cy="20.84" r="6.1"/><circle class="ring" cx="15.12" cy="16.88" r="6.1"/><circle class="ring" cx="18.51" cy="13.49" r="6.1"/><circle class="ball" cx="21.2" cy="10.8" r="6.6"/></svg><span>Animation Handbook</span></a>
- <p class="foot-t">130 web animations with live demos and copyable prompts.</p>
+ <p class="foot-t">131 web animations with live demos and copyable prompts.</p>
<nav class="nav" aria-label="Footer"><a class="lnk" href="https://github.com/matinmonshizadeh/animation-handbook" target="_blank" rel="noopener noreferrer">GitHub</a><a class="lnk" href="#top">Back to top</a></nav>
</footer>
<div class="toast" id="toast" role="status" aria-live="polite"><span class="ok" aria-hidden="true"><svg class="i" viewBox="0 0 24 24"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></span><span class="toast-t"></span></div>
@@ -1217,6 +1231,7 @@ const CATS=[
['segmented-control','Segmented Control','A highlight slides to the option you pick. Best for switching views.'],
['pull-to-refresh','Pull to Refresh','Pulling a list down shows a spinner, then new items. Best for feeds.'],
['hold-to-confirm','Hold to Confirm','Fills up while you hold it and acts only once it is full. Best for delete buttons.'],
+ ['expanding-search','Expanding Search','A search icon opens into a field you can type in, and closes when done. Best for toolbars.'],
]
},
{
@@ -1296,7 +1311,7 @@ const PV={
'svg-line-draw':'linedraw','scrollspy-nav':'spy','scroll-background-color':'bgblend',
'hamburger-menu-toggle':'hamb','theme-toggle-morph':'thememorph','copy-to-clipboard':'copyfx',
'star-rating':'stars','toast-notification':'toast','segmented-control':'segct','pull-to-refresh':'pullref',
- 'hold-to-confirm':'holdconf',
+ 'hold-to-confirm':'holdconf','expanding-search':'xsearch',
'flip-card-3d':'flip3d','matrix-rain':'matrix','plasma':'plasmapv',
'parallax-depth-of-field':'dof','parallax-scrolling':'plx','reverse-scrolling-columns':'revcol',
'cover-card-to-fixed-header':'cover','fly-in-fly-out-contact-list':'flylist','stacking-cards':'stack',
@@ -1419,6 +1434,7 @@ const PLACES={
'segmented-control':['menu','btn'],
'pull-to-refresh':['load'],
'hold-to-confirm':['btn'],
+ 'expanding-search':['menu','btn'],
// 05
'kinetic-typography':['text','intro'],
'typewriter-effect':['text','intro'],
@@ -1482,6 +1498,7 @@ function pvMarkup(k){
case 'sig3': return '<span class="s3 pa anim"></span><span class="s3 pb anim"></span>';
case 'sig4': return '<span class="s4r anim"></span><span class="s4r r2 anim"></span><span class="s4r r3 anim"></span><span class="s4d"></span>';
case 'holdconf': return '<span class="btn anim"><span class="fl anim"></span><span class="t t1 anim">HOLD TO DELETE</span><span class="t t2 anim">✓ DELETED</span></span>';
+ case 'xsearch': return '<span class="tb"><i class="br"></i><span class="ln anim"><i></i><i></i><i></i></span><span class="fd anim"><i class="tx anim"></i></span><svg class="ic" viewBox="0 0 24 24"><circle cx="11" cy="11" r="6"/><path d="m19.5 19.5-4-4"/></svg></span><span class="pg"><i></i><i></i></span>';
case 'sig5': return '<span class="s5 anim"></span><span class="s5 anim"></span><span class="s5 anim"></span>';
case 'sig6': return '<div class="cube anim"><span class="face f1"></span><span class="face f2"></span><span class="face f3"></span><span class="face f4"></span><span class="face f5"></span><span class="face f6"></span></div>';
case 'sig7': return '<span class="s7 anim"></span>';
diff --git a/sitemap.xml b/sitemap.xml
index 7ab615a8..aa0163af 100644
--- a/sitemap.xml
+++ b/sitemap.xml
@@ -82,6 +82,7 @@
<url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/segmented-control/</loc><lastmod>2026-07-14</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url>
<url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/pull-to-refresh/</loc><lastmod>2026-07-14</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url>
<url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/hold-to-confirm/</loc><lastmod>2026-10-01</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url>
+ <url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/expanding-search/</loc><lastmod>2026-10-01</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url>
<url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/kinetic-typography/</loc><lastmod>2026-07-14</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url>
<url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/typewriter-effect/</loc><lastmod>2026-07-14</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url>
<url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/scramble-text/</loc><lastmod>2026-07-14</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url>