Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Add, manage, and compose shadcn/ui components with correct patterns, styling, and CLI workflows.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
customization.md
1# Customization & Theming23Components reference semantic CSS variable tokens. Change the variables to change every component.45## Contents67- How it works (CSS variables → Tailwind utilities → components)8- Color variables and OKLCH format9- Dark mode setup10- Changing the theme (presets, CSS variables)11- Adding custom colors (Tailwind v3 and v4)12- Border radius13- Customizing components (variants, className, wrappers)14- Checking for updates1516---1718## How It Works19201. CSS variables defined in `:root` (light) and `.dark` (dark mode).212. Tailwind maps them to utilities: `bg-primary`, `text-muted-foreground`, etc.223. Components use these utilities — changing a variable changes all components that reference it.2324---2526## Color Variables2728Every color follows the `name` / `name-foreground` convention. The base variable is for backgrounds, `-foreground` is for text/icons on that background.2930| Variable | Purpose |31| -------------------------------------------- | -------------------------------- |32| `--background` / `--foreground` | Page background and default text |33| `--card` / `--card-foreground` | Card surfaces |34| `--primary` / `--primary-foreground` | Primary buttons and actions |35| `--secondary` / `--secondary-foreground` | Secondary actions |36| `--muted` / `--muted-foreground` | Muted/disabled states |37| `--accent` / `--accent-foreground` | Hover and accent states |38| `--destructive` / `--destructive-foreground` | Error and destructive actions |39| `--border` | Default border color |40| `--input` | Form input borders |41| `--ring` | Focus ring color |42| `--chart-1` through `--chart-5` | Chart/data visualization |43| `--sidebar-*` | Sidebar-specific colors |44| `--surface` / `--surface-foreground` | Secondary surface |4546Colors use OKLCH: `--primary: oklch(0.205 0 0)` where values are lightness (0–1), chroma (0 = gray), and hue (0–360).4748---4950## Dark Mode5152Class-based toggle via `.dark` on the root element. In Next.js, use `next-themes`:5354```tsx55import { ThemeProvider } from "next-themes"5657<ThemeProvider attribute="class" defaultTheme="system" enableSystem>58{children}59</ThemeProvider>60```6162---6364## Changing the Theme6566```bash67# Apply a preset code from ui.shadcn.com.68npx shadcn@latest apply --preset a2r6bw6970# Positional shorthand also works.71npx shadcn@latest apply a2r6bw7273# Switch to a named preset and overwrite existing components.74npx shadcn@latest apply --preset nova7576# Preserve existing components instead.77npx shadcn@latest init --preset nova --force --no-reinstall7879# Use a custom theme URL.80npx shadcn@latest apply --preset "https://ui.shadcn.com/init?base=radix&style=nova&theme=blue&..."81```8283Or edit CSS variables directly in `globals.css`.8485---8687## Adding Custom Colors8889Add variables to the file at `tailwindCssFile` from `npx shadcn@latest info` (typically `globals.css`). Never create a new CSS file for this.9091```css92/* 1. Define in the global CSS file. */93:root {94--warning: oklch(0.84 0.16 84);95--warning-foreground: oklch(0.28 0.07 46);96}97.dark {98--warning: oklch(0.41 0.11 46);99--warning-foreground: oklch(0.99 0.02 95);100}101```102103```css104/* 2a. Register with Tailwind v4 (@theme inline). */105@theme inline {106--color-warning: var(--warning);107--color-warning-foreground: var(--warning-foreground);108}109```110111When `tailwindVersion` is `"v3"` (check via `npx shadcn@latest info`), register in `tailwind.config.js` instead:112113```js114// 2b. Register with Tailwind v3 (tailwind.config.js).115module.exports = {116theme: {117extend: {118colors: {119warning: "oklch(var(--warning) / <alpha-value>)",120"warning-foreground":121"oklch(var(--warning-foreground) / <alpha-value>)",122},123},124},125}126```127128```tsx129// 3. Use in components.130<div className="bg-warning text-warning-foreground">Warning</div>131```132133---134135## Border Radius136137`--radius` controls border radius globally. Components derive values from it (`rounded-lg` = `var(--radius)`, `rounded-md` = `calc(var(--radius) - 2px)`).138139---140141## Customizing Components142143See also: [rules/styling.md](./rules/styling.md) for Incorrect/Correct examples.144145Prefer these approaches in order:146147### 1. Built-in variants148149```tsx150<Button variant="outline" size="sm">151Click152</Button>153```154155### 2. Tailwind classes via `className`156157```tsx158<Card className="mx-auto max-w-md">...</Card>159```160161### 3. Add a new variant162163Edit the component source to add a variant via `cva`:164165```tsx166// components/ui/button.tsx167warning: "bg-warning text-warning-foreground hover:bg-warning/90",168```169170### 4. Wrapper components171172Compose shadcn/ui primitives into higher-level components:173174```tsx175export function ConfirmDialog({ title, description, onConfirm, children }) {176return (177<AlertDialog>178<AlertDialogTrigger asChild>{children}</AlertDialogTrigger>179<AlertDialogContent>180<AlertDialogHeader>181<AlertDialogTitle>{title}</AlertDialogTitle>182<AlertDialogDescription>{description}</AlertDialogDescription>183</AlertDialogHeader>184<AlertDialogFooter>185<AlertDialogCancel>Cancel</AlertDialogCancel>186<AlertDialogAction onClick={onConfirm}>Confirm</AlertDialogAction>187</AlertDialogFooter>188</AlertDialogContent>189</AlertDialog>190)191}192```193194---195196## Checking for Updates197198```bash199npx shadcn@latest add button --diff200```201202To preview exactly what would change before updating, use `--dry-run` and `--diff`:203204```bash205npx shadcn@latest add button --dry-run # see all affected files206npx shadcn@latest add button --diff button.tsx # see the diff for a specific file207```208209See [Updating Components in SKILL.md](./SKILL.md#updating-components) for the full smart merge workflow.210