FormsPremium

Search Expand V2

A 50 px indigo ring with its magnifier: on click or Tab, the wrapper widens to 250 px in 0.4 s and the field appears inside it, magnifier on the right. It stays open as long as there is text.

CSSFocusWidth

Updated

This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. Forms has 21 effects, including 2 free. Explore the category →

3 usage examples

Looking up a word in a board game's rules — a game publisher's viewer — Search Expand V2 example 1

① Looking up a word in a board game's rules — a game publisher's viewer

WhenAt the end of the toolbar, an amber ring. It opens to the left; "barter" is typed, the three passages on the page are highlighted and a counter shows next to the field.
WhyA viewer keeps its bar for the title and the page count; search is only needed now and then. Closed, it fits in a circle; open, it eats into the title, never into the page being read.
SettingsRoot aligned to the right (justify-content:flex-end) to open leftwards, and shrunk with transform:scale(.8): the ring is 40 px without touching the effect's measurements. --sxv-width:230px, --sxv-accent:#fbbf24, --sxv-ring:#fde68a, aria-label="Search the rules". Highlighting and the counter are scene code, which also plays focus and typing.
Finding an aisle on a hardware store's map — the magnifier floats over the map — Search Expand V2 example 2

② Finding an aisle on a hardware store's map — the magnifier floats over the map

