shadcn ui examples source code

Shadcn UI Source Code Examples

By David Robinson
AD

If you're a developer seeking to enhance your understanding and usage of shadcn UI library with examples, you've come to the right place. Shadcn UI is a collection of beautiful, provably production-ready React UI components that are composable, customizable, and accessible. Let's delve into some practical examples and explore their source code.

Before we dive into the examples, ensure you have Node.js and npm installed. Then, install shadcn UI via npm using the command: `npm install @shadcn/ui`. Now, let's get started with our first main topic: components.

Shadcn UI Components

Shadcn UI offers a wide array of components, ranging from buttons and cards to modals and accordions. Each component is designed with simplicity and extensibility in mind.

AD
Beautiful themes for shadcn/ui — tweakcn | Theme Editor & Generator
Beautiful themes for shadcn/ui — tweakcn | Theme Editor & Generator
The Foundation for your Design System - shadcn/ui
The Foundation for your Design System - shadcn/ui
11+ Best Open Source Shadcn Dashboard Templates for 2026
11+ Best Open Source Shadcn Dashboard Templates for 2026

Let's explore two essential components: the Button and the Card.

Button

The Button component is a fundamental part of any UI library. Shadcn UI's Button component is simple, customizable, and supports different variants like primary, secondary, and destructive.

shadcn/ui Obsidian App, Dark Mode User Interface, Dark Theme Coding Interface, Obsidian Daily Notes, Google Dark Mode Interface, Notion Dashboard Dark Mode, Dark Theme Spotify Interface, Dark Mode Spotify Interface, Dark Mode Terminal Interface
shadcn/ui Obsidian App, Dark Mode User Interface, Dark Theme Coding Interface, Obsidian Daily Notes, Google Dark Mode Interface, Notion Dashboard Dark Mode, Dark Theme Spotify Interface, Dark Mode Spotify Interface, Dark Mode Terminal Interface
Shadows in UI design: Tips & Tricks
Shadows in UI design: Tips & Tricks
Shadcn/ui Design System
Shadcn/ui Design System

Here's an example of a primary button:

<Button>Button</Button>

The source code for the Button component in shadcn UI can be found at https://github.com/shadcn-ui/ui/blob/main/src/components/button.tsx. It's well-documented and easy to understand.

AD

Card

Here's a simple Card example:

<Card>
  <CardHeader>Card Header</CardHeader>
  <CardContent>Card Content</CardContent>
  <CardFooter>Card Footer</CardFooter>
</Card>

The Card component's source code can be found at https://github.com/shadcn-ui/ui/blob/main/src/components/card.tsx.

Theming and Styling

Shadcn UI supports theming out of the box, making it easy to customize the look and feel of your application. It also supports the use of class names and ids for specific styling.

Let's explore two aspects of theming: color and typography.

Color

Shadcn UI uses the tailwindcss color palette, providing a wide range of colors for your components. You can customize these colors using the theme.extend function in your theme file.

Here's an example of extending the theme to include a new color:

{
  extend: {
    colors: {
      'my-color': '#F00',
    },
  },
}

The color is now available for use in your components: `bg-my-color`.

Typography

Shadcn UI supports customizing fonts and font sizes using the theme.fontFamily and theme.fontSize properties. You can also use the `@tailwindcss/typography` plugin for advanced typography customization.

Here's how you can extend the default font families:

{
  extend: {
    fontFamily: {
      'my-font': ['rial', 'sans-serif'],
    },
  },
}

Now, you can use the new font family in your components: `font-my-font`.

The shadcn UI library is designed to be intuitive and extensible, helping you build beautiful, responsive user interfaces quickly. Whether you're a seasoned developer or just starting, shadcn UI's examples and source code provide valuable insights into creating production-ready React components. Happy coding!

12 shadcn/ui Pro Tips to Write Cleaner, Faster React Code
12 shadcn/ui Pro Tips to Write Cleaner, Faster React Code
Pricing - Shadcnblocks.com
Pricing - Shadcnblocks.com
Shadcn/ui 2025 Guide | Modern UI Components for Developers
Shadcn/ui 2025 Guide | Modern UI Components for Developers
shadcn/ui | Are.na
shadcn/ui | Are.na
the 4 css box shadow effects in adobe
the 4 css box shadow effects in adobe
shadcn/ui kit for Figma, Pro Blocks & Templates
shadcn/ui kit for Figma, Pro Blocks & Templates
Shadcn Admin Dashboard Templates – Shadcnuikit.com
Shadcn Admin Dashboard Templates – Shadcnuikit.com
AD