Skip to content
Playground

The expanding search

June 2026Used in zeblink.io

One of my all-time favorite UI hacks, solving the age-old problem of how poorly form fields animate.

Sleight of hand UI

Your brain sees a single search field expanding to a larger size, but it's really two separate elements working in sync. As the small faux search input (our decoy button) fades, the real search field, already full size and in place, is revealed from the center by an animated mask.

Small, cheap movements in the larger element as it settles complete the trick, and make your brain accept the illusion of a single element expanding.

Why?

Because the alternatives are so much worse. If you animate the width of an actual search field, showing the advanced filters and controls as it grows, the browser has to lay out the row again and repaint it on every frame. All that happens on the main thread, so when the page is busy, frames drop and the motion stutters.

You could scale the button up instead, which skips the layout. But the bar is several times as wide as the button and barely taller, so the icons, the border, the rounded corners and the text would squash and blur on the way.

Our trick only animates opacity, transforms and a clip. None of them changes the layout, so nothing is laid out again. The fades and slides can run on the GPU, and the clip, depending on the browser, at most repaints the overlay, never the page under it. And the field is real from the first frame: it takes focus at 150 ms, so you can even start typing before the motion is over.