WhenSitting in the corner of the map, the magnifier opens on click. From "pai" on, the Paint aisle turns orange, the others fade and a tag gives the aisle number.
WhyThe map is the content: an always-open field would hide part of it. The ring covers only 54 px while nothing is searched, then stays unfolded with the word inside as long as the aisle is shown.
SettingsAs the field is transparent, the scene gives the root a rounded white background (background:#fff; border-radius:27px; padding:2px) and a shadow so that it stands out from the map. --sxv-width:214px, --sxv-accent:#c2410c, --sxv-ring:#c2410c, --sxv-text:#2a2f27, --sxv-muted:#5c6455. The highlighted aisle and the tag are scene code.
The current search stays unfolded in the header — results of a second-hand bike ads site — Search Expand V2 example 3

③ The current search stays unfolded in the header — results of a second-hand bike ads site

WhenThe results page arrives with "gravel size M" already in the field: the search is open though nobody touched it. A click on the "×" chip clears it; the ring closes and the list goes back to all ads.
WhyOn a results page you want to re-read what you asked for. The "open because filled" state does that with no script: the value only has to be written in the HTML sent by the server.
Settingsvalue="gravel size M" in the HTML, --sxv-width:206px, --sxv-accent:#1d4ed8, --sxv-ring:#1d4ed8, --sxv-text:#111827, --sxv-muted:#6b7280, root aligned to the right. The "×" chip, the counter and the two lists belong to the scene; it clears the field with input.value = '' and the ring closes by itself.

How it works

Here it is not the field that changes width, it is its wrapper. .sxv-group is 50 × 50 px at rest; the .sxv-input field covers all of it, with a 2 px indigo frame, 25 px corners and no fill. While the wrapper is closed, the field's padding leaves no room for text: all you see is the ring and the magnifier, set 15 px from the right edge.

As soon as focus enters the wrapper (:focus-within), its width goes to --sxv-width, 250 px by default, in 0.4 s. The field follows, since it is 100% of the wrapper, and its padding returns to normal: 20 px on the left, 50 px on the right so text never runs under the magnifier. A light 2 px outline surrounds the whole thing for as long as it has focus.

A second rule keeps the wrapper open without focus: .sxv-group:has(.sxv-input:not(:placeholder-shown)), meaning "the wrapper holds a non-empty field". A value written in the value attribute therefore opens the search as soon as the page arrives (measured: 250 px on load). Cleared and then left, it becomes a ring again.

The magnifier is a drawing, not a button: it lets clicks through to the field and triggers nothing. The search is sent with Enter, if the field sits in a form. The .fx-0300-root root centres the ring on a dark demo background; its alignment decides which side the ring opens to.

Accessibility

  • Name: the field carries aria-label="Search"; the magnifier is hidden from screen readers (aria-hidden). Closed or open, it is the same element: a screen reader announces a search field, never a button.
  • Keyboard: Tab opens the ring and places the caret, Enter submits the surrounding form. Escape clears the field in Chromium and Firefox (built-in behaviour of search fields), not in the test WebKit.
  • Visible focus: a light 2 px outline (#a5b4fc, 9.9:1 on the demo background) surrounds the wrapper. It was added: without it, a field that was already filled did not change by a single pixel when focused in Firefox and WebKit.
  • Clear cross: the browser's own is hidden. It showed in blue in Chromium, not at all in Firefox, and in black on the dark background in WebKit, hence invisible yet clickable.
  • Touch: the closed target is 50 × 50 px; one tap is enough to open it (measured on a 390 px screen).
  • Reduced motion: the wrapper takes its final width at once, on opening and on closing.
  • Contrast: ring and magnifier #6366f1, 4.4:1; hint text #a1a1aa, 7.7:1, identical in all three engines.

Browser compatibility

Opening on focus needs :focus-within (Chrome 60, Firefox 52, Safari 10.1). Staying open when the field is filled needs :has(): Chrome 105, Firefox 121, Safari 15.4 (@mdn/browser-compat-data). The two rules are separate: a browser that ignores :has() keeps the opening on focus (checked by swapping :has for an unknown selector; when both sat in one rule, the ring no longer opened at all). Measured on 04/12/2026 in Chromium 149, Firefox 151 and WebKit 26.5: two rings on the page, value on load, field cleared, 200 px container, 390 px with touch, reduced motion, forced colours.

Chrome 105+✓ Full (measured in Chromium 149)
Firefox 121+✓ Full (measured in Firefox 151)
Safari 15.4+✓ Full (measured in WebKit 26.5)
Edge 105+✓ Full (Chromium engine)
iOS Safari 15.4+✓ Not checked on a real device
Chrome 60-104, Firefox 52-120, Safari 10.1-15.3✓ Partial: opens on focus, closes even when filled (simulated, not measured on these versions)

Without :has(), the ring opens on focus but closes as soon as you leave it, even when filled: the typed text is no longer visible until you come back. If your visitors use browsers from before late 2023, prefer Search Expand. No script is involved.

The code

HTML structure to paste into your page (the CSS + JS come with your purchase):

index.html — structure
<div class="fx-0300-root">
  <div class="sxv-group">
    <input class="sxv-input" type="search" name="q" aria-label="Search" placeholder="Search...">
    <span class="sxv-icon" aria-hidden="true">
      <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" focusable="false">
        <circle cx="11" cy="11" r="8"></circle>
        <path d="M21 21l-4.35-4.35"></path>
      </svg>
    </span>
  </div>
</div>

One-time payment, no subscription — the code is yours forever

Customize

Options passed to the API or data-* attributes:

Option / propertyDefaultEffect
Open width (CSS — --sxv-width) 250px A length or a percentage of the root: 100% opens across its whole width. The wrapper never exceeds its parent.
Colours (CSS — --sxv-accent, --sxv-ring) #6366f1 · #a5b4fc Ring and magnifier; outline added while in focus. On a light background give the outline a dark colour, or it gets lost.
Texts (CSS — --sxv-text, --sxv-muted) #fff · #a1a1aa Typed text and hint text. The field has no fill: they must be readable on whatever lies behind.
Opening side (CSS — the root's justify-content) center (opens both ways) flex-end: the right edge stays put and it opens leftwards; flex-start: the reverse.
Duration (CSS — transition on .sxv-group) 0.4 s Only the width is animated; the field's padding switches at once at the start.
Ring size (CSS) 50px Hard-coded in several places (width, height, 25 px corners, padding). For a smaller ring without redoing the maths, shrink the root: transform: scale(.8).
Hint text (HTML — placeholder) Search... Keep it, even reduced to one space: without a placeholder the browser treats the field as always filled and the ring never closes.

FAQ

In Search Expand the field itself stretches (280 px in 0.5 s), its magnifier sits on the left and goes from grey to indigo, its background gets tinted. Here the wrapper opens, the magnifier is on the right, the ring is indigo from the start and the field stays transparent. The other difference is technical: this V2 needs :has() to stay open when filled, hence browsers released since late 2023; Search Expand does without it.
First case: the browser is older than Chrome 105, Firefox 121 or Safari 15.4 and does not know :has(): the ring opens on focus but cannot stay open. Second case: the field has lost its placeholder; the browser then takes it as always filled and the ring stays open all the time (measured: 250 px at rest).
The browser's own is hidden, because it did not look the same from one browser to the next and turned invisible on a dark background in WebKit. Escape still clears the field in Chrome and Firefox. To get it back, delete the .sxv-input::-webkit-search-cancel-button rule; for a cross of your own, add a button next to the wrapper and clear the field with input.value = ''.