FreeInteractive
Animated Tabs
Use this component for docs, pricing toggles, product demos, settings screens, and feature comparisons.
ReactTailwind CSSMotionTabs
Preview content goes here.
Overview
A tab switcher with a shared animated active background.
Framework
React
Styling
Tailwind CSS
Animation
Motion
Create a Vite React project
bashnpm create vite@latest my-ui-app -- --template react-ts
cd my-ui-app
npm installCreate a Next.js project
bashnpx create-next-app@latest my-ui-app --typescript --tailwind --eslint
cd my-ui-appAdd Tailwind CSS to Vite
bashnpm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -pInstall dependencies
bashnpm install framer-motionUsage
tsx<AnimatedTabs />Animated Tabs.tsx
tsx"use client";
import { useState } from "react";
import { motion } from "framer-motion";
const tabs = ["Preview", "Code", "Setup"];
export function AnimatedTabs() {
const [active, setActive] = useState("Preview");
return (
<div className="w-full max-w-md rounded-xl border border-white/10 bg-zinc-950 p-2 text-white">
<div className="relative grid grid-cols-3 gap-1">
{tabs.map((tab) => (
<button key={tab} type="button" onClick={() => setActive(tab)} className="relative z-10 rounded-lg px-3 py-2 text-sm">
{tab}
{active === tab && <motion.span layoutId="active-tab" className="absolute inset-0 -z-10 rounded-lg bg-lime-300" />}
</button>
))}
</div>
<p className="p-5 text-center text-sm text-zinc-400">{active} content goes here.</p>
</div>
);
}