3D Button Press V2
A violet key on its 10 px edge: it lifts 2 px on hover and squashes 5 px under the finger. One element, pure CSS, no wrapper.
Updated
This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. 3D has 50 effects, including 8 free. Explore the category →
3 usage examples



How it works
It all fits in one <button class="btn-3d-press">. The top is a vertical #8b5cf6 → #6366f1 gradient with 8 px corners; the thickness is not a second element but the first shadow of box-shadow, a shadow with no blur shifted 10 px down in #4f46e5. A second shadow, 40% black with a 20 px blur, sets the key on the page. With the original label the button measures 118 × 47 px in Chromium (119 × 48 in Firefox), edge not included.
Three states, three sets of values, joined by transition: .1s. At rest: a 10 px edge. On hover: the button moves up 2 px, the edge grows to 12 px and the soft shadow widens (18 px offset, 25 px blur) — the key comes loose. On press: it moves down 5 px, the edge shrinks to 5 px and the shadow tightens (8 px, 15 px) — the key squashes while the bottom of the edge stays put. Each state adds a backward tilt, rotateX(2deg) then rotateX(5deg), seen through a perspective(500px) written into the button's own transform.
Let us be exact about that tilt: it is there in the computed matrix, but at this size it widens the button by one pixel on press (118 → 119 px measured). What the eye picks up is the 7 px of travel between hover and press and the edge melting from 12 to 5 px. The point of putting perspective() inside the transform lies elsewhere: the button needs no prepared parent. The .demo-3d frame only centres the demo; drop the button alone into a form, a toolbar or a grid of keys and it behaves the same.
Accessibility
- Keyboard: it is a real button. Measured in all three engines: Tab reaches it and draws a 3 px
#c4b5fdring 4 px off the edge (10.7:1 on the#0a0a0fbackground, computed); Enter and Space each trigger the click. Holding Space shows the key pressed in Chromium and WebKit, not in Firefox; Enter shows it nowhere — that is how:activebehaves in those browsers. - Touch: the hover rule is wrapped in
@media (hover: hover). Measured in touch emulation (Chromium, WebKit): after a tap, the button goes back exactly to its resting state instead of staying raised. The press during contact relies on:active; not verified on a real phone. - Reduced motion: the button no longer rises, sinks or tilts (identical transform in all three states, measured in all three engines). The edge still goes from 10 to 12 then 5 px: hover and press stay readable without movement.
- Contrast: white label in weight 600 on the gradient, 4.2:1 at the top (
#8b5cf6) and 4.5:1 at the bottom (#6366f1), computed values. That is tight: for a label under 19 px, darken the top of the gradient (#7c3aedgives 5.7:1). - Target size: 118 × 47 px as supplied, above the recommended 44 px. If you shrink the button into a keyboard key, keep at least 44 px in one dimension and count the edge in the spacing: 10 px under each key.
Browser compatibility
CSS only, 1.8 KB, no script. Recorded in Chromium 149, Firefox 151 and WebKit 26.5: same matrices and same shadows at rest, on hover and on press, visible focus, keyboard click, two independent buttons on one page, no overflow at 320 px. Real Safari not verified. Floor versions per MDN: 3D transforms and perspective() (Chrome 36, Firefox 16, Safari 9), @media (hover) (Chrome 38, Firefox 64, Safari 9), :focus-visible (Chrome 86, Firefox 85, Safari 15.4). Before Firefox 64 the hover block is ignored: the button still presses but does not lift.
Without 3D transforms you are left with a flat button and its edge: the shadow alone is enough to say “key”. Without :focus-visible the browser draws its usual focus ring. No JavaScript is shipped, so nothing depends on a script.
The code
HTML structure to paste into your page (the CSS + JS come with your purchase):
<div class="fx-0018-root">
<div class="demo-3d">
<button type="button" class="btn-3d-press">…</button>
</div>
</div>
One-time payment, no subscription — the code is yours forever
Customize
Options passed to the API or data-* attributes:
| Option / property | Default | Effect |
|---|---|---|
Key thickness (CSS — first shadow of box-shadow) |
10 px at rest, 12 px on hover, 5 px on press | Keep the order hover > rest > press. For the bottom of the edge to stay still, the travel must make up the difference: 5 px less edge on press, 5 px of descent. |
Travel (CSS — translateY() in the :hover and :active rules) |
−2 px on hover, +5 px on press | A slim keyboard key: 4 px edge, +3 px travel. A big arcade button: 16 px edge, +12 px travel. |
Tilt (CSS — rotateX() and perspective(500px)) |
2° on hover, 5° on press | Almost invisible at these values. Go to 12° and perspective(300px) for a key that clearly dives backwards, or remove rotateX for a straight press. |
Colours (CSS — background and the colour of the first shadow) |
top #8b5cf6 → #6366f1, edge #4f46e5 |
The edge must be darker than the bottom of the gradient, or the volume disappears. Its colour is written in all three states: change it three times. |
Speed (CSS — transition: .1s) |
0.1 s | 0.05 s gives a crisp key, 0.2 s a soft one. Beyond that a quick click no longer has time to show the press. |
Shape (CSS — padding: 16px 32px, border-radius: 8px) |
118 × 47 px with “Click Me” | Set a fixed width and height for a grid of keys. border-radius: 50% on a square button makes a round push-button, and the edge follows. |
FAQ
:active, so it lasts as long as the press. For a two-state button, add aria-pressed to the button, toggle it by script, and copy the two :active declarations into a .btn-3d-press[aria-pressed="true"] rule.