Back to Snippets

Interactive 3D Credit Card Tilt JS

Move your mouse over the card and it tilts to follow, with a band of light sweeping across the surface. Moving away settles it back to flat.

The tilt is a rotateX and rotateY pair worked out from how far the cursor sits from the card center, capped at 15 degrees each way. The parent holds the perspective value, and that is what makes the rotation read as depth instead of a flat skew. Card number, logos and labels each carry their own translateZ, so they float above the surface at different heights.

The sheen is a separate layer holding an oversized diagonal gradient. Only its background-position moves, which is far cheaper than redrawing a gradient, and mix-blend-mode overlay keeps it looking like reflected light rather than a white streak. Transitions are switched off on mouseenter so tracking stays instant, then switched back on for the settle.

186
#javascript
#css
#3d
#tilt
#credit card
#checkout
#payment
#holographic
#interactive