CSS Expanding Search
A round search icon that stretches into a full search field when it gets focus.
HTML
<input class="search-expand" type="search" placeholder="Search…" aria-label="Search">
CSS
.search-expand {
box-sizing: border-box;
width: 44px;
height: 44px;
padding: 0 0 0 42px;
border: 1px solid #e2e8f0;
border-radius: 999px;
background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") 13px 50% / 17px no-repeat;
color: #0f172a;
font: 15px system-ui, sans-serif;
-webkit-appearance: none;
appearance: none;
outline: none;
cursor: pointer;
transition: width 0.35s cubic-bezier(0.3, 0.7, 0.4, 1), border-color 0.2s ease, box-shadow 0.2s ease;
}
/* Stay open while focused or while it has text */
.search-expand:focus,
.search-expand:not(:placeholder-shown) {
width: 220px;
padding-right: 14px;
border-color: #0ea5e9;
box-shadow: 0 0 0 4px rgba(14, 165, 233, 0.15);
cursor: text;
}
About this CSS Expanding Search
This CSS Expanding Search is 26 lines of pure CSS (0.9 KB) with no JavaScript and no dependencies. It uses transitions and box shadows. It works in current versions of Chrome, Edge, Safari and Firefox. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.
CSS features used
Customize it
The colors in this snippet. Search and replace them to match your brand:
#e2e8f0#fff#0f172a#0ea5e9
How to use this expanding search
- Copy the HTML and paste it where you want the element to appear.
- Copy the CSS into your stylesheet, or inside a
<style>tag. - Keep the
.search-expandclass name, or rename it in both places. Then tweak colors, sizes and timing to match your design. - Using React or Next.js? Change
classtoclassNamein the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).
Building with an AI tool?
“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.