ui
A set of beautifully-designed, accessible components and a code distribution platform. Works with your favorite frameworks. Open Source. Open Code.
Top Related Projects
A utility-first CSS framework for rapid UI development.
Chakra UI is a component system for building products with speed ⚡️
Material UI: Comprehensive React component library that implements Google's Material Design. Free forever.
An enterprise-class UI design language and React UI library
Storybook is the industry standard workshop for building, documenting, and testing UI components in isolation
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress 💅
Quick Overview
shadcn-ui/ui is a collection of re-usable components built using Radix UI and Tailwind CSS. It provides a set of accessible, customizable, and beautifully designed UI components that can be easily integrated into React applications. The project aims to offer a balance between flexibility and convenience for developers building modern web interfaces.
Pros
- Highly customizable components with Tailwind CSS
- Built on top of Radix UI, ensuring accessibility and robust functionality
- Easy to copy and paste into existing projects
- Regularly updated with new components and improvements
Cons
- Not a traditional npm package, requiring manual integration
- Learning curve for developers unfamiliar with Radix UI or Tailwind CSS
- Limited documentation compared to more established UI libraries
- Some components may require additional setup or configuration
Code Examples
- Button component usage:
import { Button } from "@/components/ui/button"
export function ButtonExample() {
return (
<Button variant="outline" size="lg">
Click me
</Button>
)
}
- Dialog component implementation:
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
export function DialogExample() {
return (
<Dialog>
<DialogTrigger>Open Dialog</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Are you sure?</DialogTitle>
<DialogDescription>
This action cannot be undone.
</DialogDescription>
</DialogHeader>
</DialogContent>
</Dialog>
)
}
- Using the Accordion component:
import {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from "@/components/ui/accordion"
export function AccordionExample() {
return (
<Accordion type="single" collapsible>
<AccordionItem value="item-1">
<AccordionTrigger>Is it accessible?</AccordionTrigger>
<AccordionContent>
Yes. It adheres to the WAI-ARIA design pattern.
</AccordionContent>
</AccordionItem>
</Accordion>
)
}
Getting Started
To use shadcn-ui components in your project:
- Install dependencies:
npm install tailwindcss-animate class-variance-authority clsx tailwind-merge
- Add the component you want to use to your project:
npx shadcn-ui add button
- Import and use the component in your React code:
import { Button } from "@/components/ui/button"
export default function Home() {
return (
<Button>Click me</Button>
)
}
Remember to set up Tailwind CSS in your project and include the necessary configuration for shadcn-ui components.
Competitor Comparisons
A utility-first CSS framework for rapid UI development.
Pros of Tailwind CSS
- More flexible and customizable, allowing for fine-grained control over styles
- Larger community and ecosystem, with extensive documentation and resources
- Can be used with any JavaScript framework or vanilla HTML
Cons of Tailwind CSS
- Steeper learning curve, requiring familiarity with utility-first CSS concepts
- Can lead to verbose class names in HTML, potentially reducing readability
- Requires more setup and configuration compared to pre-built components
Code Comparison
Tailwind CSS:
<button class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
Click me
</button>
shadcn/ui:
import { Button } from "@/components/ui/button"
<Button>Click me</Button>
Summary
Tailwind CSS offers more flexibility and customization but requires more setup and learning. shadcn/ui provides pre-built components for faster development but with less granular control. The choice depends on project requirements and developer preferences.
Chakra UI is a component system for building products with speed ⚡️
Pros of Chakra UI
- More comprehensive and feature-rich component library
- Extensive documentation and community support
- Built-in theme customization and color mode switching
Cons of Chakra UI
- Larger bundle size due to its extensive feature set
- Steeper learning curve for beginners
- Less flexibility in component customization
Code Comparison
Chakra UI:
import { Button, Box } from "@chakra-ui/react"
function MyComponent() {
return (
<Box>
<Button colorScheme="blue">Click me</Button>
</Box>
)
}
shadcn/ui:
import { Button } from "@/components/ui/button"
function MyComponent() {
return (
<div>
<Button variant="default">Click me</Button>
</div>
)
}
The code comparison shows that Chakra UI uses a more opinionated approach with built-in styling props, while shadcn/ui offers a more minimal and customizable setup. Chakra UI's Box
component provides a wrapper with additional styling capabilities, whereas shadcn/ui relies on standard HTML elements. Both libraries offer easy-to-use button components with different styling approaches.
Material UI: Comprehensive React component library that implements Google's Material Design. Free forever.
Pros of Material-UI
- Extensive component library with a wide range of pre-built components
- Strong ecosystem with additional tools, themes, and templates
- Comprehensive documentation and active community support
Cons of Material-UI
- Larger bundle size due to the extensive component library
- More opinionated design system, which may require more effort to customize
- Steeper learning curve for developers new to the framework
Code Comparison
Material-UI:
import { Button } from '@mui/material';
function MyComponent() {
return <Button variant="contained">Click me</Button>;
}
shadcn/ui:
import { Button } from "@/components/ui/button"
function MyComponent() {
return <Button>Click me</Button>
}
Material-UI uses a more structured approach with predefined variants, while shadcn/ui offers a simpler, more customizable implementation. shadcn/ui's components are typically more lightweight and easier to modify, but may require more manual styling. Material-UI provides a more complete out-of-the-box experience with consistent theming across components, but this can come at the cost of flexibility and bundle size.
An enterprise-class UI design language and React UI library
Pros of Ant Design
- Comprehensive component library with a wide range of pre-built components
- Extensive documentation and community support
- Well-established and battle-tested in production environments
Cons of Ant Design
- Larger bundle size due to the extensive component library
- Less flexibility in customization compared to shadcn/ui's utility-first approach
- Steeper learning curve for developers new to the ecosystem
Code Comparison
Ant Design (Button component):
import { Button } from 'antd';
const MyComponent = () => (
<Button type="primary">Click me</Button>
);
shadcn/ui (Button component):
import { Button } from "@/components/ui/button"
const MyComponent = () => (
<Button variant="default">Click me</Button>
);
Both libraries offer similar component usage, but Ant Design provides more built-in variants and props out of the box, while shadcn/ui focuses on customization through utility classes and Tailwind CSS.
shadcn/ui emphasizes a utility-first approach, allowing for more granular control over styling and easier integration with existing design systems. Ant Design, on the other hand, provides a more opinionated and complete set of components with consistent styling across the library.
Developers should consider their project requirements, team expertise, and desired level of customization when choosing between these two libraries.
Storybook is the industry standard workshop for building, documenting, and testing UI components in isolation
Pros of Storybook
- Comprehensive documentation and component development environment
- Supports multiple frameworks and libraries (React, Vue, Angular, etc.)
- Large ecosystem with numerous addons and integrations
Cons of Storybook
- Steeper learning curve and more complex setup
- Can be overkill for smaller projects or simpler component libraries
- Requires additional build configuration and maintenance
Code Comparison
Storybook component story:
import { Button } from './Button';
export default {
title: 'Example/Button',
component: Button,
};
const Template = (args) => <Button {...args} />;
export const Primary = Template.bind({});
Primary.args = {
primary: true,
label: 'Button',
};
shadcn/ui component usage:
import { Button } from "@/components/ui/button"
export default function Home() {
return (
<Button variant="outline">Button</Button>
)
}
While Storybook provides a dedicated environment for component development and documentation, shadcn/ui offers a more lightweight approach with ready-to-use components. Storybook excels in complex projects and team collaboration, whereas shadcn/ui is ideal for quick implementation and customization of UI components in React applications.
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress 💅
Pros of styled-components
- Offers dynamic styling with JavaScript
- Provides automatic critical CSS injection
- Supports seamless theming and global styles
Cons of styled-components
- Steeper learning curve for developers new to CSS-in-JS
- Potential performance overhead due to runtime styling
- Requires additional setup and configuration
Code Comparison
styled-components:
const Button = styled.button`
background-color: ${props => props.primary ? 'blue' : 'white'};
color: ${props => props.primary ? 'white' : 'blue'};
padding: 10px 20px;
`;
ui:
<Button variant="default">
Button
</Button>
The styled-components example demonstrates dynamic styling based on props, while the ui example uses predefined variants for styling. styled-components offers more flexibility in creating custom styles, but ui provides a more standardized approach with pre-built components.
styled-components is ideal for projects requiring highly customized and dynamic styling, whereas ui is better suited for rapid development with consistent design patterns. The choice between the two depends on project requirements, team expertise, and desired level of customization.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
shadcn/ui
Accessible and customizable components that you can copy and paste into your apps. Free. Open Source. Use this to build your own component library.
Documentation
Visit http://ui.shadcn.com/docs to view the documentation.
Contributing
Please read the contributing guide.
License
Licensed under the MIT license.
Top Related Projects
A utility-first CSS framework for rapid UI development.
Chakra UI is a component system for building products with speed ⚡️
Material UI: Comprehensive React component library that implements Google's Material Design. Free forever.
An enterprise-class UI design language and React UI library
Storybook is the industry standard workshop for building, documenting, and testing UI components in isolation
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress 💅
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot