Initial Setup
# Install shadcn/ui CLI
npx shadcn-ui@latest initDuring setup, you'll choose:
- Framework (Next.js, Vite, etc.)
- Tailwind CSS config
- Components directory (default:
components) - Alias for imports (optional)
Installing Components
npx shadcn-ui@latest add [component]Example:
npx shadcn-ui@latest add button
npx shadcn-ui@latest add card
npx shadcn-ui@latest add inputMultiple components:
npx shadcn-ui@latest add button card inputPopular Components
| Component | Command |
|---|---|
| Button | npx shadcn-ui@latest add button |
| Input | npx shadcn-ui@latest add input |
| Dialog | npx shadcn-ui@latest add dialog |
| Card | npx shadcn-ui@latest add card |
| Tooltip | npx shadcn-ui@latest add tooltip |
| AlertDialog | npx shadcn-ui@latest add alert-dialog |
| Dropdown Menu | npx shadcn-ui@latest add dropdown-menu |
| Tabs | npx shadcn-ui@latest add tabs |
| Avatar | npx shadcn-ui@latest add avatar |
| Badge | npx shadcn-ui@latest add badge |
| Accordion | npx shadcn-ui@latest add accordion |
| Select | npx shadcn-ui@latest add select |
| Switch | npx shadcn-ui@latest add switch |
| Toast | npx shadcn-ui@latest add toast |
| Skeleton | npx shadcn-ui@latest add skeleton |
Theming
Change Theme Colors
Update Tailwind config:
theme: {
extend: {
colors: {
primary: 'hsl(var(--primary))',
// etc.
}
}
}Modify Default Theme
Edit components/theme.ts or tailwind.config.js
Customization
Change Component Output Directory
npx shadcn-ui@latest init
# Select or type a new directory (e.g. `ui` or `components/ui`)Customize Tailwind Colors
npx shadcn-ui@latest add themeUpdating Components
npx shadcn-ui@latest add [component] --overwriteTesting Setup
ShadCN doesn’t include tests by default. Use:
@testing-library/reactvitestorjest
Example:
npm install --save-dev @testing-library/react @testing-library/jest-domFolder Structure (Recommended)
components/
ui/ # All ShadCN UI components
button.tsx
card.tsx
...
shared/ # Your own custom UI components
layout/ # Layout wrappersUseful Commands Summary
| Action | Command |
|---|---|
| Init Project | npx shadcn-ui@latest init |
| Add Component | npx shadcn-ui@latest add [component] |
| Add Theme | npx shadcn-ui@latest add theme |
| Overwrite Component | npx shadcn-ui@latest add [component] --overwrite |
| Add Multiple Components | npx shadcn-ui@latest add button card tooltip |
Docs & More
- Official Docs: https://ui.shadcn.com
- GitHub: https://github.com/shadcn/ui