
Tailwind Design System
- 2 installs
- 318 repo stars
- Updated June 22, 2026
- giuseppe-trisciuoglio/developer-kit-claude-code
This is a copy of tailwind-design-system by giuseppe-trisciuoglio - installs and ranking accrue to the original listing.
Helps with frontend development tasks.
About
tailwind-design-system is a Claude Code skill for frontend development. It helps solo builders move faster with AI-assisted development.
- tailwind-design-system
- Frontend Development
- AI-coding skill
Tailwind Design System by the numbers
- 2 all-time installs (skills.sh)
- Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/giuseppe-trisciuoglio/developer-kit-claude-code --skill tailwind-design-systemAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 2 |
|---|---|
| repo stars | ★ 318 |
| Last updated | June 22, 2026 |
| Repository | giuseppe-trisciuoglio/developer-kit-claude-code ↗ |
What it does
Helps with frontend development tasks.
Files
Tailwind CSS & shadcn/ui Design System
Overview
Expert guide for creating and managing a centralized Design System using Tailwind CSS (v4.1+) and shadcn/ui. This skill provides structured workflows for defining design tokens, configuring themes with CSS variables, and building a consistent UI component library based on shadcn/ui primitives.
Relationship with other skills:
- tailwind-css-patterns covers utility-first styling, responsive design, and general Tailwind CSS usage
- shadcn-ui covers individual component installation, configuration, and implementation
- This skill focuses on the system-level orchestration: design tokens, theming infrastructure, component wrapping patterns, and ensuring consistency across the entire application
When to Use
- Setting up a new design system from scratch with Tailwind CSS and shadcn/ui
- Defining design tokens (colors, typography, spacing, radius, shadows) as CSS variables
- Configuring
globals.csswith a centralized theming system (light/dark mode) - Wrapping shadcn/ui components into design system primitives with enforced constraints
- Building a token-driven component library for consistent UI
- Migrating from a JavaScript-based Tailwind config to CSS-first configuration (v4.1+)
- Establishing color palettes with oklch format for perceptual uniformity
- Creating multi-theme support beyond light/dark (e.g., brand themes)
Instructions
Step 1: Initialize Design System Configuration
Run these commands to set up the project:
# Check if Tailwind is installed
npx tailwindcss --version
# For Tailwind v4 (recommended)
npx @tailwindcss/vite@latest init # or: npm install -D tailwindcss @tailwindcss/vite
# Initialize shadcn/ui CLI
npx shadcn@latest init
# Install core shadcn/ui components
npx shadcn@latest add button card input -yValidation checkpoint: After setup, verify with:
ls src/components/ui/ # Should list installed components
cat src/app/globals.css # Should contain @tailwind directivesStep 2: Define Design Tokens
Create src/app/globals.css with your design tokens:
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer base {
:root {
/* Brand Colors */
--primary: oklch(0.55 0.18 250);
--primary-foreground: oklch(0.985 0 0);
/* Semantic Colors */
--background: oklch(0.99 0 0);
--foreground: oklch(0.15 0 0);
--secondary: oklch(0.96 0.01 250);
--secondary-foreground: oklch(0.20 0 0);
/* Validation: all colors must have foreground pair */
--destructive: oklch(0.55 0.22 25);
--destructive-foreground: oklch(0.985 0 0);
}
.dark {
--primary: oklch(0.65 0.20 250);
--background: oklch(0.14 0 0);
--foreground: oklch(0.97 0 0);
--secondary: oklch(0.25 0.02 250);
}
}Validation checkpoint: Verify tokens are valid CSS:
grep -E "^[[:space:]]*--[a-z-]+:" src/app/globals.css | wc -l
# Should return count of defined tokens (e.g., 10+)Step 3: Configure Theming Infrastructure
Bridge CSS variables to Tailwind utilities (Tailwind v4.1+):
@theme inline {
--color-primary: var(--primary);
--color-primary-foreground: var(--primary-foreground);
--color-background: var(--background);
--color-foreground: var(--foreground);
}Add dark mode class toggle in components/providers/theme-provider.tsx:
import { useEffect } from "react";
export function ThemeProvider({ children }: { children: React.ReactNode }) {
useEffect(() => {
const isDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
document.documentElement.classList.toggle("dark", isDark);
}, []);
return <>{children}</>;
}Validation checkpoint: Test dark mode:
document.documentElement.classList.contains("dark") // in browser consoleStep 4: Wrap shadcn/ui Components
Create src/components/ds/Button.tsx:
import { Button as ShadcnButton } from "@/components/ui/button";
type DSVariant = "primary" | "secondary" | "destructive" | "ghost";
const variantMap: Record<DSVariant, "default" | "secondary" | "destructive" | "ghost"> = {
primary: "default", secondary: "secondary",
destructive: "destructive", ghost: "ghost",
};
export function Button({ variant = "primary", ...props }: { variant?: DSVariant } & React.ComponentProps<typeof ShadcnButton>) {
return <ShadcnButton variant={variantMap[variant]} {...props} />;
}Validation checkpoint: Verify build passes:
npx tsc --noEmit src/components/ds/Button.tsxStep 5: Validate and Document
Run the token validation script:
REQUIRED=("primary" "primary-foreground" "background" "foreground" "secondary" "secondary-foreground")
for token in "${REQUIRED[@]}"; do
grep -q "$token:" src/app/globals.css || echo "MISSING: --$token"
doneValidation checkpoint: Ensure all shadcn components use DS tokens:
grep -r "bg-primary\|text-primary\|bg-background" src/components/ds/Examples
Adding Custom Tokens
Extend the base tokens in globals.css:
:root {
--warning: oklch(0.84 0.16 84);
--warning-foreground: oklch(0.28 0.07 46);
}
.dark {
--warning: oklch(0.41 0.11 46);
--warning-foreground: oklch(0.99 0.02 95);
}
@theme inline {
--color-warning: var(--warning);
--color-warning-foreground: var(--warning-foreground);
}Usage: <div className="bg-warning text-warning-foreground">Warning</div>
Wrapping shadcn/ui Components as Design System Primitives
See references/component-wrapping.md for complete examples including Button, Text, and Stack primitives with full TypeScript types.
Create constrained design system components that enforce token usage. Inline example:
import { Button as ShadcnButton } from "@/components/ui/button";
export function Button({ variant = "primary", size = "md", ...props }) {
const variantMap = { primary: "default", secondary: "secondary" };
const sizeMap = { sm: "sm", md: "default", lg: "lg" };
return (
<ShadcnButton
variant={variantMap[variant]}
size={sizeMap[size]}
{...props}
/>
);
}Multi-Theme Support
For applications requiring multiple brand themes beyond light/dark:
[data-theme="ocean"] {
--primary: oklch(0.55 0.18 230);
--primary-foreground: oklch(0.985 0 0);
}
[data-theme="forest"] {
--primary: oklch(0.50 0.15 145);
--primary-foreground: oklch(0.985 0 0);
}const [theme, setTheme] = useState("light");
useEffect(() => {
document.documentElement.setAttribute("data-theme", theme);
}, [theme]);Design Token Validation
Verify all required tokens are defined:
#!/bin/bash
REQUIRED=("--background" "--foreground" "--primary" "--primary-foreground")
for token in "${REQUIRED[@]}"; do
grep -q "$token:" src/styles/globals.css || echo "Missing: $token"
doneConstraints and Warnings
- oklch color format: Use oklch for perceptual uniformity. Not all browsers support oklch natively; check compatibility if targeting older browsers
- Token naming: Follow the shadcn/ui convention (
--primary,--primary-foreground) for seamless integration - `@`theme inline vs `@`theme: Use
@theme inlinewhen bridging CSS variables to Tailwind utilities; use@themefor direct token definition - Component wrapping: Keep wrapper components thin. Only add constraints that enforce design system rules; avoid duplicating shadcn/ui logic
- Dark mode: Always define dark mode values for every token in
:root. Missing dark tokens cause visual regressions - CSS variable scoping: Tokens defined in
:rootare global. Use[data-theme]selectors for multi-theme without conflicts - Performance: Avoid excessive CSS custom property chains. Each
var()lookup adds minimal but non-zero overhead - Tailwind v4 vs v3: The
@themedirective and@theme inlineare v4.1+ features. For v3 projects, usetailwind.config.jswiththeme.extend
Best Practices
1. Single source of truth: All design tokens live in globals.css. Never hardcode color values in components 2. Semantic naming: Use purpose-based names (--primary, --destructive) not appearance-based (--blue-500, --red-600) 3. Foreground pairing: Every background token must have a matching -foreground token for contrast compliance 4. Token scale: Define a complete scale for custom palettes (50-950) to provide flexibility 5. Component barrel exports: Export all DS components from a single index.ts for clean imports 6. Accessibility: Ensure all token pairs (background/foreground) meet WCAG AA contrast (4.5:1 for text, 3:1 for large text) 7. Document tokens: Maintain a visual reference of all tokens for the team 8. Consistent spacing: Use Tailwind's spacing scale (gap-2, gap-4, gap-6) through DS components rather than arbitrary values
References
- Tailwind CSS v4 Theme Configuration: https://tailwindcss.com/docs/theme
- Tailwind CSS Functions and Directives: https://tailwindcss.com/docs/functions-and-directives
- shadcn/ui Theming Guide: https://ui.shadcn.com/docs/theming
- shadcn/ui Installation (Manual): https://ui.shadcn.com/docs/installation/manual
- oklch Color Space: https://oklch.com
Wrapping shadcn/ui Components as Design System Primitives
This guide shows how to wrap shadcn/ui components into design system primitives that enforce token usage and provide consistent API.
Button Component
// components/ds/Button.tsx
import { Button as ShadcnButton, type ButtonProps } from "@/components/ui/button";
import { cn } from "@/lib/utils";
type DSButtonVariant = "primary" | "secondary" | "destructive" | "ghost" | "outline";
type DSButtonSize = "sm" | "md" | "lg";
interface DSButtonProps extends Omit<ButtonProps, "variant" | "size"> {
variant?: DSButtonVariant;
size?: DSButtonSize;
}
const variantMap: Record<DSButtonVariant, ButtonProps["variant"]> = {
primary: "default",
secondary: "secondary",
destructive: "destructive",
ghost: "ghost",
outline: "outline",
};
const sizeMap: Record<DSButtonSize, ButtonProps["size"]> = {
sm: "sm",
md: "default",
lg: "lg",
};
export function Button({ variant = "primary", size = "md", className, ...props }: DSButtonProps) {
return (
<ShadcnButton
variant={variantMap[variant]}
size={sizeMap[size]}
className={cn("font-medium transition-colors", className)}
{...props}
/>
);
}Typography Component
// components/ds/Text.tsx
import { cn } from "@/lib/utils";
type TextVariant = "h1" | "h2" | "h3" | "h4" | "body" | "body-sm" | "caption" | "overline";
interface TextProps {
variant?: TextVariant;
as?: keyof JSX.IntrinsicElements;
className?: string;
children: React.ReactNode;
}
const variantStyles: Record<TextVariant, string> = {
h1: "text-4xl font-bold tracking-tight",
h2: "text-3xl font-semibold tracking-tight",
h3: "text-2xl font-semibold",
h4: "text-xl font-medium",
body: "text-base leading-relaxed",
"body-sm": "text-sm leading-relaxed",
caption: "text-xs text-muted-foreground",
overline: "text-xs font-semibold uppercase tracking-widest text-muted-foreground",
};
const defaultElements: Record<TextVariant, keyof JSX.IntrinsicElements> = {
h1: "h1",
h2: "h2",
h3: "h3",
h4: "h4",
body: "p",
"body-sm": "p",
caption: "span",
overline: "span",
};
export function Text({ variant = "body", as, className, children }: TextProps) {
const Component = as || defaultElements[variant];
return <Component className={cn(variantStyles[variant], className)}>{children}</Component>;
}Stack Layout Component
// components/ds/Stack.tsx
import { cn } from "@/lib/utils";
type StackSpacing = "xs" | "sm" | "md" | "lg" | "xl";
interface StackProps {
direction?: "row" | "column";
spacing?: StackSpacing;
align?: "start" | "center" | "end" | "stretch";
justify?: "start" | "center" | "end" | "between" | "around";
className?: string;
children: React.ReactNode;
}
const spacingMap: Record<StackSpacing, string> = {
xs: "gap-1",
sm: "gap-2",
md: "gap-4",
lg: "gap-6",
xl: "gap-8",
};
export function Stack({
direction = "column",
spacing = "md",
align = "stretch",
justify = "start",
className,
children,
}: StackProps) {
return (
<div
className={cn(
"flex",
direction === "row" ? "flex-row" : "flex-col",
spacingMap[spacing],
`items-${align}`,
`justify-${justify}`,
className
)}
>
{children}
</div>
);
}Barrel Export
// components/ds/index.ts
export { Button } from "./Button";
export { Text } from "./Text";
export { Stack } from "./Stack";Design System Directory Structure
src/
├── components/
│ ├── ui/ # Raw shadcn/ui components (auto-generated)
│ │ ├── button.tsx
│ │ ├── card.tsx
│ │ └── ...
│ └── ds/ # Design system primitives (manually curated)
│ ├── Button.tsx # Wrapped button with DS constraints
│ ├── Text.tsx # Typography component
│ ├── Stack.tsx # Layout primitive
│ └── index.ts # Barrel export
├── styles/
│ └── globals.css # Design tokens + theme configuration
└── lib/
└── utils.ts # cn() helperUsage Example
import { Button, Text, Stack } from "@/components/ds";
function Hero() {
return (
<Stack spacing="lg" align="center" className="py-20">
<Text variant="h1">Welcome to our Design System</Text>
<Text variant="body">Consistent, accessible, beautiful UI</Text>
<Stack direction="row" spacing="md">
<Button variant="primary" size="lg">Get Started</Button>
<Button variant="secondary" size="lg">Learn More</Button>
</Stack>
</Stack>
);
}/**
* Complete globals.css Example
* Production-ready design system configuration for Tailwind CSS v4.1+ with shadcn/ui
*/
@import "tailwindcss";
@import "tw-animate-css";
@import "shadcn/tailwind.css";
@custom-variant dark (&:is(.dark *));
/* ============================================
DESIGN TOKENS - CSS Variables
============================================ */
:root {
/* --- Radius --- */
--radius: 0.625rem;
/* --- Brand Colors (custom palette) --- */
--brand-50: oklch(0.97 0.01 250);
--brand-100: oklch(0.93 0.03 250);
--brand-200: oklch(0.87 0.06 250);
--brand-300: oklch(0.78 0.10 250);
--brand-400: oklch(0.68 0.15 250);
--brand-500: oklch(0.58 0.19 250);
--brand-600: oklch(0.50 0.17 250);
--brand-700: oklch(0.42 0.14 250);
--brand-800: oklch(0.35 0.11 250);
--brand-900: oklch(0.27 0.08 250);
--brand-950: oklch(0.20 0.06 250);
/* --- Semantic UI Colors --- */
--background: oklch(1 0 0);
--foreground: oklch(0.145 0 0);
--card: oklch(1 0 0);
--card-foreground: oklch(0.145 0 0);
--popover: oklch(1 0 0);
--popover-foreground: oklch(0.145 0 0);
--primary: oklch(0.205 0 0);
--primary-foreground: oklch(0.985 0 0);
--secondary: oklch(0.97 0 0);
--secondary-foreground: oklch(0.205 0 0);
--muted: oklch(0.97 0 0);
--muted-foreground: oklch(0.556 0 0);
--accent: oklch(0.97 0 0);
--accent-foreground: oklch(0.205 0 0);
--destructive: oklch(0.577 0.245 27.325);
--destructive-foreground: oklch(0.985 0 0);
--border: oklch(0.922 0 0);
--input: oklch(0.922 0 0);
--ring: oklch(0.708 0 0);
/* --- Chart Colors --- */
--chart-1: oklch(0.646 0.222 41.116);
--chart-2: oklch(0.6 0.118 184.704);
--chart-3: oklch(0.398 0.07 227.392);
--chart-4: oklch(0.828 0.189 84.429);
--chart-5: oklch(0.769 0.188 70.08);
/* --- Sidebar Colors --- */
--sidebar: oklch(0.985 0 0);
--sidebar-foreground: oklch(0.145 0 0);
--sidebar-primary: oklch(0.205 0 0);
--sidebar-primary-foreground: oklch(0.985 0 0);
--sidebar-accent: oklch(0.97 0 0);
--sidebar-accent-foreground: oklch(0.205 0 0);
--sidebar-border: oklch(0.922 0 0);
--sidebar-ring: oklch(0.708 0 0);
/* --- Custom Semantic Colors --- */
--success: oklch(0.62 0.17 145);
--success-foreground: oklch(0.985 0 0);
--warning: oklch(0.84 0.16 84);
--warning-foreground: oklch(0.28 0.07 46);
--info: oklch(0.62 0.14 250);
--info-foreground: oklch(0.985 0 0);
/* --- Typography --- */
--font-sans: "Inter", ui-sans-serif, system-ui, sans-serif;
--font-mono: "JetBrains Mono", ui-monospace, monospace;
--font-heading: "Inter", ui-sans-serif, system-ui, sans-serif;
/* --- Shadows (Elevation) --- */
--shadow-xs: 0 1px 2px 0 oklch(0 0 0 / 0.05);
--shadow-sm: 0 1px 3px 0 oklch(0 0 0 / 0.1), 0 1px 2px -1px oklch(0 0 0 / 0.1);
--shadow-md: 0 4px 6px -1px oklch(0 0 0 / 0.1), 0 2px 4px -2px oklch(0 0 0 / 0.1);
--shadow-lg: 0 10px 15px -3px oklch(0 0 0 / 0.1), 0 4px 6px -4px oklch(0 0 0 / 0.1);
--shadow-xl: 0 20px 25px -5px oklch(0 0 0 / 0.1), 0 8px 10px -6px oklch(0 0 0 / 0.1);
/* --- Transitions --- */
--duration-fast: 150ms;
--duration-normal: 250ms;
--duration-slow: 400ms;
--ease-default: cubic-bezier(0.4, 0, 0.2, 1);
--ease-in: cubic-bezier(0.4, 0, 1, 1);
--ease-out: cubic-bezier(0, 0, 0.2, 1);
--ease-bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
/* --- Dark Theme --- */
.dark {
--background: oklch(0.145 0 0);
--foreground: oklch(0.985 0 0);
--card: oklch(0.205 0 0);
--card-foreground: oklch(0.985 0 0);
--popover: oklch(0.269 0 0);
--popover-foreground: oklch(0.985 0 0);
--primary: oklch(0.922 0 0);
--primary-foreground: oklch(0.205 0 0);
--secondary: oklch(0.269 0 0);
--secondary-foreground: oklch(0.985 0 0);
--muted: oklch(0.269 0 0);
--muted-foreground: oklch(0.708 0 0);
--accent: oklch(0.371 0 0);
--accent-foreground: oklch(0.985 0 0);
--destructive: oklch(0.704 0.191 22.216);
--destructive-foreground: oklch(0.985 0 0);
--border: oklch(1 0 0 / 10%);
--input: oklch(1 0 0 / 15%);
--ring: oklch(0.556 0 0);
--chart-1: oklch(0.488 0.243 264.376);
--chart-2: oklch(0.696 0.17 162.48);
--chart-3: oklch(0.769 0.188 70.08);
--chart-4: oklch(0.627 0.265 303.9);
--chart-5: oklch(0.645 0.246 16.439);
--sidebar: oklch(0.205 0 0);
--sidebar-foreground: oklch(0.985 0 0);
--sidebar-primary: oklch(0.488 0.243 264.376);
--sidebar-primary-foreground: oklch(0.985 0 0);
--sidebar-accent: oklch(0.269 0 0);
--sidebar-accent-foreground: oklch(0.985 0 0);
--sidebar-border: oklch(1 0 0 / 10%);
--sidebar-ring: oklch(0.439 0 0);
/* --- Custom Semantic (Dark) --- */
--success: oklch(0.55 0.15 145);
--success-foreground: oklch(0.985 0 0);
--warning: oklch(0.41 0.11 46);
--warning-foreground: oklch(0.99 0.02 95);
--info: oklch(0.50 0.12 250);
--info-foreground: oklch(0.985 0 0);
}
/* ============================================
TAILWIND THEME BRIDGE
Expose CSS variables to Tailwind utilities
============================================ */
@theme inline {
/* Semantic Colors */
--color-background: var(--background);
--color-foreground: var(--foreground);
--color-card: var(--card);
--color-card-foreground: var(--card-foreground);
--color-popover: var(--popover);
--color-popover-foreground: var(--popover-foreground);
--color-primary: var(--primary);
--color-primary-foreground: var(--primary-foreground);
--color-secondary: var(--secondary);
--color-secondary-foreground: var(--secondary-foreground);
--color-muted: var(--muted);
--color-muted-foreground: var(--muted-foreground);
--color-accent: var(--accent);
--color-accent-foreground: var(--accent-foreground);
--color-destructive: var(--destructive);
--color-destructive-foreground: var(--destructive-foreground);
--color-border: var(--border);
--color-input: var(--input);
--color-ring: var(--ring);
/* Chart Colors */
--color-chart-1: var(--chart-1);
--color-chart-2: var(--chart-2);
--color-chart-3: var(--chart-3);
--color-chart-4: var(--chart-4);
--color-chart-5: var(--chart-5);
/* Sidebar */
--color-sidebar: var(--sidebar);
--color-sidebar-foreground: var(--sidebar-foreground);
--color-sidebar-primary: var(--sidebar-primary);
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
--color-sidebar-accent: var(--sidebar-accent);
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
--color-sidebar-border: var(--sidebar-border);
--color-sidebar-ring: var(--sidebar-ring);
/* Custom Semantic */
--color-success: var(--success);
--color-success-foreground: var(--success-foreground);
--color-warning: var(--warning);
--color-warning-foreground: var(--warning-foreground);
--color-info: var(--info);
--color-info-foreground: var(--info-foreground);
/* Brand Palette */
--color-brand-50: var(--brand-50);
--color-brand-100: var(--brand-100);
--color-brand-200: var(--brand-200);
--color-brand-300: var(--brand-300);
--color-brand-400: var(--brand-400);
--color-brand-500: var(--brand-500);
--color-brand-600: var(--brand-600);
--color-brand-700: var(--brand-700);
--color-brand-800: var(--brand-800);
--color-brand-900: var(--brand-900);
--color-brand-950: var(--brand-950);
/* Radius */
--radius-sm: calc(var(--radius) - 4px);
--radius-md: calc(var(--radius) - 2px);
--radius-lg: var(--radius);
--radius-xl: calc(var(--radius) + 4px);
}
/* ============================================
BASE LAYER
============================================ */
@layer base {
* {
@apply border-border outline-ring/50;
}
body {
@apply bg-background text-foreground;
}
}
Design System Theming References
Official Documentation
Tailwind CSS
- Tailwind CSS v4 Theme Configuration
- Tailwind CSS Functions and Directives
- Dark Mode
- Customizing Colors
- Customizing Spacing
shadcn/ui
Color Theory
- oklch Color Space - Perceptually uniform color picker
- WCAG Contrast Checker
Design Token Architecture
Semantic Token Naming
--{category}-{variant}-{state}
Examples:
--color-primary-default
--color-primary-hover
--color-primary-disabled
--color-surface-elevated
--color-text-primary
--color-text-secondary
--color-border-subtleToken Categories
| Category | Purpose | Examples |
|---|---|---|
color | All colors | --color-primary, --color-background |
font | Typography | --font-sans, --font-mono |
spacing | Space/distance | --spacing-4, --gap-md |
radius | Border radius | --radius-sm, --radius-lg |
shadow | Elevation | --shadow-sm, --shadow-lg |
duration | Animation time | --duration-fast, --duration-slow |
ease | Easing functions | --ease-default, --ease-bounce |
oklch Color Format
Why oklch?
- Perceptually uniform: Same lightness value appears equally light regardless of hue
- Wide gamut: Access to modern display colors (P3)
- Predictable: Changing hue doesn't affect perceived lightness
Format: oklch(L C H)
- L (Lightness): 0 to 1 (0 = black, 1 = white)
- C (Chroma): 0 to ~0.4 (saturation/intensity)
- H (Hue): 0 to 360 degrees
Common Color Values
/* Grays */
--gray-50: oklch(0.985 0 0);
--gray-100: oklch(0.967 0 0);
--gray-200: oklch(0.92 0 0);
--gray-300: oklch(0.87 0 0);
--gray-400: oklch(0.70 0 0);
--gray-500: oklch(0.56 0 0);
--gray-600: oklch(0.44 0 0);
--gray-700: oklch(0.37 0 0);
--gray-800: oklch(0.27 0 0);
--gray-900: oklch(0.20 0 0);
--gray-950: oklch(0.14 0 0);
/* Blue */
--blue-500: oklch(0.58 0.19 250);
/* Red */
--red-500: oklch(0.58 0.25 25);
/* Green */
--green-500: oklch(0.62 0.17 145);
/* Yellow */
--yellow-500: oklch(0.84 0.16 84);CSS Variable Strategy
Layered Tokens
/* 1. Primitive/Raw values */
:root {
--color-blue-50: oklch(0.97 0.01 250);
--color-blue-500: oklch(0.58 0.19 250);
--color-blue-900: oklch(0.27 0.08 250);
}
/* 2. Semantic mapping */
:root {
--color-primary: var(--color-blue-500);
--color-primary-light: var(--color-blue-50);
--color-primary-dark: var(--color-blue-900);
}
/* 3. Component-specific (rarely needed with shadcn) */
.button {
--button-bg: var(--color-primary);
}Tailwind v4.1+ @theme Directive
Basic Theme Extension
@theme {
/* Custom colors */
--color-brand: #3b82f6;
--color-brand-light: #93c5fd;
--color-brand-dark: #1e40af;
/* Custom fonts */
--font-display: "Satoshi", sans-serif;
/* Custom spacing */
--spacing-18: 4.5rem;
/* Custom breakpoints */
--breakpoint-3xl: 120rem;
}Theme with CSS Variables
@theme inline {
/* Bridge CSS vars to Tailwind */
--color-primary: var(--primary);
--color-secondary: var(--secondary);
}Custom Utilities
@utility content-auto {
content-visibility: auto;
}
@utility contain-layout {
contain: layout;
}Dark Mode Patterns
Class-based Strategy (Recommended)
@custom-variant dark (&:is(.dark *));
:root {
--background: white;
--foreground: black;
}
.dark {
--background: black;
--foreground: white;
}Media Query Strategy
@media (prefers-color-scheme: dark) {
:root {
--background: black;
--foreground: white;
}
}Combined Strategy
:root {
--background: white;
}
@media (prefers-color-scheme: dark) {
:root {
--background: black;
}
}
/* Override with class */
.dark {
--background: black;
}
.light {
--background: white;
}Multi-Theme Support
Data Attribute Themes
[data-theme="ocean"] {
--primary: oklch(0.55 0.18 230);
--accent: oklch(0.65 0.12 190);
}
[data-theme="forest"] {
--primary: oklch(0.50 0.15 145);
--accent: oklch(0.70 0.10 100);
}Theme Switcher Component
function ThemeSwitcher() {
const [theme, setTheme] = useState("light");
useEffect(() => {
document.documentElement.setAttribute("data-theme", theme);
}, [theme]);
return (
<select value={theme} onChange={(e) => setTheme(e.target.value)}>
<option value="light">Light</option>
<option value="dark">Dark</option>
<option value="ocean">Ocean</option>
<option value="forest">Forest</option>
</select>
);
}Best Practices
1. Use semantic naming: --primary not --blue-500 2. Always pair foreground: Every background needs a matching foreground 3. Consistent scale: Define complete color scales (50-950) 4. oklch for colors: Use oklch for perceptual uniformity 5. Single source: All tokens in one globals.css file 6. Test contrast: Verify WCAG AA compliance (4.5:1 for normal text) 7. Document tokens: Maintain visual reference