--- name: tailwind-ui-patterns description: Tailwind CSS v4 patterns, component styling, and responsive design license: MIT compatibility: tailwindcss 4+, react 18+, vite 6+ allowed-tools: read_file write_file apply_patch search_with_context --- # Tailwind UI Patterns ## Tailwind v4 Setup ```css /* app.css */ @import "tailwindcss"; /* Custom theme tokens */ @theme { --color-brand-50: oklch(0.97 0.01 250); --color-brand-500: oklch(0.55 0.15 250); --color-brand-900: oklch(0.25 0.08 250); --font-display: "Cal Sans", system-ui, sans-serif; --spacing-18: 4.5rem; } ``` ## Component Patterns ### Button Variants ```tsx const buttonVariants = { base: "inline-flex items-center justify-center font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50", variant: { primary: "bg-brand-500 text-white hover:bg-brand-600 focus-visible:ring-brand-500", secondary: "bg-gray-100 text-gray-900 hover:bg-gray-200 focus-visible:ring-gray-500", outline: "border border-gray-300 bg-transparent hover:bg-gray-50 focus-visible:ring-gray-500", ghost: "hover:bg-gray-100 focus-visible:ring-gray-500", destructive: "bg-red-500 text-white hover:bg-red-600 focus-visible:ring-red-500", }, size: { sm: "h-8 px-3 text-sm rounded-md", md: "h-10 px-4 text-sm rounded-lg", lg: "h-12 px-6 text-base rounded-lg", icon: "h-10 w-10 rounded-lg", }, }; function Button({ variant = "primary", size = "md", className, ...props }) { return ( // Scale on hover
Card
// Combined transitions Link with arrow → ``` ### Keyframe Animations ```css @theme { --animate-fade-in: fade-in 0.3s ease-out; --animate-slide-up: slide-up 0.3s ease-out; --animate-spin-slow: spin 3s linear infinite; } @keyframes fade-in { from { opacity: 0; } to { opacity: 1; } } @keyframes slide-up { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } } ``` ```tsx
Fading content
Sliding content
``` ## Dark Mode ```tsx // Toggle component

Adaptive heading

Adaptive text

// Using CSS variables for theming @theme { --color-surface: white; --color-on-surface: #111827; } @media (prefers-color-scheme: dark) { @theme { --color-surface: #111827; --color-on-surface: #f9fafb; } } ``` ## Layout Patterns ### Sticky Header ```tsx
``` ### Sidebar Layout ```tsx
{/* Main content */}
``` ### Centered Max-Width Content ```tsx
{/* Content */}
``` ## Best Practices 1. **Use design tokens** via @theme for consistency 2. **Mobile-first** - start with mobile, add breakpoints up 3. **Compose with cn()** - merge classes cleanly 4. **Extract components** when patterns repeat 3+ times 5. **Use semantic colors** (brand, surface, error) over raw values 6. **Prefer utilities** over custom CSS when possible 7. **Group related utilities** logically for readability