Cards
FloatingCard
The card bobs gently in the air and its shadow shrinks as it rises. Use delay to put several cards out of step.
Download
- React
- Tailwind CSS v4
- motion
components/ui/floating-card.tsx
"use client";
import type { ReactNode } from "react";
import { motion, useReducedMotion } from "motion/react";
type FloatingCardProps = {
children: ReactNode;
className?: string;
/** How high the card rises, in pixels. */
distance?: number;
/** Seconds for one rise and fall. */
duration?: number;
/** Seconds to wait before starting, to put several cards out of step. */
delay?: number;
};
/* FloatingCard: the card bobs gently in the air; its shadow shrinks as it rises. */
export function FloatingCard({
children,
className = "rounded-2xl border border-white/10 bg-[#16132a] p-6 text-white",
distance = 12,
duration = 4,
delay = 0,
}: FloatingCardProps) {
const reduce = useReducedMotion();
const loop = { duration, delay, repeat: Infinity, ease: "easeInOut" } as const;
return (
<div className="relative pb-6">
<motion.div
className={className}
animate={reduce ? undefined : { y: [0, -distance, 0] }}
transition={loop}
>
{children}
</motion.div>
<motion.div
aria-hidden
className="absolute inset-x-[12%] bottom-0 h-3 rounded-[50%] bg-black/50 blur-md"
animate={reduce ? undefined : { scaleX: [1, 0.8, 1], opacity: [0.8, 0.45, 0.8] }}
transition={loop}
/>
</div>
);
}
1. Install the dependency.
npm i motion2. Paste the Code tab into
components/ui/floating-card.tsx. The styles are Tailwind CSS v4 classes.3. Use it. This is the preview above:
app/floating-card-demo.tsx
import { FloatingCard } from "@/components/ui/floating-card"; export default function FloatingCardExample() { return ( <div className="grid h-full place-items-center bg-[#0b0a14] p-6"> <div className="flex w-full max-w-[360px] gap-4"> <div className="flex-1"> <FloatingCard> <p className="font-mono text-[11px] uppercase tracking-[0.2em] text-[#a78bfa]">Uptime</p> <p className="mt-2 text-2xl font-semibold">99.9%</p> </FloatingCard> </div> <div className="flex-1"> <FloatingCard delay={1.2}> <p className="font-mono text-[11px] uppercase tracking-[0.2em] text-[#5eead4]">Users</p> <p className="mt-2 text-2xl font-semibold">12k</p> </FloatingCard> </div> </div> </div> ); }
Props
| Name | Type | Default | What it does |
|---|---|---|---|
| children | ReactNode | — | Card content. |
| distance | number | 12 | How high the card rises, in pixels. |
| duration | number | 4 | Seconds for one rise and fall. |
| delay | number | 0 | Seconds before it starts. |
| className | string | dark violet card | Replaces the default look. |