--- description: Tailwind CSS utility-first design system patterns alwaysApply: false globs: **/*.{vue,html,jsx,tsx} --- # Tailwind CSS Mastery ## Core Principles ### 1. Embrace Utility Classes Don't fight against utilities - they're your superpower. ### 2. Extract Components When You Repeat Create component classes only after repeating a pattern **3+ times**. ### 3. Mobile-First Responsive Design Always start mobile, progressively enhance for larger screens. ```html
``` ### 4. Use Design Tokens Extend Tailwind's config with your design system. ```javascript // tailwind.config.js module.exports = { theme: { extend: { colors: { primary: { DEFAULT: '#606060', light: '#808080', dark: '#404040', }, }, } } } ``` ## Spacing System (4px Grid) **The 4px Base Grid Rule**: All spacing follows a 4px base grid for mathematical harmony. ``` 4px = p-1, m-1, gap-1 8px = p-2, m-2, gap-2 16px = p-4, m-4, gap-4 24px = p-6, m-6, gap-6 32px = p-8, m-8, gap-8 ``` ## Responsive Breakpoints ```javascript sm: 640px // Mobile landscape md: 768px // Tablets lg: 1024px // Desktop xl: 1280px // Large desktop ``` ### Mobile-First Pattern ```html
``` ## Component Patterns ### Buttons ```html ``` ### Cards ```html

Card Title

Content

``` ### Form Elements ```html ``` ## Color Contrast for Accessibility Always ensure **4.5:1 contrast ratio** minimum (WCAG AA). ```html

Dark text on light

Hard to read!

``` ## Custom Component Classes Only extract after 3+ repetitions: ```css @layer components { .btn-primary { @apply px-6 py-3 bg-primary text-white rounded-lg font-semibold; @apply hover:bg-primary-dark transition-colors duration-200; @apply focus:outline-none focus:ring-2 focus:ring-primary-focus; } } ``` ## Summary Checklist - ✅ Start mobile-first, enhance for larger screens - ✅ Use design tokens (extend Tailwind config) - ✅ Follow 4px spacing grid - ✅ Extract components after 3+ repetitions - ✅ Keep utility classes in HTML - ✅ Ensure color contrast for accessibility - ✅ Use transitions for smooth interactions - ✅ Configure PurgeCSS for production