DeveloperBreeze

ShadCN Cheatsheet

Initial Setup

# Install shadcn/ui CLI
npx shadcn-ui@latest init

During 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 input

Multiple components:

npx shadcn-ui@latest add button card input

Popular Components

ComponentCommand
Buttonnpx shadcn-ui@latest add button
Inputnpx shadcn-ui@latest add input
Dialognpx shadcn-ui@latest add dialog
Cardnpx shadcn-ui@latest add card
Tooltipnpx shadcn-ui@latest add tooltip
AlertDialognpx shadcn-ui@latest add alert-dialog
Dropdown Menunpx shadcn-ui@latest add dropdown-menu
Tabsnpx shadcn-ui@latest add tabs
Avatarnpx shadcn-ui@latest add avatar
Badgenpx shadcn-ui@latest add badge
Accordionnpx shadcn-ui@latest add accordion
Selectnpx shadcn-ui@latest add select
Switchnpx shadcn-ui@latest add switch
Toastnpx shadcn-ui@latest add toast
Skeletonnpx 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 theme

Updating Components

npx shadcn-ui@latest add [component] --overwrite

Testing Setup

ShadCN doesn’t include tests by default. Use:

  • @testing-library/react
  • vitest or jest

Example:

npm install --save-dev @testing-library/react @testing-library/jest-dom

Folder Structure (Recommended)

components/

 ui/           # All ShadCN UI components
    button.tsx
    card.tsx
    ...
 shared/       # Your own custom UI components
 layout/       # Layout wrappers

Useful Commands Summary

ActionCommand
Init Projectnpx shadcn-ui@latest init
Add Componentnpx shadcn-ui@latest add [component]
Add Themenpx shadcn-ui@latest add theme
Overwrite Componentnpx shadcn-ui@latest add [component] --overwrite
Add Multiple Componentsnpx shadcn-ui@latest add button card tooltip

Docs & More

Related Posts

More content you might like

Discussion 0

Please sign in to join the discussion.

No comments yet. Be the first to share your thoughts!