3DPremium

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.

CSS3DButton

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

Keypad of a baguette vending machine — screen of a village bread dispenser — 3D Button Press V2 example 1

① Keypad of a baguette vending machine — screen of a village bread dispenser

WhenStanding at the dispenser, the customer types the locker number: twelve light keys on the left, the green display and the “Confirm” button on the right, the list of breads below.
WhyOn a street-side touch screen you want to feel that the key registered: it squashes, the digit shows. Twelve copies of the same button do the job, with no wrapper and no per-key setting, since the perspective is inside the button.
Settings56 × 44 px keys in a 3-column grid, 18 px apart vertically to leave room for the edge; recoloured light grey (#f8fafc → #cbd5e1 gradient, #64748b edge) in all three states; “Confirm” in green, same CSS. For the capture, the scene keeps the pressed look for 260 ms after each click (a class that repeats the :active values): on your page it lasts as long as the press.
Keyboard shortcuts shown as keys — help page of an online spreadsheet — 3D Button Press V2 example 2

② Keyboard shortcuts shown as keys — help page of an online spreadsheet

WhenA “Four keys worth knowing” help page: F2, F4, F9 and Del drawn as keys, each next to what it does. The key can be clicked: it acts on the small sample sheet on the right.
WhyA key drawn in relief is recognised before it is read, and the hover that lifts it invites a try. Readers remember a shortcut they have seen at work better than a row in a table.
Settings62 × 34 px buttons in a monospace font, white on a grey edge (#9ca3af), soft shadow lightened to 18% for the light background; the help page's script applies the command to the sheet on click; same 260 ms hold of the pressed look for the capture.
Play, pause, rewind — tape player for a heritage museum's oral archives — 3D Button Press V2 example 3

③ Play, pause, rewind — tape player for a heritage museum's oral archives

WhenA visitor listens to a testimony recorded in 1987: two reels, a counter, and under the machine four wide cream keys — Rewind, Play, Pause, Stop — plus “Next excerpt”.
WhyMechanical keys are part of the memory of a tape recorder: you press, it goes down, the tape starts. The relief gives that gesture to a museum audio player without an image or a line of script for the effect.
Settings104 × 52 px keys with a CSS-drawn pictogram above the label, cream #f5ead6 → #d9c7a4 gradient, brown #8a7558 edge; the player's script spins the reels and runs the counter; pressed look held for 260 ms after the click for the capture.

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 #c4b5fd ring 4 px off the edge (10.7:1 on the #0a0a0f background, 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 :active behaves 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 (#7c3aed gives 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.

Chrome 38+✓ Full (measured) — dedicated focus ring from 86
Firefox 64+✓ Full (measured) — Space does not show the press
Safari 9+✓ Not verified on a real Safari (states measured in WebKit)
Edge 79+✓ Not verified (same engine as Chrome)
Mobile iOS 9+✓ Not verified
Android Chrome 50+✓ Measured in emulation: no sticky hover after a tap

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):

index.html — structure
<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 / propertyDefaultEffect
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

The gesture is the same: a key on its edge that rises on hover and sinks on press. 3D Button Press moves forwards and backwards in depth inside a wrapper that carries the perspective, with a longer travel (an 8 px edge brought down to 2). This version puts the perspective in the button: a single element, to place anywhere and repeat in a grid, with a 10 px edge that keeps 5 on press, a very discreet tilt, and hover switched off on touch screens. To the eye the two look much alike; pick this one for keypads and rows of keys, the other for one big standalone button.
Not with the original CSS: the press follows :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.
The edge is a shadow: it takes up no room in the layout. Two buttons stacked tight see the first one's edge slip under the second. Allow a vertical gap of at least 12 px (the edge on hover) plus your margin; the dispenser example uses 18.