✨ What Makes shadcn/ui Different?
When building React applications, developers often use component libraries to avoid creating buttons, forms, dialogs, dropdowns, and other UI elements from scratch.
Traditional component libraries provide pre-built components through installed npm packages.
For example:
Chakra UI
Material UI
You install the library, import its components, and customize them using the APIs provided by that library.
But what if you want complete control over the component source code?
What if you want to customize a dialog, modify its internal behavior, or change its styling without being restricted by a library’s exposed APIs?
This is where shadcn/ui takes a different approach.
Instead of treating components as a dependency that you simply import, shadcn/ui provides a collection of reusable components that you add directly to your project.
You own the source code and can modify it according to your requirements.
This makes shadcn/ui an interesting choice for developers who want flexibility, customization, and control over their UI architecture.
🎯 What Is shadcn/ui?
shadcn/ui is a collection of beautifully designed, accessible, and customizable components that you can copy into your React application and own.
It is built around technologies such as:
React
Tailwind CSS
Radix UI
TypeScript
Lucide icons
Unlike traditional component libraries, shadcn/ui does not work primarily by providing a large set of components that remain inside an installed package.
Instead, its CLI adds component source files to your project.
For example, when you add a Button component, its source code is placed inside your project, typically under:
src/
└── components/
└── ui/
└── button.tsxYou can then customize that component directly.
👉 Key Features of shadcn/ui
1. Copy-and-Own Components
Components are added to your project, allowing you to modify their implementation.
2. Tailwind CSS Integration
Uses utility classes for styling and customization.
3. Accessible Components
Uses accessible component primitives, including Radix UI for many interactive components.
4. Customization
You have direct access to the component source code.
5. Modern UI Design
Provides clean, consistent components for modern web applications.
6. CLI-Based Installation
You can add only the components your application needs instead of importing an entire component collection.
Official website: shadcn/ui Official Website.
🧠 Understanding shadcn/ui Architecture
To understand why shadcn/ui is different, let’s look at its architecture.
Let's understand the important building blocks.
A. Component Source Code
When you add a component using the shadcn CLI, its source code is generated inside your application.
For example:
npx shadcn@latest add buttonThis adds the Button component to your project.
You can then import it:
import { Button } from "@/components/ui/button";
function App() {
return (
<Button>
Submit
</Button>
);
}
export default App;The important difference is that you can open button.tsx, inspect its implementation, and modify it.
You are not limited to the public APIs of an installed UI component package.
B. Tailwind CSS
Tailwind CSS is a utility-first CSS framework.
Instead of writing separate CSS classes for every element, you apply utility classes directly in your markup.
For example, traditional CSS:
.primary-button {
background-color: #2563eb;
color: white;
padding: 12px 20px;
border-radius: 8px;
}With Tailwind CSS:
<button class="bg-blue-600 text-white px-5 py-3 rounded-lg">
Submit
</button>shadcn/ui uses Tailwind CSS classes to style its components.
This gives developers direct control over spacing, colors, typography, borders, and responsive behavior.
C. UI Primitives
This is another important part of the architecture.
Interactive components such as dialogs, dropdowns, popovers, and menus require more than visual styling.
They need functionality such as:
Keyboard navigation
Focus management
Open and close behavior
Accessibility attributes
Interaction handling
shadcn/ui builds components using underlying UI primitives.
An important current-version distinction: The current shadcn CLI supports multiple component bases, including Base UI, Radix UI, and React Aria. Base UI is the default for current configurations. Radix UI remains an important option and is widely associated with earlier shadcn/ui implementations.
⚙️ Setting Up shadcn/ui in a React Project
Let’s implement shadcn/ui in a React application.
For this tutorial, we’ll use:
React
Vite
TypeScript
Tailwind CSS
shadcn/ui
Step 1: Create a React application
npm create vite@latest shadcn-demo -- --template react-tsNavigate to the project:
cd shadcn-demoInstall dependencies:
npm installStep 2: Initialize shadcn/ui
Run:
npx shadcn@latest initThe CLI initializes the project configuration and installs the required dependencies.
It also configures important files and styling settings.
Step 3: Add a Button component
npx shadcn@latest add buttonThis generates the Button component in your project.
A typical component structure looks like this:
src/
├── components/
│ └── ui/
│ └── button.tsx
├── lib/
│ └── utils.ts
├── App.tsx
├── main.tsx
└── index.cssStep 4: Use the Button component
Open App.tsx:
import { Button } from "@/components/ui/button";
function App() {
return (
<div className="p-6">
<Button>
Click Me
</Button>
</div>
);
}
export default App;That’s it! You now have a reusable Button component in your React application.
Why is this approach useful?
You can use the generated component immediately, but you can also modify its source code whenever your application requires different behavior or styling.
🧱 Working with shadcn/ui Components
Let’s explore some commonly used components.
A. Button Component
Buttons are used for actions such as submitting forms, saving records, deleting data, and navigating between screens.
import { Button } from "@/components/ui/button";
function ButtonExample() {
return (
<div className="flex gap-4">
<Button>Primary</Button>
<Button variant="outline">
Secondary
</Button>
<Button variant="destructive">
Delete
</Button>
<Button variant="ghost">
Cancel
</Button>
</div>
);
}You can customize button variants and styling by modifying the component implementation.
B. Card Component
Cards are useful for displaying related information.
import {
Card,
CardContent,
CardHeader,
CardTitle,
CardDescription
} from "@/components/ui/card";
function UserCard() {
return (
<Card className="max-w-sm">
<CardHeader>
<CardTitle>John Doe</CardTitle>
<CardDescription>
Senior Software Engineer
</CardDescription>
</CardHeader>
<CardContent>
Working with React and TypeScript.
</CardContent>
</Card>
);
}C. Input Component
Input components help developers build forms.
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
function LoginForm() {
return (
<div className="space-y-4">
<div>
<Label htmlFor="email">
Email Address
</Label>
<Input
id="email"
type="email"
placeholder="Enter your email"
/>
</div>
<div>
<Label htmlFor="password">
Password
</Label>
<Input
id="password"
type="password"
placeholder="Enter your password"
/>
</div>
</div>
);
}D. Dialog Component
Dialogs are useful for confirmations, forms, and displaying additional information.
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
DialogDescription,
DialogTrigger
} from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
function ConfirmDialog() {
return (
<Dialog>
<DialogTrigger asChild>
<Button>Open Dialog</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>
Confirm Action
</DialogTitle>
<DialogDescription>
Are you sure you want to continue?
</DialogDescription>
</DialogHeader>
<Button>Confirm</Button>
</DialogContent>
</Dialog>
);
}The Dialog component handles important interaction behavior through its underlying primitive, while you control its appearance through Tailwind classes.
🛠️ Customization: The Biggest Advantage of shadcn/ui
One of the biggest advantages of shadcn/ui is component ownership.
Imagine you have a standard Button component, but your application requires:
A custom loading state.
A special icon.
A unique animation.
Different padding and border radius.
Application-specific behavior.
With a traditional component library, you generally customize components through the APIs exposed by the library.
With shadcn/ui, you can directly modify the generated component.
For example:
import { Button } from "@/components/ui/button";
function CustomButton() {
return (
<Button
className="rounded-full px-8 shadow-lg"
>
Get Started
</Button>
);
}You can also modify the underlying Button component to introduce your own variants.
The important takeaway: You are not just consuming a component. You are maintaining the component’s source code as part of your application.
🎨 Theming in shadcn/ui
A consistent design system is important for enterprise applications.
shadcn/ui uses CSS variables and Tailwind CSS to manage design tokens.
For example:
:root {
--background: 0 0% 100%;
--foreground: 222.2 84% 4.9%;
--primary: 221.2 83.2% 53.3%;
--primary-foreground: 210 40% 98%;
--border: 214.3 31.8% 91.4%;
--radius: 0.5rem;
}These variables represent design values used throughout the application.
You can define different values for dark mode:
.dark {
--background: 222.2 84% 4.9%;
--foreground: 210 40% 98%;
--primary: 217.2 91.2% 59.8%;
--primary-foreground: 222.2 47.4% 11.2%;
}Your components can then consume these theme values instead of using hardcoded colors everywhere.
Why is this useful?
If your application’s primary color changes, you can update the theme variables instead of modifying individual components.
This makes it easier to maintain a consistent design system across multiple pages.
Note: The current shadcn setup uses CSS variables and Tailwind CSS v4’s CSS-first configuration. The exact token format depends on the selected style and generated configuration.
⭐ Best Practices When Using shadcn/ui
Here are some best practices for real-world React applications.
Create a reusable component structure: Keep shared UI components organized under a common directory.
Establish design tokens: Define consistent colors, typography, spacing, and border radii.
Avoid unnecessary modifications: Customize components when there is a genuine application requirement.
Keep components reusable: Avoid duplicating the same UI implementation across multiple pages.
Review component updates: Compare upstream changes before replacing your customized source files.
Maintain accessibility: Don’t remove keyboard navigation, focus handling, or accessible labels while customizing components.
Use consistent styling conventions: Establish a common approach for Tailwind CSS classes across your application.
🏁 Conclusion
shadcn/ui introduces a different approach to building React interfaces.
Instead of treating UI components as external dependencies, it allows developers to bring component source code directly into their applications and customize it.
Its combination of Tailwind CSS, accessible UI primitives, and direct component ownership provides flexibility for building modern React applications.
However, this flexibility also comes with responsibility. Developers must maintain their components, review updates, and establish consistent design practices.
In simple terms:
Chakra UI focuses on providing a ready-to-use component library.
shadcn/ui focuses on providing components that developers can own and customize.
Both approaches have their strengths, and the right choice depends on your project’s requirements.


