Preview and code
/*
* MIT License
*
* Copyright (c) 2026 Syed Subhan Uddin
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
// Tilt Card from amicro by Syed Subhan Uddin
// https://github.com/Subhan-code/Amicro--Micro-transitions-/blob/main/registry/ui/hover/tilt-card.tsx
// MIT License, Copyright (c) 2026 Syed Subhan Uddin. Full licence: https://github.com/Subhan-code/Amicro--Micro-transitions-/blob/main/LICENSE
// Styled with Tailwind CSS. Needs: framer-motion
import React, { useRef, useState } from 'react';
import { motion, useMotionValue, useSpring, useTransform } from 'framer-motion';
interface TiltCardProps {
children: React.ReactNode;
maxTilt?: number;
className?: string;
cardClassName?: string;
}
export function TiltCard({
children,
maxTilt = 15,
className = '',
cardClassName = '',
}: TiltCardProps) {
const cardRef = useRef<HTMLDivElement>(null);
const [isHovered, setIsHovered] = useState(false);
// Motion values for x/y mouse offset relative to card center (-0.5 to 0.5)
const x = useMotionValue(0);
const y = useMotionValue(0);
// Springs for smooth movement
const springConfig = { damping: 20, stiffness: 200, mass: 0.5 };
const rotateX = useSpring(useTransform(y, [-0.5, 0.5], [maxTilt, -maxTilt]), springConfig);
const rotateY = useSpring(useTransform(x, [-0.5, 0.5], [-maxTilt, maxTilt]), springConfig);
const handleMouseMove = (event: React.MouseEvent<HTMLDivElement>) => {
if (!cardRef.current) return;
const rect = cardRef.current.getBoundingClientRect();
// Calculate normalized position relative to center (-0.5 to 0.5)
const relativeX = (event.clientX - rect.left) / rect.width - 0.5;
const relativeY = (event.clientY - rect.top) / rect.height - 0.5;
x.set(relativeX);
y.set(relativeY);
};
const handleMouseLeave = () => {
setIsHovered(false);
x.set(0);
y.set(0);
};
return (
<div
ref={cardRef}
onMouseMove={handleMouseMove}
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={handleMouseLeave}
className={`relative w-full aspect-[4/3] max-w-[320px] cursor-pointer ${className}`}
style={{ perspective: '800px' }}
>
<motion.div
style={{
rotateX,
rotateY,
transformStyle: 'preserve-3d',
}}
className={`w-full h-full rounded-2xl bg-gradient-to-br from-neutral-100 to-neutral-250 dark:from-neutral-850 dark:to-neutral-900 border border-neutral-200/20 shadow-lg flex items-center justify-center p-6 select-none ${cardClassName}`}
>
<div style={{ transform: 'translateZ(40px)', transformStyle: 'preserve-3d' }} className="w-full h-full flex flex-col justify-center items-center">
{children}
</div>
</motion.div>
</div>
);
}
Needs: framer-motion
react tailwindcss
Install
npx shadcn@latest add https://ownlyplans.com/r/bhaskar/tilt-card-motion.json
Adds the React files to components/ownlyplans/ in a project set up with shadcn and Tailwind CSS. Or copy them from the Code tab.
About
3D parallax tilt effect following mouse cursor.
A React card built with Motion and Tailwind CSS. Open the Preview tab to try it, then copy the code from the Code tab or install it with the shadcn command. Hand this page’s link to Claude or any AI tool and it can read the code straight from the page.
Credit: from the amicro library by Syed Subhan Uddin (https://github.com/Subhan-code/Amicro–Micro-transitions-), shared here under the MIT licence.
MIT License
Copyright (c) 2026 Syed Subhan Uddin
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.