# Expanding search bar

> A round magnifying glass button that opens into a full search field when you click it.

- Category: [Inputs](https://library.aimran.es/components/inputs)
- Built with: HTML + CSS
- Live editor: https://library.aimran.es/blocks/uv-in-search
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

An expanding search bar saves room in crowded headers. It works well for a blog with a busy menu, the top bar of a small online shop or the mobile header of a news site. At rest it is a round button with a magnifying glass; click it and it springs open into a wide field.

When the field loses focus it shrinks back, so it suits sites where search is a helper, not the main road. On a documentation site or a large catalog, where people search all the time, show a full search bar from the start.

## Code

### HTML

```html
<label class="uv-is"><input placeholder="Search…"><svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="6.5"/><path d="M20 20l-4.2-4.2"/></svg></label>
```

### CSS

```css
.uv-is {
  --c1: #0071e3;
  --c2: #8ec5ff;
  --s: 16px;
  /* tamaño */
  --k: 1;
  /* velocidad */
  --fg: #1d1d1f;
  /* texto */
  --bg: #f5f5f7;
  /* fondo */
}

.uv-is {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  position: relative;
  display: block;
  font-size: var(--s);
}

.uv-is input {
  width: 3em;
  height: 3em;
  box-sizing: border-box;
  padding: 0 0 0 3em;
  border: 0;
  border-radius: 999px;
  font: inherit;
  color: var(--fg);
  background: var(--c1);
  outline: none;
  cursor: pointer;
  box-shadow: 0 8px 24px -10px var(--c1);
  transition: all calc(0.5s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uv-is input::placeholder {
  color: transparent;
}

.uv-is svg {
  position: absolute;
  left: .85em;
  top: .85em;
  width: 1.3em;
  fill: none;
  stroke: #fff;
  stroke-width: 2.2;
  stroke-linecap: round;
  pointer-events: none;
  transition: stroke calc(0.3s / var(--k));
}

.uv-is input:focus {
  width: 16em;
  padding-right: 1em;
  cursor: text;
  background: color-mix(in srgb,var(--fg) 6%,var(--bg));
  box-shadow: inset 0 0 0 2px var(--c1);
}

.uv-is input:focus::placeholder {
  color: color-mix(in srgb,var(--fg) 40%,transparent);
}

.uv-is input:focus+svg {
  stroke: var(--c1);
}
```

### React

```tsx
import type { CSSProperties } from "react";

const css = `
.uv-is {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  position: relative;
  display: block;
  font-size: var(--s);
}

.uv-is input {
  width: 3em;
  height: 3em;
  box-sizing: border-box;
  padding: 0 0 0 3em;
  border: 0;
  border-radius: 999px;
  font: inherit;
  color: var(--fg);
  background: var(--c1);
  outline: none;
  cursor: pointer;
  box-shadow: 0 8px 24px -10px var(--c1);
  transition: all calc(0.5s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uv-is input::placeholder {
  color: transparent;
}

.uv-is svg {
  position: absolute;
  left: .85em;
  top: .85em;
  width: 1.3em;
  fill: none;
  stroke: #fff;
  stroke-width: 2.2;
  stroke-linecap: round;
  pointer-events: none;
  transition: stroke calc(0.3s / var(--k));
}

.uv-is input:focus {
  width: 16em;
  padding-right: 1em;
  cursor: text;
  background: color-mix(in srgb,var(--fg) 6%,var(--bg));
  box-shadow: inset 0 0 0 2px var(--c1);
}

.uv-is input:focus::placeholder {
  color: color-mix(in srgb,var(--fg) 40%,transparent);
}

.uv-is input:focus+svg {
  stroke: var(--c1);
}
`;

export default function InSearch() {
  return (
    <>
      <style>{css}</style>
      <div
        style={{
          "--c1": "#0071e3",
          "--c2": "#8ec5ff",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <label className="uv-is"><input placeholder="Search…" /><svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="6.5" /><path d="M20 20l-4.2-4.2" /></svg></label>
      </div>
    </>
  );
}
```

## Prompt for AI assistants

Paste this into ChatGPT, Claude, Cursor, v0 or Lovable to adapt the block to your stack (Tailwind, Vue, Svelte…):

````text
I want to add the “Expanding search bar” block (Inputs) from AIMRAN Library to my project.

## What it is
A round magnifying glass button that opens into a full search field when you click it.

## Chosen settings
- Main color: #0071e3
- Secondary color: #8ec5ff
- Size: 16px (from 12 to 24px)
- Speed: 1x (from 0.5 to 2x)
- Text: "Search…"

## What I need
1. Add it to my project with the same look and animation as the reference code: same sizes, colours, radii, shadows, timings and easing.
2. It is built with plain HTML and CSS (the reference wraps it in a React component with its CSS). If my project uses something else (Vue, Svelte, Astro, plain HTML…), translate it without losing any behaviour. If I use Tailwind, turn the styles into classes; if not, keep the CSS in its own file.
3. Expose the settings above as props (or CSS variables) with those values as defaults.
4. Make it work well on phones: nothing that depends only on hover, touch targets of at least 44 px and no overflow on 320 px screens.
5. Make it look right in light and dark mode.
6. Keep it accessible: semantic HTML, roles and aria-* where needed, visible focus and keyboard support.
7. Respect prefers-reduced-motion: with reduced motion, no big animations but the same end result.

## Reference code
```tsx
import type { CSSProperties } from "react";

const css = `
.uv-is {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  position: relative;
  display: block;
  font-size: var(--s);
}

.uv-is input {
  width: 3em;
  height: 3em;
  box-sizing: border-box;
  padding: 0 0 0 3em;
  border: 0;
  border-radius: 999px;
  font: inherit;
  color: var(--fg);
  background: var(--c1);
  outline: none;
  cursor: pointer;
  box-shadow: 0 8px 24px -10px var(--c1);
  transition: all calc(0.5s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uv-is input::placeholder {
  color: transparent;
}

.uv-is svg {
  position: absolute;
  left: .85em;
  top: .85em;
  width: 1.3em;
  fill: none;
  stroke: #fff;
  stroke-width: 2.2;
  stroke-linecap: round;
  pointer-events: none;
  transition: stroke calc(0.3s / var(--k));
}

.uv-is input:focus {
  width: 16em;
  padding-right: 1em;
  cursor: text;
  background: color-mix(in srgb,var(--fg) 6%,var(--bg));
  box-shadow: inset 0 0 0 2px var(--c1);
}

.uv-is input:focus::placeholder {
  color: color-mix(in srgb,var(--fg) 40%,transparent);
}

.uv-is input:focus+svg {
  stroke: var(--c1);
}
`;

export default function InSearch() {
  return (
    <>
      <style>{css}</style>
      <div
        style={{
          "--c1": "#0071e3",
          "--c2": "#8ec5ff",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <label className="uv-is"><input placeholder="Search…" /><svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="6.5" /><path d="M20 20l-4.2-4.2" /></svg></label>
      </div>
    </>
  );
}
```

Give me the complete final code, ready to paste, and tell me in one line where to put it in my project.
````
