Skip to content

shadcn components: copy the code into your project with the shadcn CLI

Better Design

Direct answer

shadcn/ui is not a component library you install from npm: the shadcn CLI copies each component's code into your project, so you can edit it directly. You set a project up with npx shadcn@latest init and add components with npx shadcn@latest add.

A hand-drawn browser window with shadcn/ui written in it and a short list of what it does.

What shadcn/ui is

Each fact comes from the sources listed at the end of this page, read on November 12, 2026.

  • shadcn/ui describes itself this way: it is not a component library, it is how you build your component library.
  • shadcn/ui hands you the actual component code, so you change a button by editing the button code directly.
  • The init command installs dependencies, adds the cn util and configures CSS variables for the project.
  • npx shadcn@latest init sets up an existing project, and the --name option creates a new one.
  • init supports the templates next, vite, start, react-router, laravel and astro.
  • npx shadcn@latest add [component] adds components and their dependencies to your project.
  • The add command has a --dry-run option that previews changes without writing files.
  • You can use the shadcn CLI to run your own registry and distribute components, hooks, pages, config, rules and other files.
  • The registry works with any project type and framework, not only React.
  • Theming uses CSS variables such as background, foreground and primary, set by tailwind.cssVariables in components.json, which is true by default.
  • The shadcn MCP server lets AI assistants browse, search and install items from registries, and npx shadcn@latest mcp init --client claude sets it up for Claude Code.

The shadcn CLI commands you use most

init
What it does

Installs dependencies, adds the cn util, configures CSS variables

Example

npx shadcn@latest init

add
What it does

Adds components and their dependencies

Example

npx shadcn@latest add [component]

view
What it does

Shows registry items before you install them

Example

npx shadcn@latest view button card dialog

search
What it does

Searches items in one or more registries

Example

npx shadcn@latest search @shadcn -q "button"

build
What it does

Generates registry JSON files from registry.json

Example

npx shadcn@latest build

Get started with shadcn/ui

  • Run npx shadcn@latest init in your project.
  • Preview a component with npx shadcn@latest view button.
  • Add it with npx shadcn@latest add button.
  • Edit the component file in your project to change how it looks or behaves.
  • Change colors by overriding the CSS variables under :root and .dark in your CSS file.

shadcn/ui in four steps

The four steps, in the order you take them.

A hand-drawn four-step path for shadcn/ui: Run init, View a component, Add it, Edit the code.
  1. Step 1: Run init
  2. Step 2: View a component
  3. Step 3: Add it
  4. Step 4: Edit the code

Caveats shadcn/ui states

  • Because the code lives in your project, upstream fixes reach you only through dependencies such as @base-ui/react; the top layer stays yours to update.
  • Registry names passed to search must start with @.
  • Dark mode works by overriding the same tokens inside a .dark selector, so define each token twice.
  • The CLI cannot update ~/.codex/config.toml, so Codex users add the shadcn MCP server configuration by hand.

Steal this workflow

Run this guide in your own assistant. The prompt carries the guide link and the workflow summary, so the assistant can adapt it to your project.

Read the guide "shadcn components: copy the code into your project with the shadcn CLI" at https://better-design.com/blog/shadcn-components and help me apply it to my project.

shadcn/ui is not a component library you install from npm: the shadcn CLI copies each component's code into your project, so you can edit it directly. You set a project up with npx shadcn@latest init and add components with npx shadcn@latest add.

Start by asking what I am building and which tools I use. Then walk me through the workflow step by step, adapted to my answers.

Claude and ChatGPT open with the prompt filled in. Gemini copies the prompt to your clipboard first, so paste it when the app opens.

Questions

Is shadcn/ui an npm package?

No. shadcn/ui gives you the component code. The shadcn CLI copies it into your project, and you edit it there.

How do I add a shadcn component?

Run npx shadcn@latest init once, then npx shadcn@latest add followed by the component name, such as button.

Does shadcn have an MCP server?

Yes. The shadcn MCP server lets an AI assistant browse, search and install registry items. For Claude Code, run npx shadcn@latest mcp init --client claude and restart Claude Code.

Where these shadcn/ui facts come from

Each fact comes from the pages listed here, read on November 12, 2026. Products change, so check those pages for the current version.

Build the interface in your own code instead

A coding agent such as Claude Code, Cursor or Codex can build your interface in your own code. Better Design gives that agent a design system, interface principles and review rules, so the result looks designed.