Create interactive cards that respond to mouse movement with 3D transforms, perspective effects, and smooth animations. Perfect for social media demos and portfolio showcases.
Want to see what you'll be building? Check out the working example with complete code snippets.
Preview This3D transforms create depth and perspective:
Create a clean, semantic structure:
<div class="card-container">
<div class="floating-card profile" data-tilt>
<div class="card-content">
<div class="avatar">👤</div>
<h3>John Developer</h3>
<p>Full Stack Developer</p>
<div class="skills">
<span>React</span>
<span>Node.js</span>
<span>CSS</span>
</div>
</div>
</div>
</div>
Start with fundamental card properties:
.floating-card {
width: 300px;
height: 350px;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(20px);
border-radius: 25px;
padding: 2.5rem;
cursor: pointer;
transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
border: 1px solid rgba(255, 255, 255, 0.2);
position: relative;
overflow: hidden;
transform-style: preserve-3d;
}
Set up the 3D environment:
body {
perspective: 1000px;
}
.floating-card {
transform-style: preserve-3d;
}
Build the JavaScript tilt functionality:
class TiltEffect {
constructor(element) {
this.element = element;
this.maxTilt = 15;
this.init();
}
handleMouseMove(e) {
const deltaX = e.clientX - this.centerX;
const deltaY = e.clientY - this.centerY;
const tiltX = (deltaY / (this.rect.height / 2)) * -this.maxTilt;
const tiltY = (deltaX / (this.rect.width / 2)) * this.maxTilt;
this.element.style.transform = `
perspective(1000px)
rotateX(${tiltX}deg)
rotateY(${tiltY}deg)
translateZ(20px)
scale(1.02)
`;
}
}
Enhance with modern backdrop-filter:
.floating-card {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(20px);
border: 1px solid rgba(255, 255, 255, 0.2);
}
Ensure smooth 3D animations:
will-change: transform
for elements being animatedrequestAnimationFrame
for smooth updatestransform3d
Improve the tilt effect accuracy:
Master the frosted glass effect:
3D transforms and backdrop-filter support:
Once you’ve mastered 3D card effects, try:
Ready to add depth to your designs? Let’s build some stunning 3D floating cards! 🌟