← All effects

3D Press Button

Micro-interactionVanilla JS · zero dependenciesCSS transforms · no canvas
press and hold the button — it also presses itself
-- fps
prefers-reduced-motion detected — presses without animation

X-ray · layers

the body under the face
grounds it on the page
overshoots on the way back

Parameters

Edge depth7 px
Press travel6 px
Return time300 ms
Bounce0.40
your version · updates as you tinker

How this effect works

The button is two rectangles pretending to be one object. The face is the button you see; underneath sits an identical, darker copy shifted down by a few pixels — that sliver of dark is the "side" of the button, and it's the entire 3D illusion. Press, and the face slides down over the edge: the sliver shrinks, so your eye reads it as the button sinking into the page. Turn the depth layer off and the same motion suddenly looks like a flat sticker twitching.

The spring layer lives in one CSS timing function: on release, the face doesn't just return — it overshoots its resting point and settles, like something with real mass. That overshoot is a single number in a cubic-bezier curve; drag the bounce slider and you're editing that number. The shadow underneath dims and shrinks while pressed, because an object closer to the ground casts a tighter shadow — a detail nobody notices consciously and everybody feels.

Production notes: respects prefers-reduced-motion (still presses, without animation) · everything is CSS transform + opacity on three elements — compositor-cheap · works with mouse, touch and keyboard (it's a real button) · the copied snippet is self-contained HTML + CSS + JS.