# Expanding Search

> A round search icon that stretches into a full search field when it gets focus.

- Category: [CSS Form Elements](https://copy-css.com/category/forms)
- Tags: search, expand, icon, focus, input, header
- Live preview: https://copy-css.com/snippets/expanding-search
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<input class="search-expand" type="search" placeholder="Search…" aria-label="Search">
```

## CSS

```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;
}
```

## Notes

- 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.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
